Prechádzať zdrojové kódy

Support for removing files from shared collection

Neeraj Gupta 2 rokov pred
rodič
commit
12a95136af

+ 1 - 1
lib/services/collections_service.dart

@@ -1052,7 +1052,7 @@ class CollectionsService {
         params["fileIDs"].add(file.uploadedFileID);
       }
       await _enteDio.post(
-        "/collections/v2/remove-files",
+        "/collections/v3/remove-files",
         data: params,
       );
 

+ 13 - 9
lib/ui/actions/collection/collection_sharing_actions.dart

@@ -380,19 +380,23 @@ class CollectionActions {
   ) async {
     final int currentUserID = Configuration.instance.getUserID()!;
     final isCollectionOwner = collection.owner!.id == currentUserID;
-    if (!isCollectionOwner) {
-      // Todo: Support for removing own files from a collection owner by
-      // someone else will be added along with collaboration changes
-      showShortToast(context, "Only collection owner can remove");
-      return;
-    }
     final FilesSplit split = FilesSplit.split(
       files,
       Configuration.instance.getUserID()!,
     );
-    if (split.ownedByOtherUsers.isNotEmpty) {
-      //  Todo: Support for removing own files from a collection owner by
-      // someone else will be added along with collaboration changes
+    if (isCollectionOwner) {
+      await collectionsService.removeFromCollection(
+        collection.id,
+        split.ownedByOtherUsers,
+      );
+    } else {
+      await collectionsService.removeFromCollection(
+        collection.id,
+        split.ownedByCurrentUser,
+      );
+    }
+
+    if (!isCollectionOwner && split.ownedByOtherUsers.isNotEmpty) {
       showShortToast(context, "Can only remove files owned by you");
       return;
     }

+ 15 - 6
lib/ui/viewer/actions/file_selection_actions_widget.dart

@@ -49,6 +49,7 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
   late int currentUserID;
   late FilesSplit split;
   late CollectionActions collectionActions;
+  late bool isCollectionOwner;
 
   // _cachedCollectionForSharedLink is primarly used to avoid creating duplicate
   // links if user keeps on creating Create link button after selecting
@@ -61,6 +62,8 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
     split = FilesSplit.split(<File>[], currentUserID);
     widget.selectedFiles.addListener(_selectFileChangeListener);
     collectionActions = CollectionActions(CollectionsService.instance);
+    isCollectionOwner =
+        widget.collection != null && widget.collection!.isOwner(currentUserID);
     super.initState();
   }
 
@@ -88,17 +91,21 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
         ? " (${split.ownedByCurrentUser.length})"
             ""
         : "";
+    final int removeCount = split.ownedByCurrentUser.length +
+        (isCollectionOwner ? split.ownedByOtherUsers.length : 0);
+    final String removeSuffix = showPrefix
+        ? " ($removeCount)"
+            ""
+        : "";
     final String suffixInPending = split.ownedByOtherUsers.isNotEmpty
         ? " (${split.ownedByCurrentUser.length + split.pendingUploads.length})"
             ""
         : "";
+
     final bool anyOwnedFiles =
         split.pendingUploads.isNotEmpty || split.ownedByCurrentUser.isNotEmpty;
     final bool anyUploadedFiles = split.ownedByCurrentUser.isNotEmpty;
-    bool showRemoveOption = widget.type.showRemoveFromAlbum();
-    if (showRemoveOption && widget.type == GalleryType.sharedCollection) {
-      showRemoveOption = split.ownedByCurrentUser.isNotEmpty;
-    }
+    final bool showRemoveOption = widget.type.showRemoveFromAlbum();
     debugPrint('$runtimeType building  $mounted');
     final colorScheme = getEnteColorScheme(context);
     final List<List<BlurMenuItemWidget>> items = [];
@@ -156,7 +163,7 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
       secondList.add(
         BlurMenuItemWidget(
           leadingIcon: Icons.remove_outlined,
-          labelText: "Remove from album$suffix",
+          labelText: "Remove from album$removeSuffix",
           menuItemColor: colorScheme.fillFaint,
           onTap: anyUploadedFiles ? _removeFilesFromAlbum : null,
         ),
@@ -301,9 +308,11 @@ class _FileSelectionActionWidgetState extends State<FileSelectionActionWidget> {
   }
 
   Future<void> _removeFilesFromAlbum() async {
-    if (split.pendingUploads.isNotEmpty || split.ownedByOtherUsers.isNotEmpty) {
+    if (split.pendingUploads.isNotEmpty) {
       widget.selectedFiles
           .unSelectAll(split.pendingUploads.toSet(), skipNotify: true);
+    }
+    if (!isCollectionOwner && split.ownedByOtherUsers.isNotEmpty) {
       widget.selectedFiles
           .unSelectAll(split.ownedByOtherUsers.toSet(), skipNotify: true);
     }