π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
refactor bulk ignore
laurenspriem253f8daf9ba3
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 24908c52bf..1aa723f61c 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@@ -526,84 +526,95 @@ class _FacesItemWidgetState extends State<FacesItemWidget> {final selectedFaces = _selectedFaceInfos();if (selectedFaces.isEmpty) return;+ final l10n = AppLocalizations.of(context);+ final multiple = selectedFaces.length > 1;final result = await showChoiceActionSheet(context,- title: selectedFaces.length == 1- ? AppLocalizations.of(context).areYouSureYouWantToIgnoreThisPerson- : AppLocalizations.of(context).areYouSureYouWantToIgnoreThesePersons,- body: selectedFaces.length == 1- ? AppLocalizations.of(context).thePersonWillNotBeDisplayed- : AppLocalizations.of(context).thePersonGroupsWillNotBeDisplayed,- firstButtonLabel: AppLocalizations.of(context).yesIgnore,+ title: multiple+ ? l10n.areYouSureYouWantToIgnoreThesePersons+ : l10n.areYouSureYouWantToIgnoreThisPerson,+ body: multiple+ ? l10n.thePersonGroupsWillNotBeDisplayed+ : l10n.thePersonWillNotBeDisplayed,+ firstButtonLabel: l10n.yesIgnore,firstButtonType: ButtonType.critical,- secondButtonLabel: AppLocalizations.of(context).cancel,+ secondButtonLabel: l10n.cancel,isCritical: true,);- if (result?.action != ButtonAction.first) return;+ if (!mounted || result?.action != ButtonAction.first) return;++ final mlDataDB = MLDataDB.instance;- final mlDataDB = isLocalGalleryMode- ? MLDataDB.localGalleryInstance- : MLDataDB.instance;final faceIDToNewClusterID = <String, String>{};- final createdPersonIDs = <String>[];+ final clusterIDs = <String>{};+ final faceIdToClusterIdResults = await Future.wait(+ selectedFaces.map((f) async {+ final clusterID =+ f.clusterID ?? await mlDataDB.getClusterIDForFaceID(f.face.faceID);+ return MapEntry(f.face.faceID, clusterID);+ }),+ );+ for (final entry in faceIdToClusterIdResults) {+ var clusterID = entry.value;+ if (clusterID == null) {+ clusterID = newClusterID();+ faceIDToNewClusterID[entry.key] = clusterID;+ }+ clusterIDs.add(clusterID);+ }+ if (faceIDToNewClusterID.isNotEmpty) {+ await mlDataDB.updateFaceIdToClusterId(faceIDToNewClusterID);+ }+ final total = clusterIDs.length;+ final dialog = total > 1+ ? createProgressDialog(+ context,+ _bulkIgnoreProgressMessage(l10n, 0, total),+ )+ : null;+ if (dialog != null) {+ await dialog.show();+ }+ var completed = 0;+ var hasUpdates = false;+ var completedAll = false;try {- final clusterIDs = <String>{};-- final faceIdToClusterIdResults = await Future.wait(- selectedFaces.map((f) async {- final clusterID =- f.clusterID ??- await mlDataDB.getClusterIDForFaceID(f.face.faceID);- return MapEntry(f.face.faceID, clusterID);- }),- );-- for (final entry in faceIdToClusterIdResults) {- var clusterID = entry.value;- if (clusterID == null) {- clusterID = newClusterID();- faceIDToNewClusterID[entry.key] = clusterID;- }- clusterIDs.add(clusterID);+ for (final clusterID in clusterIDs) {+ await ClusterFeedbackService.instance.ignoreCluster(+ clusterID,+ firePeopleChangedEvent: false,+ );+ completed++;+ hasUpdates = true;+ dialog?.update(+ message: _bulkIgnoreProgressMessage(l10n, completed, total),+ );}-- if (faceIDToNewClusterID.isNotEmpty) {- await mlDataDB.updateFaceIdToClusterId(faceIDToNewClusterID);+ completedAll = true;+ } catch (e, s) {+ _logger.severe('Error while ignoring selected face clusters', e, s);+ } finally {+ if (hasUpdates) {+ Bus.instance.fire(PeopleChangedEvent());}-- await Future.wait(- clusterIDs.map((clusterID) async {- try {- final ignoredPerson = await PersonService.instance.addPerson(- name: '',- clusterID: clusterID,- isHidden: true,- );- createdPersonIDs.add(ignoredPerson.remoteID);- // Try automatic merges for the ignored person but avoid firing events per cluster- await ClusterFeedbackService.instance.checkAndDoAutomaticMerges(- ignoredPerson,- personClusterID: clusterID,- firePeopleChangedEvent: false,- );- } catch (e, s) {- _logger.warning('Error ignoring cluster $clusterID', e, s);- }- }),- );-- // Fire a single people changed event and reload faces- Bus.instance.fire(PeopleChangedEvent());- if (mounted) {+ if (dialog != null) {+ await dialog.hide();+ }+ if (completedAll && mounted) {_clearSelectionMode();- await loadFaces(isRefresh: true);}- } catch (e, s) {- _logger.severe('Error while ignoring unlinked faces', e, s);}}+ String _bulkIgnoreProgressMessage(+ AppLocalizations l10n,+ int completed,+ int total,+ ) {+ return "${l10n.pleaseWait} ($completed/$total)";+ }+Future<_FaceDataResult> _fetchFaceData() async {final bool isLocalGallery = isLocalGalleryMode;int? fileKey;