π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add method to leave collection
AmanRajSinghMourya5036a8da5928
diff --git a/mobile/apps/locker/lib/services/collections/collections_api_client.dart b/mobile/apps/locker/lib/services/collections/collections_api_client.dartindex 9867e3880b..e4e0d1fc60 100644--- a/mobile/apps/locker/lib/services/collections/collections_api_client.dart+++ b/mobile/apps/locker/lib/services/collections/collections_api_client.dart@@ -171,6 +171,26 @@ class CollectionApiClient {}}+ Future<void> leaveCollection(Collection collection) async {+ try {+ await _enteDio.post(+ "/collections/leave/${collection.id}",+ );+ await _handleCollectionDeletion(collection);+ Bus.instance.fire(CollectionsUpdatedEvent());+ } catch (e, s) {+ _logger.severe("failed to leave collection", e, s);+ rethrow;+ }+ }++ Future<void> _handleCollectionDeletion(Collection collection) async {+ await _db.deleteCollection(collection);+ final deletedCollection = collection.copyWith(isDeleted: true);+ unawaited(_db.updateCollections([deletedCollection]));+ CollectionService.instance.updateCollectionCache(deletedCollection);+ }+Future<void> move(EnteFile file,Collection fromCollection,@@ -423,8 +443,13 @@ class CollectionApiClient {await _db.updateCollections([collection]);CollectionService.instance.updateCollectionCache(collection);Bus.instance.fire(CollectionsUpdatedEvent());+ } on DioException catch (e) {+ if (e.response?.statusCode == 402) {+ throw SharingNotPermittedForFreeAccountsError();+ }+ rethrow;} catch (e, s) {- _logger.severe('Failed to create share URL for collection', e, s);+ _logger.severe("failed to rename collection", e, s);rethrow;}}diff --git a/mobile/apps/locker/lib/services/collections/collections_service.dart b/mobile/apps/locker/lib/services/collections/collections_service.dartindex c2d92a9798..b92b2b568d 100644--- a/mobile/apps/locker/lib/services/collections/collections_service.dart+++ b/mobile/apps/locker/lib/services/collections/collections_service.dart@@ -59,6 +59,9 @@ class CollectionService {_init();});}+ Bus.instance.on<CollectionsUpdatedEvent>().listen((event) {+ _init();+ });}Future<void> sync() async {@@ -401,8 +404,6 @@ class CollectionService {/// - Owners of collections shared to user./// - All collaborators of collections in which user is a collaborator or/// a viewer.- /// - All family members of user.- /// - All contacts linked to a person.List<User> getRelevantContacts() {final List<User> relevantUsers = [];final existingEmails = <String>{};diff --git a/mobile/apps/locker/lib/utils/collection_actions.dart b/mobile/apps/locker/lib/utils/collection_actions.dartindex ce17a4420e..d0a014e573 100644--- a/mobile/apps/locker/lib/utils/collection_actions.dart+++ b/mobile/apps/locker/lib/utils/collection_actions.dart@@ -171,6 +171,53 @@ class CollectionActions {}}+ static Future<void> leaveCollection(+ BuildContext context,+ Collection collection, {+ VoidCallback? onSuccess,+ }) async {+ final actionResult = await showActionSheet(+ context: context,+ buttons: [+ ButtonWidget(+ buttonType: ButtonType.critical,+ isInAlert: true,+ shouldStickToDarkTheme: true,+ buttonAction: ButtonAction.first,+ shouldSurfaceExecutionStates: true,+ labelText: context.l10n.leaveCollection,+ onTap: () async {+ await CollectionApiClient.instance.leaveCollection(collection);+ },+ ),+ ButtonWidget(+ buttonType: ButtonType.secondary,+ buttonAction: ButtonAction.cancel,+ isInAlert: true,+ shouldStickToDarkTheme: true,+ labelText: context.l10n.cancel,+ ),+ ],+ title: context.l10n.leaveCollection,+ body: context.l10n.filesAddedByYouWillBeRemovedFromTheCollection,+ );+ if (actionResult?.action != null && context.mounted) {+ if (actionResult!.action == ButtonAction.error) {+ await showGenericErrorDialog(+ context: context,+ error: actionResult.exception,+ );+ } else if (actionResult.action == ButtonAction.first) {+ onSuccess?.call();+ Navigator.of(context).pop();+ SnackBarUtils.showInfoSnackBar(+ context,+ "Leave collection successfully",+ );+ }+ }+ }+static Future<bool> enableUrl(BuildContext context,Collection collection, {@@ -411,7 +458,7 @@ class CollectionActions {}}- // removeParticipant remove the user from a share album+ // removeParticipant remove the user from a share albumFuture<bool> removeParticipant(BuildContext context,Collection collection,@@ -455,5 +502,4 @@ class CollectionActions {}return false;}-}