diff --git a/mobile/lib/ui/viewer/people/link_email_screen.dart b/mobile/lib/ui/viewer/people/link_email_screen.dart index 1645dc15f1..dc026b60a7 100644 --- a/mobile/lib/ui/viewer/people/link_email_screen.dart +++ b/mobile/lib/ui/viewer/people/link_email_screen.dart @@ -228,6 +228,10 @@ class _LinkEmailScreen extends State { Navigator.of(context).pop(newEmail); } catch (e) { + await showGenericErrorDialog( + context: context, + error: e, + ); _logger.severe("Failed to link email to person", e); } } @@ -330,7 +334,7 @@ class _LinkEmailScreen extends State { String personID, BuildContext context, ) async { - if (await checkIfEmailAlreadyAssignedToAPerson(context, email)) { + if (await checkIfEmailAlreadyAssignedToAPerson(email)) { throw Exception("Email already linked to a person"); } diff --git a/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart b/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart index c626529447..7450bb1ace 100644 --- a/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart +++ b/mobile/lib/ui/viewer/people/person_selection_action_widgets.dart @@ -118,18 +118,17 @@ class _LinkContactToPersonSelectionPageState return _RoundedPersonFaceWidget( onTap: () async { try { - unawaited( - linkPersonToContact( - context, - emailToLink: widget.emailToLink!, - personEntity: results[index].person, - ).then((updatedPerson) { - if (updatedPerson != null) { - Navigator.of(context).pop(updatedPerson); - } - }), + final updatedPerson = await linkPersonToContact( + context, + emailToLink: widget.emailToLink!, + personEntity: results[index].person, ); + + if (updatedPerson != null) { + Navigator.of(context).pop(updatedPerson); + } } catch (e) { + await showGenericErrorDialog(context: context, error: e); _logger.severe("Failed to link person to contact", e); } }, @@ -149,8 +148,8 @@ class _LinkContactToPersonSelectionPageState required String emailToLink, required PersonEntity personEntity, }) async { - if (await checkIfEmailAlreadyAssignedToAPerson(context, emailToLink)) { - throw Exception("Email already linked"); + if (await checkIfEmailAlreadyAssignedToAPerson(emailToLink)) { + throw Exception("Email already linked to a person"); } final personName = personEntity.data.name; diff --git a/mobile/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/lib/ui/viewer/people/save_or_edit_person.dart index 515ddb92cb..1525abb8c6 100644 --- a/mobile/lib/ui/viewer/people/save_or_edit_person.dart +++ b/mobile/lib/ui/viewer/people/save_or_edit_person.dart @@ -330,7 +330,10 @@ class _SaveOrEditPersonState extends State { clusterID: widget.clusterID!, birthdate: _selectedDate, email: _email, - ); + ).catchError((e) { + _logger.severe("Error adding new person", e); + return null; + }); if (newPersonEntity != null) { Navigator.pop(context, newPersonEntity); } @@ -380,11 +383,7 @@ class _SaveOrEditPersonState extends State { shouldStickToDarkTheme: true, onTap: () async { if (widget.isEditing) { - try { - updatedPersonEntity = await updatePerson(context); - } catch (e) { - _logger.severe("Error updating person", e); - } + updatedPersonEntity = await updatePerson(context); } else { try { updatedPersonEntity = await addNewPerson( @@ -541,9 +540,17 @@ class _SaveOrEditPersonState extends State { }) async { if (email != null && email.isNotEmpty && - await checkIfEmailAlreadyAssignedToAPerson(context, email)) { - throw Exception("Email already assigned to a person"); + await checkIfEmailAlreadyAssignedToAPerson(email)) { + _logger.severe( + "Failed to addNewPerson, email is already assigned to a person", + ); + await showGenericErrorDialog( + context: context, + error: "Email already assigned", + ); + return null; } + try { if (userAlreadyAssigned) { return null; @@ -593,7 +600,7 @@ class _SaveOrEditPersonState extends State { if (_email != null && _email!.isNotEmpty && _email != person!.data.email && - await checkIfEmailAlreadyAssignedToAPerson(context, _email!)) { + await checkIfEmailAlreadyAssignedToAPerson(_email!)) { throw Exception("Email already assigned to a person"); } final String name = _inputName.trim(); diff --git a/mobile/lib/utils/person_contact_linking_util.dart b/mobile/lib/utils/person_contact_linking_util.dart index 0c7b6542a5..cf8877269e 100644 --- a/mobile/lib/utils/person_contact_linking_util.dart +++ b/mobile/lib/utils/person_contact_linking_util.dart @@ -1,23 +1,11 @@ -import "dart:io"; - -import "package:flutter/material.dart"; import "package:photos/services/machine_learning/face_ml/person/person_service.dart"; -import "package:photos/utils/dialog_util.dart"; Future checkIfEmailAlreadyAssignedToAPerson( - BuildContext context, String email, ) async { final persons = await PersonService.instance.getPersons(); for (var person in persons) { if (person.data.email == email) { - await showErrorDialog( - context, - "Email already linked", - "This email is already linked to a person", - useRootNavigator: Platform.isIOS, - ); - return true; } }