Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mobile][photos] wait for auto-add updates

r4khul42dcdeaaf09d
diff --git a/mobile/apps/photos/lib/services/smart_albums_service.dart b/mobile/apps/photos/lib/services/smart_albums_service.dart
index 67d77c501b..0b166c073e 100644
--- a/mobile/apps/photos/lib/services/smart_albums_service.dart
+++ b/mobile/apps/photos/lib/services/smart_albums_service.dart
@@ -81,22 +81,39 @@ class SmartAlbumsService {
}
Future<void> syncSmartAlbums() async {
+ await _syncSmartAlbums();
+ }
+
+ Future<void> syncSmartAlbumsFor(Set<int> collectionIds) =>
+ _syncSmartAlbums(collectionIds: collectionIds);
+
+ Future<void> _syncSmartAlbums({Set<int>? collectionIds}) async {
final isMLEnabled = hasGrantedMLConsent;
if (!isMLEnabled) {
_logger.warning("ML is not enabled, skipping smart album sync");
+ if (collectionIds != null) throw StateError("ML is not enabled");
return;
}
_logger.info("Syncing Smart Albums");
final cachedConfigs = await getSmartConfigs();
+ if (collectionIds != null &&
+ !cachedConfigs.keys.toSet().containsAll(collectionIds)) {
+ throw StateError("Smart album config is missing");
+ }
final userId = Configuration.instance.getUserID();
if (userId == null) {
_logger.warning("No user ID, skipping smart album sync");
+ if (collectionIds != null) throw StateError("No user ID");
return;
}
+ var hasFailed = false;
for (final entry in cachedConfigs.entries) {
final collectionId = entry.key;
+ if (collectionIds != null && !collectionIds.contains(collectionId)) {
+ continue;
+ }
final config = entry.value;
if (config.personIDs.isEmpty) {
@@ -114,6 +131,7 @@ class SmartAlbumsService {
_logger.warning(
"For config ($collectionId) user does not have permission",
);
+ hasFailed = true;
if (collection?.isDeleted ?? false) {
await _deleteEntry(userId: userId, collectionId: collectionId);
}
@@ -181,11 +199,15 @@ class SmartAlbumsService {
await saveConfig(newConfig);
} catch (e, sT) {
_logger.warning(e, sT);
+ hasFailed = true;
}
}
}
syncingCollection = null;
Bus.instance.fire(SmartAlbumSyncingEvent());
+ if (collectionIds != null && hasFailed) {
+ throw StateError("Failed to sync one or more smart albums");
+ }
_logger.fine("Smart Albums sync completed");
}
@@ -253,7 +275,7 @@ class SmartAlbumsService {
addWithCustomID: addWithCustomID,
);
- _lastCacheRefreshTime = 0;
+ clearCache();
return result;
}
@@ -264,6 +286,6 @@ class SmartAlbumsService {
_logger.fine("Deleting entry for collection ($collectionId)");
final id = getId(collectionId: collectionId, userId: userId);
await entityService.deleteEntry(id);
- _lastCacheRefreshTime = 0;
+ clearCache();
}
}
diff --git a/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart b/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart
index 2dbb048aa4..914b4aa036 100644
--- a/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart
+++ b/mobile/apps/photos/lib/ui/collections/album/smart_album_people.dart
@@ -82,7 +82,7 @@ class _SmartAlbumPeopleState extends State<SmartAlbumPeople> {
final dialog = createProgressDialog(
context,
context.strings.pleaseWait,
- isDismissible: true,
+ isDismissible: false,
);
if (_selectedPeople.personIds.length ==
@@ -165,14 +165,16 @@ class _SmartAlbumPeopleState extends State<SmartAlbumPeople> {
}
await smartAlbumsService.saveConfig(newConfig);
- unawaited(smartAlbumsService.syncSmartAlbums());
+ await smartAlbumsService.syncSmartAlbumsFor({
+ widget.collectionId,
+ });
await dialog.hide();
if (!context.mounted) return;
Navigator.pop(context);
} catch (error, stackTrace) {
_logger.severe(
- "Error saving smart album config",
+ "Error updating smart album",
error,
stackTrace,
);
diff --git a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
index e4b278228c..67c6d2ceb1 100644
--- a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
+++ b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart
@@ -235,7 +235,7 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
key: const ValueKey('add_button'),
label: context.strings.add,
shouldSurfaceExecutionStates: false,
- dismissModalOnSuccess: true,
+ dismissModalOnSuccess: widget.selectedPeople == null,
onTap: () async {
if (widget.selectedPeople != null) {
final ProgressDialog dialog = createProgressDialog(
@@ -243,23 +243,44 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
context.strings.uploadingFilesToAlbum,
isDismissible: true,
);
- await dialog.show();
- for (final collection in _selectedCollections) {
- try {
- await smartAlbumsService.addPeopleToSmartAlbum(
- collection.id,
- widget.selectedPeople!,
- );
- } catch (error, stackTrace) {
- _logger.severe(
- "Error while adding people to smart album",
- error,
- stackTrace,
- );
+ final updatedAlbumIds = <int>{};
+ Object? firstError;
+ try {
+ await dialog.show();
+ for (final collection in _selectedCollections) {
+ try {
+ await smartAlbumsService.addPeopleToSmartAlbum(
+ collection.id,
+ widget.selectedPeople!,
+ );
+ updatedAlbumIds.add(collection.id);
+ } catch (error, stackTrace) {
+ firstError ??= error;
+ _logger.severe(
+ "Error while adding people to smart album",
+ error,
+ stackTrace,
+ );
+ }
+ }
+ if (updatedAlbumIds.isNotEmpty) {
+ await smartAlbumsService.syncSmartAlbumsFor(updatedAlbumIds);
}
+ } catch (error, stackTrace) {
+ firstError ??= error;
+ _logger.severe("Error syncing smart albums", error, stackTrace);
+ } finally {
+ await dialog.hide();
+ }
+ if (!mounted) return;
+ if (firstError != null) {
+ await showGenericErrorDialog(
+ context: context,
+ error: firstError,
+ );
+ return;
}
- unawaited(smartAlbumsService.syncSmartAlbums());
- await dialog.hide();
+ Navigator.pop(context);
return;
}
final CollectionActions collectionActions = CollectionActions(