Pārlūkot izejas kodu

Fix state fresh issues while adding/remove participants

Neeraj Gupta 2 gadi atpakaļ
vecāks
revīzija
a075f335e8

+ 5 - 0
lib/models/collection.dart

@@ -70,6 +70,11 @@ class Collection {
     return result;
   }
 
+  void updateSharees(List<User> newSharees) {
+    sharees?.clear();
+    sharees?.addAll(newSharees);
+  }
+
   static CollectionType typeFromString(String type) {
     switch (type) {
       case "folder":

+ 0 - 1
lib/services/collections_service.dart

@@ -319,7 +319,6 @@ class CollectionsService {
       for (final user in response.data["sharees"]) {
         sharees.add(User.fromMap(user));
       }
-
       _collectionIDToCollections[collectionID] =
           _collectionIDToCollections[collectionID].copyWith(sharees: sharees);
       unawaited(_db.insert([_collectionIDToCollections[collectionID]]));

+ 2 - 3
lib/ui/actions/collection/collection_sharing_actions.dart

@@ -85,7 +85,7 @@ class CollectionSharingActions {
     try {
       final newSharees =
           await CollectionsService.instance.unshare(collection.id, user.email);
-      collection = collection.copyWith(sharees: newSharees);
+      collection.updateSharees(newSharees);
       await dialog.hide();
       showToast(context, "Stopped sharing with " + user.email + ".");
       return true;
@@ -139,7 +139,6 @@ class CollectionSharingActions {
     // getPublicKey can return null
     // ignore: unnecessary_null_comparison
     if (publicKey == null || publicKey == '') {
-      Navigator.of(context, rootNavigator: true).pop('dialog');
       final dialog = AlertDialog(
         title: const Text("Invite to ente?"),
         content: Text(
@@ -179,7 +178,7 @@ class CollectionSharingActions {
       try {
         final newSharees = await CollectionsService.instance
             .share(collection.id, email, publicKey, role);
-        collection = collection.copyWith(sharees: newSharees);
+        collection.updateSharees(newSharees);
         await dialog.hide();
         showShortToast(context, "Shared successfully!");
         return true;