Skip to content

armgit / ente

Public Imported from GitHub
0

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

Keep person avatar updates on contact failure

Neeraj Guptac7c920a6a4ef
diff --git a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
index eb2f8bee90..388f6df83b 100644
--- a/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/face_ml/person/person_service.dart
@@ -29,6 +29,10 @@ typedef ManualPersonAssignmentResult = ({
List<int> addedFileIds,
List<int> alreadyAssignedFileIds,
});
+typedef PersonAvatarUpdateResult = ({
+ PersonEntity person,
+ bool contactPictureUpdateFailed,
+});
class PersonService {
static const Object _attributeNotProvided = Object();
@@ -603,7 +607,10 @@ class PersonService {
return changed;
}
- Future<PersonEntity> updateAvatar(PersonEntity p, EnteFile file) async {
+ Future<PersonAvatarUpdateResult> updateAvatar(
+ PersonEntity p,
+ EnteFile file,
+ ) async {
final Face? face = await faceMLDataDB.getCoverFaceForPerson(
recentFileID: file.uploadedFileID!,
personID: p.remoteID,
@@ -615,13 +622,22 @@ class PersonService {
}
final person = (await getPerson(p.remoteID))!;
- await _updateLinkedContactAvatarBeforePerson(person, file, face);
+ var contactPictureUpdateFailed = false;
+ try {
+ await _updateLinkedContactAvatarBeforePerson(person, file, face);
+ } catch (e, s) {
+ contactPictureUpdateFailed = true;
+ logger.warning("Failed to update linked contact picture", e, s);
+ }
final updatedPerson = person.copyWith(
data: person.data.copyWith(avatarFaceId: face.faceID),
);
await updatePerson(updatedPerson);
await putFaceIdCachedForPersonOrCluster(p.remoteID, face.faceID);
- return updatedPerson;
+ return (
+ person: updatedPerson,
+ contactPictureUpdateFailed: contactPictureUpdateFailed,
+ );
}
Future<void> _updateLinkedContactAvatarBeforePerson(
diff --git a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
index 99055cd421..8230264e1c 100644
--- a/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
+++ b/mobile/apps/photos/lib/ui/viewer/actions/file_selection_actions_widget.dart
@@ -939,13 +939,17 @@ class _FileSelectionActionsWidgetState
Future<void> _setPersonCover() async {
final EnteFile file = widget.selectedFiles.files.first;
- final updatedPerson = await PersonService.instance.updateAvatar(
+ final result = await PersonService.instance.updateAvatar(
widget.person!,
file,
);
+ final updatedPerson = result.person;
widget.selectedFiles.clearAll();
if (mounted) {
setState(() => {});
+ if (result.contactPictureUpdateFailed) {
+ showShortToast(context, "Failed to update contact picture");
+ }
}
Bus.instance.fire(
PeopleChangedEvent(
diff --git a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
index 3acb2eef5b..91cd7b4f25 100644
--- a/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/gallery/hooks/pick_person_avatar.dart
@@ -14,6 +14,7 @@ import "package:photos/ui/components/bottom_of_title_bar_widget.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/components/title_bar_title_widget.dart";
+import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/viewer/gallery/gallery.dart";
import "package:photos/ui/viewer/gallery/state/gallery_files_inherited_widget.dart";
@@ -145,11 +146,17 @@ class PickPersonCoverPhotoWidget extends StatelessWidget {
Bus.instance.fire(
PeopleChangedEvent(
type: PeopleEventType.saveOrEditPerson,
- person: result,
+ person: result.person,
),
);
if (!context.mounted) return;
- Navigator.pop(context, result);
+ if (result.contactPictureUpdateFailed) {
+ showShortToast(
+ context,
+ "Failed to update contact picture",
+ );
+ }
+ Navigator.pop(context, result.person);
},
),
);