Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Enhance collection retrieval for UI, adding filtering options and ensuring sync after share URL updates

AmanRajSinghMouryae1cf96466757
diff --git a/mobile/apps/locker/lib/services/collections/collections_api_client.dart b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
index 8b44b6b874..127649c57e 100644
--- a/mobile/apps/locker/lib/services/collections/collections_api_client.dart
+++ b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
@@ -540,6 +540,7 @@ class CollectionApiClient {
await _updateCollectionInDB(collection);
_logger.info("Firing CollectionsUpdatedEvent: share_url_created");
Bus.instance.fire(CollectionsUpdatedEvent("share_url_created"));
+ unawaited(CollectionService.instance.sync());
}
Future<void> disableShareUrl(Collection collection) async {
@@ -548,6 +549,7 @@ class CollectionApiClient {
await _updateCollectionInDB(collection);
_logger.info("Firing CollectionsUpdatedEvent: share_url_disabled");
Bus.instance.fire(CollectionsUpdatedEvent("share_url_disabled"));
+ unawaited(CollectionService.instance.sync());
}
Future<void> updateShareUrl(
@@ -566,6 +568,7 @@ class CollectionApiClient {
await _updateCollectionInDB(collection);
_logger.info("Firing CollectionsUpdatedEvent: share_url_updated");
Bus.instance.fire(CollectionsUpdatedEvent("share_url_updated"));
+ unawaited(CollectionService.instance.sync());
}
Future<List<User>> share(
@@ -594,6 +597,7 @@ class CollectionApiClient {
final updatedCollection = collection!.copyWith(sharees: sharees);
await _updateCollectionInDB(updatedCollection);
Bus.instance.fire(CollectionsUpdatedEvent("email_share_added"));
+ unawaited(CollectionService.instance.sync());
return sharees;
}
@@ -604,6 +608,7 @@ class CollectionApiClient {
final updatedCollection = collection!.copyWith(sharees: sharees);
await _updateCollectionInDB(updatedCollection);
Bus.instance.fire(CollectionsUpdatedEvent("email_share_removed"));
+ unawaited(CollectionService.instance.sync());
return sharees;
}
diff --git a/mobile/apps/locker/lib/services/collections/collections_service.dart b/mobile/apps/locker/lib/services/collections/collections_service.dart
index 76f4e5cf07..c233e065f8 100644
--- a/mobile/apps/locker/lib/services/collections/collections_service.dart
+++ b/mobile/apps/locker/lib/services/collections/collections_service.dart
@@ -158,6 +158,26 @@ class CollectionService {
return collections.where((collection) => !collection.isDeleted).toList();
}
+ Future<List<Collection>> getCollectionsForUI({
+ bool includeViewerCollections = false,
+ bool includeUncategorized = false,
+ }) async {
+ final collections = await getCollections();
+ final int userID = Configuration.instance.getUserID()!;
+
+ return collections.where((c) {
+ if (!includeUncategorized && c.type == CollectionType.uncategorized) {
+ return false;
+ }
+
+ if (includeViewerCollections) {
+ return true;
+ }
+
+ return c.canAdd(userID);
+ }).toList();
+ }
+
Future<Collection?> getCollectionByID(int collectionID) async {
if (_collectionIDToCollections.containsKey(collectionID)) {
return _collectionIDToCollections[collectionID];
diff --git a/mobile/apps/locker/lib/services/collections/models/collection.dart b/mobile/apps/locker/lib/services/collections/models/collection.dart
index 20a9337def..3146a71da5 100644
--- a/mobile/apps/locker/lib/services/collections/models/collection.dart
+++ b/mobile/apps/locker/lib/services/collections/models/collection.dart
@@ -156,6 +156,13 @@ class Collection {
return CollectionParticipantRole.unknown;
}
+ bool canAdd(int userID) {
+ final participantRole = getRole(userID);
+ return (isOwner(userID) ||
+ participantRole == CollectionParticipantRole.collaborator) &&
+ !isDeleted;
+ }
+
void updateSharees(List<User> newSharees) {
sharees.clear();
sharees.addAll(newSharees);
diff --git a/mobile/apps/locker/lib/ui/pages/base_info_page.dart b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
index 4ae29d259c..ac7e510c5f 100644
--- a/mobile/apps/locker/lib/ui/pages/base_info_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
@@ -186,10 +186,8 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
Future<void> _loadCollections() async {
try {
- final collections = await CollectionService.instance.getCollections();
- final filteredCollections = collections
- .where((c) => c.type != CollectionType.uncategorized)
- .toList();
+ final filteredCollections =
+ await CollectionService.instance.getCollectionsForUI();
Set<int> initialSelection = _selectedCollectionIds;
diff --git a/mobile/apps/locker/lib/ui/pages/trash_page.dart b/mobile/apps/locker/lib/ui/pages/trash_page.dart
index 37a8bbcca5..2c1257bba4 100644
--- a/mobile/apps/locker/lib/ui/pages/trash_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/trash_page.dart
@@ -74,15 +74,9 @@ class _TrashPageState extends State<TrashPage> {
}
void _restoreFile(BuildContext context, EnteFile file) async {
- final collections = await CollectionService.instance.getCollections();
+ final collections = await CollectionService.instance.getCollectionsForUI();
- final availableCollections = uniqueCollectionsById(
- collections
- .where(
- (c) => !c.isDeleted && c.type != CollectionType.uncategorized,
- )
- .toList(),
- );
+ final availableCollections = uniqueCollectionsById(collections);
if (availableCollections.isEmpty) {
showToast(
diff --git a/mobile/apps/locker/lib/ui/pages/uploader_page.dart b/mobile/apps/locker/lib/ui/pages/uploader_page.dart
index d41c1c395c..2b405e1609 100644
--- a/mobile/apps/locker/lib/ui/pages/uploader_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/uploader_page.dart
@@ -64,12 +64,8 @@ abstract class UploaderPageState<T extends UploaderPage> extends State<T> {
try {
final List<Future> futures = [];
- final collections = await CollectionService.instance.getCollections();
- final regularCollections = collections
- .where(
- (c) => c.type != CollectionType.uncategorized,
- )
- .toList();
+ final regularCollections =
+ await CollectionService.instance.getCollectionsForUI();
// Navigate to upload screen to get collection selection
final uploadResult =
diff --git a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
index 9428167d66..5cbc862874 100644
--- a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
+++ b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
@@ -449,7 +449,9 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
_logger.info(
'Opening add-to dialog for ${files.length} file(s); fetching collections.',
);
- final allCollections = await CollectionService.instance.getCollections();
+
+ final allCollections =
+ await CollectionService.instance.getCollectionsForUI();
final dedupedCollections = uniqueCollectionsById(allCollections);
_logger.info(
'Presenting ${dedupedCollections.length} unique collection option(s) '