فهرست منبع

CollectionService: Add collection delete V3 for empty collections

Neeraj Gupta 2 سال پیش
والد
کامیت
b59e681fdc
1فایلهای تغییر یافته به همراه23 افزوده شده و 0 حذف شده
  1. 23 0
      lib/services/collections_service.dart

+ 23 - 0
lib/services/collections_service.dart

@@ -392,6 +392,29 @@ class CollectionsService {
     }
     }
   }
   }
 
 
+  Future<void> trashEmptyCollections(Collection collection) async {
+    try {
+      // While trashing empty albums, we must pass keeFiles flag as True.
+      // The server will verify that the collection is actually empty before
+      // deleting the files. If keepFiles is set as False and the collection
+      // is not empty, then the files in the collections will be moved to trash
+      await _enteDio.delete(
+        "/collections/v3/${collection.id}?keepFiles=True&collectionID=${collection.id}",
+      );
+      final deletedCollection = collection.copyWith(isDeleted: true);
+      _collectionIDToCollections[collection.id] = deletedCollection;
+      unawaited(_db.insert([deletedCollection]));
+    } on DioError catch (e) {
+      if (e.response != null) {
+        debugPrint("Error " + e.response!.toString());
+      }
+      rethrow;
+    } catch (e) {
+      _logger.severe('failed to trash empty collection', e);
+      rethrow;
+    }
+  }
+
   Future<void> _handleCollectionDeletion(Collection collection) async {
   Future<void> _handleCollectionDeletion(Collection collection) async {
     await _filesDB.deleteCollection(collection.id);
     await _filesDB.deleteCollection(collection.id);
     final deletedCollection = collection.copyWith(isDeleted: true);
     final deletedCollection = collection.copyWith(isDeleted: true);