Skip to content

armgit / ente

Public Imported from GitHub
0

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

Tighten linked contact auto-creation

Neeraj Gupta5b0eacd99a22
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 bd3ee41fcd..7fdd235dd5 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
@@ -761,21 +761,15 @@ class PersonService {
required int contactUserId,
required String email,
}) {
- final pending = _autoContactCreationsByUserId[contactUserId];
- if (pending != null) {
- return pending;
- }
-
- final creation = _tryAutoCreateContactForLinkedPerson(
- person: person,
- contactUserId: contactUserId,
- email: email,
- );
- _autoContactCreationsByUserId[contactUserId] = creation;
- return creation.whenComplete(() {
- if (identical(_autoContactCreationsByUserId[contactUserId], creation)) {
+ return _autoContactCreationsByUserId.putIfAbsent(contactUserId, () {
+ final creation = _tryAutoCreateContactForLinkedPerson(
+ person: person,
+ contactUserId: contactUserId,
+ email: email,
+ );
+ return creation.whenComplete(() {
_autoContactCreationsByUserId.remove(contactUserId);
- }
+ });
});
}
@@ -791,13 +785,6 @@ class PersonService {
return null;
}
- final existing = await _contactsService.getContact(
- contactUserId: contactUserId,
- );
- if (existing != null) {
- return existing;
- }
-
final personUserID = person.data.userID;
final personEmail = normalizeContactLinkEmail(person.data.email);
final matchesContact = personUserID != null
@@ -828,10 +815,7 @@ class PersonService {
e,
s,
);
- if (_currentUserIDProvider() != ownerUserID) {
- return null;
- }
- return _contactsService.getContact(contactUserId: contactUserId);
+ return null;
}
}
diff --git a/mobile/apps/photos/lib/services/photos_contacts_service.dart b/mobile/apps/photos/lib/services/photos_contacts_service.dart
index 3122e4c0c5..e8b8d87d1b 100644
--- a/mobile/apps/photos/lib/services/photos_contacts_service.dart
+++ b/mobile/apps/photos/lib/services/photos_contacts_service.dart
@@ -288,9 +288,16 @@ class PhotosContactsService {
if (generation != _sessionGeneration) {
return null;
}
- _cacheContact(contact);
- _notifyChanged(contact);
- final updated = await contactsService.setProfilePicture(contact.id, bytes);
+ late contacts.ContactRecord updated;
+ try {
+ updated = await contactsService.setProfilePicture(contact.id, bytes);
+ } catch (_) {
+ if (generation != _sessionGeneration ||
+ !identical(contactsService, _activeContactsOrNull())) {
+ rethrow;
+ }
+ updated = await contactsService.setProfilePicture(contact.id, bytes);
+ }
if (generation != _sessionGeneration) {
return null;
}