Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] split device and ente trash objects into two classes

Priyanshu Dangarede71efffdcfb
diff --git a/mobile/apps/photos/lib/db/trash_db.dart b/mobile/apps/photos/lib/db/trash_db.dart
index 08e9cdb15b..b243a72088 100644
--- a/mobile/apps/photos/lib/db/trash_db.dart
+++ b/mobile/apps/photos/lib/db/trash_db.dart
@@ -118,12 +118,12 @@ class TrashDB {
return count ?? 0;
}
- Future<void> insertMultiple(List<TrashFile> trashFiles) async {
+ Future<void> insertMultiple(List<EnteTrashFile> trashFiles) async {
final startTime = DateTime.now();
final db = await instance.database;
var batch = db.batch();
int batchCounter = 0;
- for (TrashFile trash in trashFiles) {
+ for (final trash in trashFiles) {
if (batchCounter == 400) {
await batch.commit(noResult: true);
batch = db.batch();
@@ -159,7 +159,7 @@ class TrashDB {
);
}
- Future<int> update(TrashFile file) async {
+ Future<int> update(EnteTrashFile file) async {
final db = await instance.database;
return await db.update(
tableName,
@@ -190,8 +190,8 @@ class TrashDB {
return FileLoadResult(files, files.length == limit);
}
- TrashFile _getTrashFromRow(Map<String, dynamic> row) {
- final trashFile = TrashFile();
+ EnteTrashFile _getTrashFromRow(Map<String, dynamic> row) {
+ final trashFile = EnteTrashFile();
trashFile.updateAt = row[columnTrashUpdatedAt];
trashFile.deleteBy = row[columnTrashDeleteBy];
trashFile.uploadedFileID = row[columnUploadedFileID];
@@ -228,7 +228,7 @@ class TrashDB {
return trashFile;
}
- Map<String, dynamic> _getRowForTrash(TrashFile trash) {
+ Map<String, dynamic> _getRowForTrash(EnteTrashFile trash) {
final row = <String, dynamic>{};
row[columnTrashUpdatedAt] = trash.updateAt;
row[columnTrashDeleteBy] = trash.deleteBy;
diff --git a/mobile/apps/photos/lib/models/file/extensions/file_props.dart b/mobile/apps/photos/lib/models/file/extensions/file_props.dart
index e60569fe36..97cf061419 100644
--- a/mobile/apps/photos/lib/models/file/extensions/file_props.dart
+++ b/mobile/apps/photos/lib/models/file/extensions/file_props.dart
@@ -42,11 +42,14 @@ extension FilePropsExtn on EnteFile {
bool get canEditMetaInfo => isUploaded && isOwner;
- bool get isTrashFile => this is TrashFile;
-
- bool get isDeviceOnlyTrashFile => asTrashFile?.isDeviceOnly ?? false;
-
+ bool get isTrash => this is TrashFile;
+ bool get isEnteTrash => this is EnteTrashFile;
+ bool get isDeviceTrash => this is DeviceTrashFile;
TrashFile? get asTrashFile => (this is TrashFile) ? this as TrashFile : null;
+ EnteTrashFile? get asEnteTrashFile =>
+ (this is EnteTrashFile) ? this as EnteTrashFile : null;
+ DeviceTrashFile? get asDeviceTrashFile =>
+ (this is DeviceTrashFile) ? this as DeviceTrashFile : null;
// Return true if the file was uploaded via collect photos workflow
bool get isCollect => uploaderName != null;
diff --git a/mobile/apps/photos/lib/models/file/trash_file.dart b/mobile/apps/photos/lib/models/file/trash_file.dart
index d9bdd847f3..0caaea98c6 100644
--- a/mobile/apps/photos/lib/models/file/trash_file.dart
+++ b/mobile/apps/photos/lib/models/file/trash_file.dart
@@ -1,14 +1,23 @@
import 'package:photos/models/file/file.dart';
-class TrashFile extends EnteFile {
+sealed class TrashFile extends EnteFile {
TrashFile();
- TrashFile.fromEnteFile(
+ TrashFile.from(super.file, {required this.deleteBy}) : super.from();
+
+ // time after which will will be deleted from trash & user's storage usage
+ // will go down
+ late int deleteBy;
+}
+
+class EnteTrashFile extends TrashFile {
+ EnteTrashFile();
+
+ EnteTrashFile.from(
super.file, {
+ required super.deleteBy,
required this.createdAt,
required this.updateAt,
- required this.deleteBy,
- required this.isDeviceOnly,
}) : super.from();
// time when file was put in the trash for first time
@@ -17,12 +26,8 @@ class TrashFile extends EnteFile {
// for non-deleted trash items, updateAt is usually equal to the latest time
// when the file was moved to trash
late int updateAt;
+}
- // time after which will will be deleted from trash & user's storage usage
- // will go down
- late int deleteBy;
-
- // This object represents the file in the device trash. The same file
- // may also have a separate entry in Ente's trash.
- bool isDeviceOnly = false;
+class DeviceTrashFile extends TrashFile {
+ DeviceTrashFile();
}
diff --git a/mobile/apps/photos/lib/module/download/file.dart b/mobile/apps/photos/lib/module/download/file.dart
index b7f326b6e0..e229448afe 100644
--- a/mobile/apps/photos/lib/module/download/file.dart
+++ b/mobile/apps/photos/lib/module/download/file.dart
@@ -80,7 +80,7 @@ Future<File?> _getLocalDiskFile(
}) async {
// Return null because reading a device trash file by its file system path
// fails with a permission-denied error.
- if (file.isDeviceOnlyTrashFile) {
+ if (file.isDeviceTrash) {
return null;
}
diff --git a/mobile/apps/photos/lib/module/download/thumbnail.dart b/mobile/apps/photos/lib/module/download/thumbnail.dart
index 05a58e8d0e..a0cdd98100 100644
--- a/mobile/apps/photos/lib/module/download/thumbnail.dart
+++ b/mobile/apps/photos/lib/module/download/thumbnail.dart
@@ -205,8 +205,8 @@ Future<Uint8List?> getThumbnailFromLocal(
});
} else {
return file.getAsset.then((asset) async {
- if (asset == null ||
- !(await asset.exists || file.isDeviceOnlyTrashFile)) {
+ // asset.exists may return false for files in the android device trash
+ if (asset == null || !(await asset.exists || file.isDeviceTrash)) {
return null;
}
return asset
diff --git a/mobile/apps/photos/lib/services/sync/trash_sync_service.dart b/mobile/apps/photos/lib/services/sync/trash_sync_service.dart
index 002f5438f4..e9ca1e9d95 100644
--- a/mobile/apps/photos/lib/services/sync/trash_sync_service.dart
+++ b/mobile/apps/photos/lib/services/sync/trash_sync_service.dart
@@ -149,15 +149,15 @@ class TrashSyncService {
try {
final responseData = await _gateway.getDiff(sinceTime);
int latestUpdatedAtTime = 0;
- final trashedFiles = <TrashFile>[];
+ final trashedFiles = <EnteTrashFile>[];
final deletedUploadIDs = <int>[];
- final restoredFiles = <TrashFile>[];
+ final restoredFiles = <EnteTrashFile>[];
final diff = responseData["diff"] as List;
final bool hasMore = responseData["hasMore"] as bool;
final startTime = DateTime.now();
for (final item in diff) {
- final trash = TrashFile();
+ final trash = EnteTrashFile();
trash.createdAt = item['createdAt'];
trash.updateAt = item['updatedAt'];
latestUpdatedAtTime = max(latestUpdatedAtTime, trash.updateAt);
@@ -245,7 +245,7 @@ class TrashSyncService {
await _gateway.trashFiles(items);
}
- Future<void> deleteFromTrash(List<EnteFile> files) async {
+ Future<void> deleteFromTrash(List<EnteTrashFile> files) async {
final uniqueFileIds = files.map((e) => e.uploadedFileID!).toSet().toList();
final batchedFileIDs = uniqueFileIds.chunks(batchSize);
for (final batch in batchedFileIDs) {
@@ -277,8 +277,8 @@ class TrashSyncService {
}
class TrashDiff {
- final List<TrashFile> trashedFiles;
- final List<TrashFile> restoredFiles;
+ final List<EnteTrashFile> trashedFiles;
+ final List<EnteTrashFile> restoredFiles;
final List<int> deletedUploadIDs;
final bool hasMore;
final int lastSyncedTimeStamp;
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
index 416527a63c..620a4ea0e9 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -354,7 +354,7 @@ class _BodyState extends State<_Body> {
builder: (BuildContext context, int selectedIndex, _) {
if (widget.config.mode == DetailPageMode.minimalistic ||
isGuestView ||
- _files![selectedIndex].isTrashFile) {
+ _files![selectedIndex].isTrash) {
return const SizedBox.shrink();
}
return ValueListenableBuilder(
@@ -532,7 +532,7 @@ class _BodyState extends State<_Body> {
void _evaluateQrIfEligible(EnteFile file) {
_qrHelper?.evaluateFile(
file,
- isGuestView || file.isTrashFile ? null : _renderedFiles[file.tag],
+ isGuestView || file.isTrash ? null : _renderedFiles[file.tag],
);
}
@@ -815,9 +815,7 @@ class _GallerySocialOverlay extends StatelessWidget {
@override
Widget build(BuildContext context) {
- if (mode == DetailPageMode.minimalistic ||
- isGuestView ||
- file.isTrashFile) {
+ if (mode == DetailPageMode.minimalistic || isGuestView || file.isTrash) {
return const SizedBox.shrink();
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
index 643dc1a0ed..1baf3cdbb5 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_app_bar.dart
@@ -285,7 +285,7 @@ class FileAppBarState extends State<FileAppBar> {
),
);
}
- if (!isFileHidden && isFileUploaded && !widget.file.isTrashFile) {
+ if (!isFileHidden && isFileUploaded && !widget.file.isTrash) {
_actions.add(
Center(
child: FavoriteWidget(widget.file, iconSize: 24, tapTargetSize: 48),
@@ -300,7 +300,7 @@ class FileAppBarState extends State<FileAppBar> {
final List<EntePopupMenuOption<int>> items = [];
final bool restrictFileActions =
- widget.mode == DetailPageMode.minimalistic || widget.file.isTrashFile;
+ widget.mode == DetailPageMode.minimalistic || widget.file.isTrash;
if (restrictFileActions) {
items.add(
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
index abc8aebe9f..121363c951 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_bottom_bar.dart
@@ -111,11 +111,11 @@ class FileBottomBarState extends State<FileBottomBar> {
widget.file.isOwner &&
widget.file.isUploaded &&
(collection?.isHidden() ?? false);
- if (widget.file.isTrashFile) {
+ if (widget.file.isEnteTrash) {
_addTrashOptions(children);
}
- if (!widget.file.isTrashFile) {
+ if (!widget.file.isTrash) {
if (isOwnedByUser) {
children.add(
Tooltip(
@@ -263,8 +263,8 @@ class FileBottomBarState extends State<FileBottomBar> {
color: Colors.white,
),
onPressed: () async {
- final trashedFile = <TrashFile>[];
- trashedFile.add(widget.file.asTrashFile!);
+ final trashedFile = <EnteTrashFile>[];
+ trashedFile.add(widget.file.asEnteTrashFile!);
if (await deleteFromTrash(context, trashedFile) == true) {
if (!mounted) return;
Navigator.pop(context);
diff --git a/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
index cc6f6f2feb..fbcb2e3056 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/file_details_widget.dart
@@ -156,7 +156,7 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
//Make sure the bottom most tile is always the same one, that is it should
//not be rendered only if a condition is met.
final fileDetailsTiles = <Widget>[];
- final bool canEditCaption = isFileOwner && !file.isTrashFile;
+ final bool canEditCaption = isFileOwner && !file.isTrash;
fileDetailsTiles.add(
!widget.file.isUploaded ||
(!canEditCaption && (widget.file.caption?.isEmpty ?? true))
@@ -264,7 +264,7 @@ class _FileDetailsWidgetState extends State<FileDetailsWidget> {
),
]);
- if (!file.isTrashFile) {
+ if (!file.isTrash) {
fileDetailsTiles.addAll([
AlbumsItemWidget(file, _currentUserID),
const SizedBox(height: Spacing.xxl),
diff --git a/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dart b/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dart
index 2cfe0270db..fc10a036f1 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dart
@@ -161,7 +161,7 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {
}
bool _didFileChange(EnteFile oldFile, EnteFile newFile) {
- if (oldFile.isTrashFile != newFile.isTrashFile) return true;
+ if (oldFile.isTrash != newFile.isTrash) return true;
if (oldFile.generatedID != newFile.generatedID) return true;
if (oldFile.uploadedFileID != newFile.uploadedFileID) return true;
if (oldFile.localID != newFile.localID) return true;
@@ -182,7 +182,7 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {
}
bool _isFileEligible(EnteFile file) {
- if (widget.isGuestView || file.isTrashFile) return false;
+ if (widget.isGuestView || file.isTrash) return false;
return file.fileType == FileType.image ||
file.fileType == FileType.livePhoto;
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart
index 785b30048e..451c2e7f21 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/thumbnail_widget.dart
@@ -255,7 +255,7 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
viewChildren.add(const UnSyncedIcon());
}
- if (widget.file.isTrashFile) {
+ if (widget.file.isTrash) {
viewChildren.add(TrashedFileOverlayText(widget.file.asTrashFile!));
} else if (galleryContext?.type == GroupType.size) {
viewChildren.add(FileSizeOverlayText(widget.file));
@@ -332,10 +332,15 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
if (thumbData == null) {
if (widget.file.isUploaded) {
_logger.info("Removing localID reference for " + widget.file.tag);
- widget.file.localID = null;
- if (widget.file.isTrashFile) {
- unawaited(TrashDB.instance.update(widget.file.asTrashFile!));
+ if (widget.file.isTrash) {
+ if (widget.file.isEnteTrash) {
+ widget.file.localID = null;
+ unawaited(
+ TrashDB.instance.update(widget.file.asEnteTrashFile!),
+ );
+ }
} else {
+ widget.file.localID = null;
unawaited(FilesDB.instance.update(widget.file));
}
_loadNetworkImage();
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
index 09842a8c84..5a68376991 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_media_kit.dart
@@ -158,8 +158,9 @@ class _VideoWidgetMediaKitState extends State<VideoWidgetMediaKit>
}
} else {
widget.file.getAsset.then((asset) async {
+ // asset.exists may return false for files in the android device trash
if (asset == null ||
- !(await asset.exists || widget.file.isDeviceOnlyTrashFile)) {
+ !(await asset.exists || widget.file.isDeviceTrash)) {
if (widget.file.uploadedFileID != null) {
_loadNetworkVideo();
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
index da6c93cf90..860f3fd4e7 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_widget_native.dart
@@ -201,8 +201,9 @@ class _VideoWidgetNativeState extends State<VideoWidgetNative>
}
} else {
await widget.file.getAsset.then((asset) async {
+ // asset.exists may return false for files in the android device trash
if (asset == null ||
- !(await asset.exists || widget.file.isDeviceOnlyTrashFile)) {
+ !(await asset.exists || widget.file.isDeviceTrash)) {
if (widget.file.uploadedFileID != null) {
_loadNetworkVideo(update);
}
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/creation_time_item_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/creation_time_item_widget.dart
index 5e3f6d8bfc..adbf53d9b1 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/creation_time_item_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/creation_time_item_widget.dart
@@ -29,7 +29,7 @@ class _CreationTimeItemState extends State<CreationTimeItem> {
(widget.file.ownerID == null ||
widget.file.ownerID == widget.currentUserID) &&
widget.file.uploadedFileID != null &&
- !widget.file.isTrashFile;
+ !widget.file.isTrash;
return GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/file_properties_item_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/file_properties_item_widget.dart
index c8585db503..faf147f6a3 100644
--- a/mobile/apps/photos/lib/ui/viewer/file_details/file_properties_item_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file_details/file_properties_item_widget.dart
@@ -48,7 +48,7 @@ class _FilePropertiesItemWidgetState extends State<FilePropertiesItemWidget> {
editOnTap:
widget.file.uploadedFileID == null ||
widget.file.ownerID != widget.currentUserID ||
- widget.file.isTrashFile
+ widget.file.isTrash
? null
: () async {
await editFilename(context, widget.file);
diff --git a/mobile/apps/photos/lib/utils/delete_file_util.dart b/mobile/apps/photos/lib/utils/delete_file_util.dart
index e8424ffde8..5722c44a66 100644
--- a/mobile/apps/photos/lib/utils/delete_file_util.dart
+++ b/mobile/apps/photos/lib/utils/delete_file_util.dart
@@ -17,6 +17,7 @@ import 'package:photos/events/local_photos_updated_event.dart';
import 'package:photos/gateways/trash/models/trash_item_request.dart';
import "package:photos/models/button_result.dart";
import 'package:photos/models/file/file.dart';
+import "package:photos/models/file/trash_file.dart";
import "package:photos/models/files_split.dart";
import "package:photos/models/freeable_space_info.dart";
import 'package:photos/models/selected_files.dart';
@@ -292,7 +293,11 @@ Future<List<EnteFile>> deleteFilesOnDeviceOnly(
return deletedFiles;
}
-Future<bool> deleteFromTrash(BuildContext context, List<EnteFile> files) async {
+Future<bool> deleteFromTrash(
+ BuildContext context,
+ List<EnteFile> files,
+) async {
+ final trashFiles = files.map((file) => file as EnteTrashFile).toList();
bool didDeletionStart = false;
final l10n = context.strings;
final actionResult = await showBottomSheetComponent<ButtonResult>(
@@ -314,15 +319,15 @@ Future<bool> deleteFromTrash(BuildContext context, List<EnteFile> files) async {
() async {
try {
didDeletionStart = true;
- await trashSyncService.deleteFromTrash(files);
+ await trashSyncService.deleteFromTrash(trashFiles);
Bus.instance.fire(
FilesUpdatedEvent(
- files,
+ trashFiles,
type: EventType.deletedFromEverywhere,
source: "deleteFromTrash",
),
);
- //the FilesUpdateEvent is not reloading trash on premanently removing
+ //the FilesUpdateEvent is not reloading trash on permanently removing
//files, so need to fire ForceReloadTrashPageEvent
Bus.instance.fire(ForceReloadTrashPageEvent());
} catch (e, s) {