π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] refactor bulk cluster ignore path
Priyanshu Dangare087717374b0e
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dartindex 7499ae295b..e8361b8cea 100644--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/feedback/cluster_feedback.dart@@ -1230,7 +1230,7 @@ class ClusterFeedbackService<T> {return finalSuggestions;}- Future<bool> checkAndDoAutomaticMerges(+ Future<Set<String>?> checkAndDoAutomaticMerges(PersonEntity p, {required String personClusterID,bool firePeopleChangedEvent = true,@@ -1243,7 +1243,7 @@ class ClusterFeedbackService<T> {_logger.info('Cluster $personClusterID has less than $kMinimumClusterSizeSearchResult faces, not doing automatic merges',);- return false;+ return null;}}final List<(String, double, String)> suggestions =@@ -1257,7 +1257,7 @@ class ClusterFeedbackService<T> {_logger.info('No automatic merge suggestions for ${kDebugMode ? p.data.name : "private"}',);- return false;+ return null;}_logger.info(@@ -1282,7 +1282,7 @@ class ClusterFeedbackService<T> {);}- return true;+ return suggestions.map((s) => s.$1).toSet();}Future<void> addClusterToExistingPerson({@@ -1315,7 +1315,7 @@ class ClusterFeedbackService<T> {);}- Future<PersonEntity> ignoreCluster(+ Future<(PersonEntity, Set<String>?)> ignoreCluster(String clusterID, {bool firePeopleChangedEvent = true,}) async {@@ -1324,17 +1324,61 @@ class ClusterFeedbackService<T> {clusterID: clusterID,isHidden: true,);- final merged = await checkAndDoAutomaticMerges(+ final mergedClusterIDs = await checkAndDoAutomaticMerges(ignoredPerson,personClusterID: clusterID,firePeopleChangedEvent: firePeopleChangedEvent,);- if (!merged && firePeopleChangedEvent) {+ if (firePeopleChangedEvent && mergedClusterIDs == null) {Bus.instance.fire(PeopleChangedEvent(person: ignoredPerson, source: "ignore_cluster"),);}- return ignoredPerson;+ return (ignoredPerson, mergedClusterIDs);+ }++ Future<void> ignoreClusters(+ Iterable<String> clusterIDs, {+ void Function(int completed, int total)? onProgress,+ }) async {+ final remainingClusterIDs = clusterIDs.toSet();+ final total = remainingClusterIDs.length;+ final ignoredPersons = <PersonEntity>[];+ final assignedClusterIDs = <String>{};+ var automaticallyMerged = false;++ try {+ // Automatic merges can satisfy other requested clusters in the batch.+ while (remainingClusterIDs.isNotEmpty) {+ final clusterID = remainingClusterIDs.first;+ final (ignoredPerson, mergedClusterIDs) = await ignoreCluster(+ clusterID,+ firePeopleChangedEvent: false,+ );+ ignoredPersons.add(ignoredPerson);+ assignedClusterIDs.add(clusterID);+ remainingClusterIDs.remove(clusterID);+ if (mergedClusterIDs != null) {+ automaticallyMerged = true;+ assignedClusterIDs.addAll(mergedClusterIDs);+ remainingClusterIDs.removeAll(mergedClusterIDs);+ }+ onProgress?.call(total - remainingClusterIDs.length, total);+ }+ } finally {+ if (ignoredPersons.isNotEmpty) {+ Bus.instance.fire(+ PeopleChangedEvent(+ type: automaticallyMerged+ ? PeopleEventType.automaticallyMergedClustersIntoPerson+ : PeopleEventType.defaultType,+ person: ignoredPersons.first,+ source: "ignore_clusters",+ newClusterIDs: assignedClusterIDs,+ ),+ );+ }+ }}Future<List<(String, int)>> checkForMixedClusters() async {diff --git a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dartindex 2004646a7e..c48a6143b0 100644--- a/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/actions/people_selection_action_widget.dart@@ -488,21 +488,19 @@ class _PeopleSelectionActionWidgetStateawait dialog.show();}var completed = 0;- var hasUpdates = false;+ var hasPersonUpdates = false;var completedAll = false;try {- for (final clusterID in selectedClusterIds) {- await ClusterFeedbackService.instance.ignoreCluster(- clusterID,- firePeopleChangedEvent: false,- );- completed++;- hasUpdates = true;- dialog?.update(- message: _bulkIgnoreProgressMessage(l10n, completed, total),- );- }+ await ClusterFeedbackService.instance.ignoreClusters(+ selectedClusterIds,+ onProgress: (ignoredClusters, _) {+ completed = ignoredClusters;+ dialog?.update(+ message: _bulkIgnoreProgressMessage(l10n, completed, total),+ );+ },+ );for (final personID in personIdsToIgnore) {final person = personMap[personID];@@ -512,7 +510,7 @@ class _PeopleSelectionActionWidgetState);await PersonService.instance.updatePerson(ignoredPerson);completed++;- hasUpdates = true;+ hasPersonUpdates = true;dialog?.update(message: _bulkIgnoreProgressMessage(l10n, completed, total),);@@ -523,7 +521,7 @@ class _PeopleSelectionActionWidgetStateif (completedAll) {widget.selectedPeople.clearAll();}- if (hasUpdates) {+ if (hasPersonUpdates) {Bus.instance.fire(PeopleChangedEvent());}if (dialog != null) {diff --git a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dartindex b352b2dc2f..6bcae52f65 100644--- a/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart+++ b/mobile/apps/photos/lib/ui/viewer/file_details/file_info_faces_item_widget.dart@@ -561,21 +561,14 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {if (dialog != null) {await dialog.show();}- var completed = 0;- var hasUpdates = false;var completedAll = false;- final changedPersons = <PersonEntity>[];try {- for (final clusterID in clusterIDs) {- final ignoredPerson = await ClusterFeedbackService.instance- .ignoreCluster(clusterID, firePeopleChangedEvent: false);- changedPersons.add(ignoredPerson);- completed++;- hasUpdates = true;- dialog?.update(+ await ClusterFeedbackService.instance.ignoreClusters(+ clusterIDs,+ onProgress: (completed, _) => dialog?.update(message: _bulkIgnoreProgressMessage(l10n, completed, total),- );- }+ ),+ );completedAll = true;} catch (e, s) {_logger.severe('Error while ignoring selected face clusters', e, s);@@ -586,21 +579,9 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {if (completedAll && mounted) {_clearSelectionMode();}- if (hasUpdates) {- _firePeopleChangedEvents(changedPersons);- }}}- void _firePeopleChangedEvents(List<PersonEntity> changedPersons) {- Bus.instance.fire(- PeopleChangedEvent(- person: changedPersons.isEmpty ? null : changedPersons.first,- source: "file_details_bulk_ignore_faces",- ),- );- }-String _bulkIgnoreProgressMessage(StringsLocalizations l10n,int completed,diff --git a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dartindex b42830cbf6..9ae3aa4ab4 100644--- a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart@@ -626,8 +626,12 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {email: email,userID: currentUserIDForContactLinkEmail(email),);- final bool extraPhotosFound = await ClusterFeedbackService.instance- .checkAndDoAutomaticMerges(personEntity, personClusterID: clusterID);+ final bool extraPhotosFound =+ await ClusterFeedbackService.instance.checkAndDoAutomaticMerges(+ personEntity,+ personClusterID: clusterID,+ ) !=+ null;if (extraPhotosFound && context.mounted) {showShortToast(context, context.strings.extraPhotosFound);}diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dartindex c92fb4b861..673d6ce88b 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart@@ -544,7 +544,7 @@ class _EditContactPageState extends State<EditContactPage> {error,stackTrace,);- return false;+ return null;}),);_draftLinkedPerson = person;