Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refactor collection trashing logic

AmanRajSinghMouryae96ee529ca09
diff --git a/mobile/apps/locker/ios/Podfile.lock b/mobile/apps/locker/ios/Podfile.lock
index 257fc6552f..435dbd2aa9 100644
--- a/mobile/apps/locker/ios/Podfile.lock
+++ b/mobile/apps/locker/ios/Podfile.lock
@@ -194,38 +194,38 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/url_launcher_ios/ios"
SPEC CHECKSUMS:
- app_links: f3e17e4ee5e357b39d8b95290a9b2c299fca71c6
- cupertino_http: 947a233f40cfea55167a49f2facc18434ea117ba
- device_info_plus: c6fb39579d0f423935b0c9ce7ee2f44b71b9fce6
+ app_links: 76b66b60cc809390ca1ad69bfd66b998d2387ac7
+ cupertino_http: 94ac07f5ff090b8effa6c5e2c47871d48ab7c86c
+ device_info_plus: 335f3ce08d2e174b9fdc3db3db0f4e3b1f66bd89
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
- file_picker: b159e0c068aef54932bb15dc9fd1571818edaf49
- file_saver: 503e386464dbe118f630e17b4c2e1190fa0cf808
+ file_picker: a0560bc09d61de87f12d246fc47d2119e6ef37be
+ file_saver: 6cdbcddd690cb02b0c1a0c225b37cd805c2bf8b6
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
- flutter_email_sender: e03bdda7637bcd3539bfe718fddd980e9508efaa
- flutter_inappwebview_ios: 6f63631e2c62a7c350263b13fa5427aedefe81d4
- flutter_local_authentication: 1172a4dd88f6306dadce067454e2c4caf07977bb
- flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
- fluttertoast: 21eecd6935e7064cc1fcb733a4c5a428f3f24f0f
- listen_sharing_intent: 74a842adcbcf7bedf7bbc938c749da9155141b9a
- local_auth_darwin: 66e40372f1c29f383a314c738c7446e2f7fdadc3
- objective_c: 77e887b5ba1827970907e10e832eec1683f3431d
- open_file_ios: 461db5853723763573e140de3193656f91990d9e
+ flutter_email_sender: aa1e9772696691d02cd91fea829856c11efb8e58
+ flutter_inappwebview_ios: b89ba3482b96fb25e00c967aae065701b66e9b99
+ flutter_local_authentication: 989278c681612f1ee0e36019e149137f114b9d7f
+ flutter_secure_storage: 1ed9476fba7e7a782b22888f956cce43e2c62f13
+ fluttertoast: 2c67e14dce98bbdb200df9e1acf610d7a6264ea1
+ listen_sharing_intent: fe0b9a59913cc124dd6cbd55cd9f881de5f75759
+ local_auth_darwin: 553ce4f9b16d3fdfeafce9cf042e7c9f77c1c391
+ objective_c: 89e720c30d716b036faf9c9684022048eee1eee2
+ open_file_ios: 5ff7526df64e4394b4fe207636b67a95e83078bb
OrderedSet: e539b66b644ff081c73a262d24ad552a69be3a94
- package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
- path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
- photo_manager: 81954a1bf804b6e882d0453b3b6bc7fad7b47d3d
- privacy_screen: 1a131c052ceb3c3659934b003b0d397c2381a24e
+ package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
+ path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
+ photo_manager: 1d80ae07a89a67dfbcae95953a1e5a24af7c3e62
+ privacy_screen: 3159a541f5d3a31bea916cfd4e58f9dc722b3fd4
SDWebImage: 16309af6d214ba3f77a7c6f6fdda888cb313a50a
Sentry: da60d980b197a46db0b35ea12cb8f39af48d8854
- sentry_flutter: 2df8b0aab7e4aba81261c230cbea31c82a62dd1b
- share_plus: 8b6f8b3447e494cca5317c8c3073de39b3600d1f
- shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
- sodium_libs: 1faae17af662384acbd13e41867a0008cd2e2318
- sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d
+ sentry_flutter: 27892878729f42701297c628eb90e7c6529f3684
+ share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
+ shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
+ sodium_libs: 6c6d0e83f4ee427c6464caa1f1bdc2abf3ca0b7f
+ sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
SwiftyGif: 706c60cf65fa2bc5ee0313beece843c8eb8194d4
- ua_client_hints: aeabd123262c087f0ce151ef96fa3ab77bfc8b38
- url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
+ ua_client_hints: 92fe0d139619b73ec9fcb46cc7e079a26178f586
+ url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
PODFILE CHECKSUM: d2d3220ea22664a259778d9e314054751db31361
diff --git a/mobile/apps/locker/lib/services/collections/collections_api_client.dart b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
index 05ecac2ce7..fc03bf2284 100644
--- a/mobile/apps/locker/lib/services/collections/collections_api_client.dart
+++ b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
@@ -211,10 +211,15 @@ class CollectionApiClient {
);
}
- Future<void> trashCollection(Collection collection) async {
+ Future<void> trashCollection(
+ Collection collection, {
+ bool keepFiles = false,
+ }) async {
try {
await _enteDio.delete(
- "/collections/v3/${collection.id}?keepFiles=False&collectionID=${collection.id}",
+ "/collections/v3/${collection.id}"
+ "?keepFiles=${keepFiles ? "True" : "False"}"
+ "&collectionID=${collection.id}",
);
} catch (e) {
_logger.severe('failed to trash collection', e);
diff --git a/mobile/apps/locker/lib/services/collections/collections_service.dart b/mobile/apps/locker/lib/services/collections/collections_service.dart
index e15e31d4c4..f026398561 100644
--- a/mobile/apps/locker/lib/services/collections/collections_service.dart
+++ b/mobile/apps/locker/lib/services/collections/collections_service.dart
@@ -1,5 +1,5 @@
import 'dart:async';
-import 'dart:math';
+import "dart:math";
import 'dart:typed_data';
import "package:ente_accounts/services/user_service.dart";
@@ -78,8 +78,6 @@ class CollectionService {
final List<Future> fileFutures = [];
for (final collection in updatedCollections) {
if (collection.isDeleted) {
- await _db.deleteCollection(collection);
- _collectionIDToCollections.remove(collection.id);
continue;
}
final syncTime = _db.getCollectionSyncTime(collection.id);
@@ -365,10 +363,39 @@ class CollectionService {
Future<void> trashCollection(Collection collection) async {
try {
- await _apiClient.trashCollection(collection);
+ final files = await _db.getFilesInCollection(collection);
+ var keepFiles = false;
+
+ if (files.isNotEmpty) {
+ keepFiles = true;
+ final requests = files
+ .where((file) => file.uploadedFileID != null)
+ .map(
+ (file) => TrashRequest(
+ file.uploadedFileID!,
+ collection.id,
+ ),
+ )
+ .toList();
+
+ if (requests.isNotEmpty) {
+ await _apiClient.trash(requests);
+ }
+
+ await _db.deleteFilesFromCollection(collection, files);
+ Bus.instance.fire(CollectionsUpdatedEvent('collection_files_trashed'));
+ await TrashService.instance.syncTrash();
+ }
+
+ await _apiClient.trashCollection(
+ collection,
+ keepFiles: keepFiles,
+ );
+
_logger.info("Trashed collection: ${collection.name}");
// Let sync update the local state
await sync();
+ await TrashService.instance.syncTrash();
} catch (e) {
_logger.severe("Failed to trash collection: $e");
rethrow;
diff --git a/mobile/apps/locker/lib/services/trash/trash_service.dart b/mobile/apps/locker/lib/services/trash/trash_service.dart
index 128713eee9..f95ded81bb 100644
--- a/mobile/apps/locker/lib/services/trash/trash_service.dart
+++ b/mobile/apps/locker/lib/services/trash/trash_service.dart
@@ -91,6 +91,11 @@ class TrashService {
"sinceTime": sinceTime,
},
);
+ final List<Collection> allCollections =
+ await CollectionService.instance.getCollections();
+ final Map<int, Collection> collectionMap = {
+ for (final collection in allCollections) collection.id: collection,
+ };
int latestUpdatedAtTime = 0;
final trashedFiles = <TrashFile>[];
final deletedUploadIDs = <int>[];
@@ -121,12 +126,7 @@ class TrashService {
item["file"]["thumbnail"]["decryptionHeader"];
trash.metadataDecryptionHeader =
item["file"]["metadata"]["decryptionHeader"];
- // TODO: Refactor
- final collections = await CollectionService.instance.getCollections();
- final Collection? collection =
- collections.where((c) => c.id == trash.collectionID).isNotEmpty
- ? collections.firstWhere((c) => c.id == trash.collectionID)
- : null;
+ final Collection? collection = collectionMap[trash.collectionID];
if (collection == null) {
continue;
}
diff --git a/mobile/apps/locker/lib/utils/collection_actions.dart b/mobile/apps/locker/lib/utils/collection_actions.dart
index e063bde73f..d0783cac6b 100644
--- a/mobile/apps/locker/lib/utils/collection_actions.dart
+++ b/mobile/apps/locker/lib/utils/collection_actions.dart
@@ -181,10 +181,11 @@ class CollectionActions {
Collection collection, {
VoidCallback? onSuccess,
}) async {
+ final l10n = context.l10n;
if (!collection.type.canDelete) {
SnackBarUtils.showWarningSnackBar(
context,
- context.l10n.collectionCannotBeDeleted,
+ l10n.collectionCannotBeDeleted,
);
return;
}
@@ -193,9 +194,9 @@ class CollectionActions {
final result = await showDeleteConfirmationDialog(
context,
- title: context.l10n.areYouSure,
- body: context.l10n.deleteCollectionDialogBody(collectionName),
- deleteButtonLabel: context.l10n.yesDeleteCollections(1),
+ title: l10n.areYouSure,
+ body: l10n.deleteCollectionDialogBody(collectionName),
+ deleteButtonLabel: l10n.yesDeleteCollections(1),
assetPath: "assets/collection_delete_icon.png",
);
@@ -203,8 +204,7 @@ class CollectionActions {
return;
}
- final progressDialog =
- createProgressDialog(context, context.l10n.pleaseWait);
+ final progressDialog = createProgressDialog(context, l10n.pleaseWait);
await progressDialog.show();
try {
@@ -213,7 +213,7 @@ class CollectionActions {
SnackBarUtils.showInfoSnackBar(
context,
- context.l10n.collectionDeletedSuccessfully,
+ l10n.collectionDeletedSuccessfully,
);
// Call success callback if provided
@@ -223,7 +223,7 @@ class CollectionActions {
SnackBarUtils.showWarningSnackBar(
context,
- context.l10n.failedToDeleteCollection(error.toString()),
+ l10n.failedToDeleteCollection(error.toString()),
);
}
}