Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix stale suggestion when ignoring suggestion

laurenspriemed49353516a6
diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
index 110d597f03..1118953262 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_app_bar.dart
@@ -21,6 +21,7 @@ import "package:photos/services/machine_learning/face_ml/feedback/cluster_feedba
import "package:photos/services/machine_learning/ml_result.dart";
import 'package:photos/ui/actions/collection/collection_sharing_actions.dart';
import "package:photos/ui/common/popup_item.dart";
+import 'package:photos/ui/components/buttons/button_widget.dart';
import "package:photos/ui/viewer/people/cluster_breakup_page.dart";
import "package:photos/ui/viewer/people/cluster_page.dart";
import "package:photos/utils/dialog_util.dart";
@@ -166,7 +167,7 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
}
Future<void> _onIgnoredClusterClicked(BuildContext context) async {
- await showChoiceDialog(
+ final result = await showChoiceDialog(
context,
title: AppLocalizations.of(context).areYouSureYouWantToIgnoreThisPerson,
body: AppLocalizations.of(context).thePersonGroupsWillNotBeDisplayed,
@@ -174,13 +175,18 @@ class _AppBarWidgetState extends State<ClusterAppBar> {
firstButtonOnTap: () async {
try {
await ClusterFeedbackService.instance.ignoreCluster(widget.clusterID);
- Navigator.of(context).pop(); // Close the cluster page
} catch (e, s) {
_logger.severe('Ignoring a cluster failed', e, s);
- // await showGenericErrorDialog(context: context, error: e);
+ rethrow;
}
},
);
+
+ if (!mounted || result?.action != ButtonAction.first) {
+ return;
+ }
+
+ Navigator.of(context).pop(ClusterPageResult.ignoredPerson);
}
Future<void> _breakUpCluster(BuildContext context) async {
diff --git a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
index 1be47079e3..2984b4b683 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/cluster_page.dart
@@ -59,6 +59,10 @@ class ClusterPage extends StatefulWidget {
State<ClusterPage> createState() => _ClusterPageState();
}
+enum ClusterPageResult {
+ ignoredPerson,
+}
+
class _ClusterPageState extends State<ClusterPage> {
final _selectedFiles = SelectedFiles();
late final List<EnteFile> files;
diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_gallery_suggestion.dart b/mobile/apps/photos/lib/ui/viewer/people/person_gallery_suggestion.dart
index 155cd48898..aafc6b5221 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/person_gallery_suggestion.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/person_gallery_suggestion.dart
@@ -196,7 +196,7 @@ class _PersonGallerySuggestionState extends State<PersonGallerySuggestion>
return faceCrops;
}
- void _navigateToCluster() {
+ Future<void> _navigateToCluster() async {
if (allSuggestions.isEmpty ||
currentSuggestionIndex >= allSuggestions.length) {
return;
@@ -209,7 +209,7 @@ class _PersonGallerySuggestionState extends State<PersonGallerySuggestion>
sortedFiles.sort(
(a, b) => b.creationTime!.compareTo(a.creationTime!),
);
- Navigator.of(context).push(
+ final result = await Navigator.of(context).push<ClusterPageResult>(
MaterialPageRoute(
builder: (context) => ClusterPage(
sortedFiles,
@@ -219,6 +219,46 @@ class _PersonGallerySuggestionState extends State<PersonGallerySuggestion>
),
),
);
+
+ if (!mounted || result != ClusterPageResult.ignoredPerson) {
+ return;
+ }
+
+ await _consumeCurrentSuggestionAfterExternalAction();
+ }
+
+ Future<void> _consumeCurrentSuggestionAfterExternalAction() async {
+ if (isProcessing ||
+ allSuggestions.isEmpty ||
+ currentSuggestionIndex >= allSuggestions.length) {
+ return;
+ }
+
+ setState(() {
+ isProcessing = true;
+ });
+
+ try {
+ await _animateOut();
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ hasCurrentSuggestion = false;
+ });
+ await _prepareNextSuggestion();
+ } catch (e, s) {
+ _logger.severe(
+ "Error consuming suggestion after external action",
+ e,
+ s,
+ );
+ if (mounted) {
+ setState(() {
+ isProcessing = false;
+ });
+ }
+ }
}
Future<void> _handleUserChoice(bool accepted) async {