Add method to leave collection
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>{};
|
||||
|
||||
@@ -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 album
|
||||
Future<bool> removeParticipant(
|
||||
BuildContext context,
|
||||
Collection collection,
|
||||
@@ -455,5 +502,4 @@ class CollectionActions {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user