浏览代码

Support for adding as collaborator

Neeraj Gupta 2 年之前
父节点
当前提交
df9d5d5771

+ 7 - 1
lib/services/collections_service.dart

@@ -258,7 +258,12 @@ class CollectionsService {
     });
     });
   }
   }
 
 
-  Future<void> share(int collectionID, String email, String publicKey) async {
+  Future<void> share(
+    int collectionID,
+    String email,
+    String publicKey,
+    CollectionParticipantRole role,
+  ) async {
     final encryptedKey = CryptoUtil.sealSync(
     final encryptedKey = CryptoUtil.sealSync(
       getCollectionKey(collectionID),
       getCollectionKey(collectionID),
       Sodium.base642bin(publicKey),
       Sodium.base642bin(publicKey),
@@ -270,6 +275,7 @@ class CollectionsService {
           "collectionID": collectionID,
           "collectionID": collectionID,
           "email": email,
           "email": email,
           "encryptedKey": Sodium.bin2base64(encryptedKey),
           "encryptedKey": Sodium.bin2base64(encryptedKey),
+          "role": role.toStringVal()
         },
         },
       );
       );
     } on DioError catch (e) {
     } on DioError catch (e) {

+ 11 - 8
lib/ui/actions/collection/collection_sharing_actions.dart

@@ -100,6 +100,7 @@ class CollectionSharingActions {
     BuildContext context,
     BuildContext context,
     Collection collection,
     Collection collection,
     String email, {
     String email, {
+    CollectionParticipantRole role = CollectionParticipantRole.viewer,
     String? publicKey,
     String? publicKey,
   }) async {
   }) async {
     if (!isValidEmail(email)) {
     if (!isValidEmail(email)) {
@@ -112,13 +113,15 @@ class CollectionSharingActions {
     } else if (email == Configuration.instance.getEmail()) {
     } else if (email == Configuration.instance.getEmail()) {
       await showErrorDialog(context, "Oops", "You cannot share with yourself");
       await showErrorDialog(context, "Oops", "You cannot share with yourself");
       return null;
       return null;
-    } else if (collection.getSharees().any((user) => user.email == email)) {
-      showErrorDialog(
-        context,
-        "Oops",
-        "You're already sharing this with " + email,
-      );
-      return null;
+    } else {
+      // if (collection.getSharees().any((user) => user.email == email)) {
+      //   showErrorDialog(
+      //     context,
+      //     "Oops",
+      //     "You're already sharing this with " + email,
+      //   );
+      //   return null;
+      // }
     }
     }
     if (publicKey == null) {
     if (publicKey == null) {
       final dialog = createProgressDialog(context, "Searching for user...");
       final dialog = createProgressDialog(context, "Searching for user...");
@@ -174,7 +177,7 @@ class CollectionSharingActions {
       await dialog.show();
       await dialog.show();
       try {
       try {
         await CollectionsService.instance
         await CollectionsService.instance
-            .share(collection.id, email, publicKey);
+            .share(collection.id, email, publicKey, role);
         collection.sharees?.add((User(email: email)));
         collection.sharees?.add((User(email: email)));
         await dialog.hide();
         await dialog.hide();
 
 

+ 4 - 4
lib/ui/sharing/add_partipant_page.dart

@@ -12,7 +12,6 @@ import 'package:photos/ui/components/menu_item_widget.dart';
 import 'package:photos/ui/components/menu_section_description_widget.dart';
 import 'package:photos/ui/components/menu_section_description_widget.dart';
 import 'package:photos/ui/components/menu_section_title.dart';
 import 'package:photos/ui/components/menu_section_title.dart';
 import 'package:photos/ui/sharing/user_avator_widget.dart';
 import 'package:photos/ui/sharing/user_avator_widget.dart';
-import 'package:photos/utils/toast_util.dart';
 
 
 class AddParticipantPage extends StatefulWidget {
 class AddParticipantPage extends StatefulWidget {
   final Collection collection;
   final Collection collection;
@@ -168,9 +167,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {
                       pressedColor: getEnteColorScheme(context).fillFaint,
                       pressedColor: getEnteColorScheme(context).fillFaint,
                       trailingIcon: !selectAsViewer ? Icons.check : null,
                       trailingIcon: !selectAsViewer ? Icons.check : null,
                       onTap: () async {
                       onTap: () async {
-                        showShortToast(context, "Coming soon!");
-                        // showShortToast(context, "coming soon!");
-                        // setState(() => {selectAsViewer = false});
+                        setState(() => {selectAsViewer = false});
                       },
                       },
                       isBottomBorderRadiusRemoved: true,
                       isBottomBorderRadiusRemoved: true,
                     ),
                     ),
@@ -213,6 +210,9 @@ class _AddParticipantPage extends State<AddParticipantPage> {
                                   context,
                                   context,
                                   widget.collection,
                                   widget.collection,
                                   emailToAdd,
                                   emailToAdd,
+                                  role: selectAsViewer
+                                      ? CollectionParticipantRole.viewer
+                                      : CollectionParticipantRole.collaborator,
                                 );
                                 );
                                 if (result != null && result && mounted) {
                                 if (result != null && result && mounted) {
                                   Navigator.of(context).pop(true);
                                   Navigator.of(context).pop(true);