π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Tighten linked contact person sync
Neeraj Gupta9758409a0164
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.dartindex 0f1010eac1..49e1547e2a 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@@ -34,9 +34,15 @@ class PersonService {final EntityService entityService;final MLDataDB faceMLDataDB;final SharedPreferences prefs;+ final PhotosContactsService _contactsService;final _emailToPartialPersonDataMapCache = <String, Map<String, String>>{};- PersonService(this.entityService, this.faceMLDataDB, this.prefs);+ PersonService(+ this.entityService,+ this.faceMLDataDB,+ this.prefs, {+ PhotosContactsService? contactsService,+ }) : _contactsService = contactsService ?? PhotosContactsService.instance;// instancestatic PersonService? _instance;@@ -600,7 +606,7 @@ class PersonService {if (!flagService.enableContact) {return;}- final contact = await PhotosContactsService.instance.getContact(+ final contact = await _contactsService.getContact(contactUserId: person.data.userID,email: person.data.email,);@@ -617,7 +623,7 @@ class PersonService {);}try {- await PhotosContactsService.instance.setProfilePicture(+ await _contactsService.setProfilePicture(contactId: contact.id,bytes: bytes,);@@ -639,8 +645,17 @@ class PersonService {int? version,Object? birthDate = _attributeNotProvided,Object? email = _attributeNotProvided,+ Object? userID = _attributeNotProvided,+ bool syncLinkedContactName = true,}) async {final person = (await getPerson(id))!;+ final trimmedName = name?.trim();+ if (syncLinkedContactName &&+ trimmedName != null &&+ trimmedName.isNotEmpty &&+ trimmedName != person.data.name.trim()) {+ await _updateLinkedContactNameBeforePerson(person, trimmedName);+ }var updatedData = person.data.copyWith(name: name,avatarFaceId: avatarFaceId,@@ -655,6 +670,9 @@ class PersonService {if (!identical(email, _attributeNotProvided)) {updatedData = updatedData.copyWith(email: email as String?);}+ if (!identical(userID, _attributeNotProvided)) {+ updatedData = updatedData.copyWith(userID: userID as int?);+ }final updatedPerson = person.copyWith(data: updatedData);await updatePerson(updatedPerson);await refreshPersonCache();@@ -668,18 +686,45 @@ class PersonService {return updatedPerson;}+ Future<void> _updateLinkedContactNameBeforePerson(+ PersonEntity person,+ String name,+ ) async {+ if (!flagService.enableContact) {+ return;+ }+ final contact = await _contactsService.getContact(+ contactUserId: person.data.userID,+ email: person.data.email,+ );+ if (contact == null || !flagService.enableContact) {+ return;+ }+ try {+ await _contactsService.createOrUpdateContact(+ contactUserId: contact.contactUserId,+ name: name,+ birthDate: contact.data?.birthDate,+ );+ } on StateError {+ if (!flagService.enableContact) {+ return;+ }+ rethrow;+ }+ }+Future<PersonEntity> updateContactLink(String id, {required int? userID,required String? email,}) async {- final person = (await getPerson(id))!;- final updatedPerson = person.copyWith(- data: person.data.copyWith(userID: userID, email: email),+ return updateAttributes(+ id,+ userID: userID,+ email: email,+ syncLinkedContactName: false,);- await updatePerson(updatedPerson);- await refreshPersonCache();- return updatedPerson;}Future<ManualPersonAssignmentResult> addManualFileAssignments({diff --git a/mobile/apps/photos/lib/services/photos_contacts_service.dart b/mobile/apps/photos/lib/services/photos_contacts_service.dartindex a91808bc2e..78590387c9 100644--- a/mobile/apps/photos/lib/services/photos_contacts_service.dart+++ b/mobile/apps/photos/lib/services/photos_contacts_service.dart@@ -94,10 +94,6 @@ class PhotosContactsService {return readyFuture;}- Future<contacts.ContactRecord?> getContactByUserId(int contactUserId) async {- return getContact(contactUserId: contactUserId);- }-Future<contacts.ContactRecord?> getContact({int? contactUserId,String? email,@@ -140,10 +136,6 @@ class PhotosContactsService {return _getCachedContact(contactUserId: contactUserId);}- contacts.ContactRecord? getCachedContactByEmail(String? email) {- return _getCachedContact(email: email);- }-contacts.ContactRecord? getCachedContact({int? contactUserId,String? email,diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart b/mobile/apps/photos/lib/ui/viewer/people/people_page.dartindex d8139f359e..6a7165864b 100644--- a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/people_page.dart@@ -356,6 +356,11 @@ class _GalleryState extends State<_Gallery> {@overrideWidget build(BuildContext context) {+ final showLinkEmailBanner =+ !flagService.enableContact &&+ !widget.personEntity.data.isIgnored &&+ (widget.personEntity.data.email == null ||+ widget.personEntity.data.email!.isEmpty);if (widget.showTimelineBanner && !_loggedTimelineImpression) {_timelineLogger.info("banner_impression person=${widget.personEntity.remoteID}",@@ -382,24 +387,21 @@ class _GalleryState extends State<_Gallery> {: [],header: Column(children: [- (widget.personEntity.data.email != null &&- widget.personEntity.data.email!.isNotEmpty) ||- widget.personEntity.data.isIgnored- ? const SizedBox.shrink()- : Padding(- padding: const EdgeInsets.only(top: 12, bottom: 8),- child: EndToEndBanner(- title: context.l10n.linkEmail,- caption: context.l10n.linkEmailToContactBannerCaption,- leadingIcon: Icons.email_outlined,- onTap: () async {- await routeToPage(- context,- LinkEmailScreen(widget.personEntity.remoteID),- );- },- ),- ),+ if (showLinkEmailBanner)+ Padding(+ padding: const EdgeInsets.only(top: 12, bottom: 8),+ child: EndToEndBanner(+ title: context.l10n.linkEmail,+ caption: context.l10n.linkEmailToContactBannerCaption,+ leadingIcon: Icons.email_outlined,+ onTap: () async {+ await routeToPage(+ context,+ LinkEmailScreen(widget.personEntity.remoteID),+ );+ },+ ),+ ),MemoryLaneBannerSection(showBanner: widget.memoryLaneEnabled && widget.showTimelineBanner,person: widget.personEntity,diff --git a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dartindex e41cf21f43..deb6253c37 100644--- a/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart@@ -58,12 +58,21 @@ class SaveOrEditPerson extends StatefulWidget {State<SaveOrEditPerson> createState() => _SaveOrEditPersonState();}+String? _trimEmptyToNull(String? value) {+ final trimmedValue = value?.trim();+ if (trimmedValue == null || trimmedValue.isEmpty) {+ return null;+ }+ return trimmedValue;+}+class _SaveOrEditPersonState extends State<SaveOrEditPerson> {static const int _maxSuggestedPersons = 3;bool isKeypadOpen = false;String _inputName = "";String? _selectedDate;String? _email;+ bool _contactLinkEmailCleared = false;bool _isPinned = false;bool _hideFromMemories = false;bool userAlreadyAssigned = false;@@ -73,6 +82,14 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {final _nameFocsNode = FocusNode();List<PersonEntity> _allPersons = [];+ String? get _emailToSave => _trimEmptyToNull(_email);++ bool get _shouldClearContactUserID =>+ widget.isEditing &&+ _contactLinkEmailCleared &&+ person?.data.userID != null &&+ _emailToSave == null;+@overridevoid initState() {super.initState();@@ -640,30 +657,41 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {bool get changed => widget.isEditing? (_inputName.trim() != person!.data.name ||_selectedDate != person!.data.birthDate ||- _email != person!.data.email ||+ _emailToSave != _trimEmptyToNull(person!.data.email) ||+ _shouldClearContactUserID ||_isPinned != person!.data.isPinned ||_hideFromMemories != person!.data.hideFromMemories): _inputName.trim().isNotEmpty;Future<PersonEntity?> updatePerson(BuildContext context) async {try {- if (_email != null &&- _email!.isNotEmpty &&- _email != person!.data.email &&- await checkIfEmailAlreadyAssignedToAPerson(_email!)) {- await showAlreadyLinkedEmailDialog(context, _email!);+ final emailToSave = _emailToSave;+ if (emailToSave != null &&+ emailToSave != _trimEmptyToNull(person!.data.email) &&+ await checkIfEmailAlreadyAssignedToAPerson(emailToSave)) {+ await showAlreadyLinkedEmailDialog(context, emailToSave);return null;}final String name = _inputName.trim();final String? birthDate = _selectedDate;- final personEntity = await PersonService.instance.updateAttributes(- person!.remoteID,- name: name,- birthDate: birthDate,- isPinned: _isPinned,- hideFromMemories: _hideFromMemories,- email: _email,- );+ final personEntity = _shouldClearContactUserID+ ? await PersonService.instance.updateAttributes(+ person!.remoteID,+ name: name,+ birthDate: birthDate,+ isPinned: _isPinned,+ hideFromMemories: _hideFromMemories,+ email: emailToSave,+ userID: null,+ )+ : await PersonService.instance.updateAttributes(+ person!.remoteID,+ name: name,+ birthDate: birthDate,+ isPinned: _isPinned,+ hideFromMemories: _hideFromMemories,+ email: emailToSave,+ );Bus.instance.fire(PeopleChangedEvent(@@ -1208,8 +1236,13 @@ class _EmailSectionState extends State<_EmailSection> {void _updateEmailField(String? newEmail) {final saveOrEditPersonState = context.findAncestorStateOfType<_SaveOrEditPersonState>()!;+ final clearedExistingEmail =+ saveOrEditPersonState.widget.isEditing &&+ _trimEmptyToNull(saveOrEditPersonState.person?.data.email) != null &&+ _trimEmptyToNull(newEmail) == null;saveOrEditPersonState.setState(() {saveOrEditPersonState._email = newEmail;+ saveOrEditPersonState._contactLinkEmailCleared = clearedExistingEmail;});}diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dart b/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dartindex 2810e4001b..ad9947674b 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/contact_photo_picker_sheet.dart@@ -125,26 +125,27 @@ class _ContactPhotoPickerSheetState extends State<_ContactPhotoPickerSheet> {return Column(mainAxisSize: MainAxisSize.min,children: [- _ContactPhotoSheetButton(+ ButtonComponent(label: l10n.setSelectedPhoto,isDisabled: !value,- backgroundColor: colors.primary,- disabledBackgroundColor: colors.fillDark,- foregroundColor: colors.specialWhite,- disabledForegroundColor: colors.textLightest,- onTap: () {- Navigator.pop(- context,- ContactPhotoPickerFile(_selectedFiles.files.first),- );- },+ shouldSurfaceExecutionStates: false,+ onTap: value+ ? () {+ Navigator.pop(+ context,+ ContactPhotoPickerFile(+ _selectedFiles.files.first,+ ),+ );+ }+ : null,),if (widget.canRemovePhoto) ...[const SizedBox(height: Spacing.md),- _ContactPhotoSheetButton(+ ButtonComponent(label: l10n.removeContactPhoto,- backgroundColor: colors.fillDark,- foregroundColor: colors.textBase,+ variant: ButtonComponentVariant.secondary,+ shouldSurfaceExecutionStates: false,onTap: () {Navigator.pop(context,@@ -208,54 +209,3 @@ class _ContactPhotoSheetHeader extends StatelessWidget {);}}--class _ContactPhotoSheetButton extends StatelessWidget {- const _ContactPhotoSheetButton({- required this.label,- required this.backgroundColor,- required this.foregroundColor,- required this.onTap,- this.disabledBackgroundColor,- this.disabledForegroundColor,- this.isDisabled = false,- });-- final String label;- final Color backgroundColor;- final Color foregroundColor;- final Color? disabledBackgroundColor;- final Color? disabledForegroundColor;- final VoidCallback onTap;- final bool isDisabled;-- @override- Widget build(BuildContext context) {- final enabled = !isDisabled;- final effectiveBackground = enabled- ? backgroundColor- : disabledBackgroundColor ?? backgroundColor;- final effectiveForeground = enabled- ? foregroundColor- : disabledForegroundColor ?? foregroundColor;- return GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: enabled ? onTap : null,- child: Container(- width: double.infinity,- height: 48,- alignment: Alignment.center,- padding: const EdgeInsets.symmetric(horizontal: Spacing.xxl),- decoration: BoxDecoration(- color: effectiveBackground,- borderRadius: BorderRadius.circular(Radii.button),- ),- child: Text(- label,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: TextStyles.body.copyWith(color: effectiveForeground),- ),- ),- );- }-}diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dartindex a808540b20..0dc184710e 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/contact_result_page.dart@@ -306,8 +306,8 @@ class _ContactResultPageState extends State<ContactResultPage> {if (contactUserId == null) {return;}- final saved = await PhotosContactsService.instance.getContactByUserId(- contactUserId,+ final saved = await PhotosContactsService.instance.getContact(+ contactUserId: contactUserId,);if (!mounted) {return;diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dartindex 66cd7946e8..bf00f3fac1 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart@@ -192,9 +192,10 @@ class _EditContactPageState extends State<EditContactPage> {),Padding(padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),- child: _ContactSaveButton(+ child: ButtonComponent(label: l10n.saveContact,isDisabled: !_canSave,+ shouldShowSuccessState: false,onTap: _canSave ? _saveContact : null,),),@@ -469,13 +470,18 @@ class _EditContactPageState extends State<EditContactPage> {}Future<void> _saveContact() async {+ if (!_canSave) {+ return;+ }setState(() {_isSaving = true;});try {+ final contactName = _nameController.text.trim();+ final contactNameChanged = contactName != _initialName;var saved = await PhotosContactsService.instance.createOrUpdateContact(contactUserId: widget.contactUserId,- name: _nameController.text.trim(),+ name: contactName,birthDate: _birthDateToPreserve,);if (_photoDirty) {@@ -491,7 +497,10 @@ class _EditContactPageState extends State<EditContactPage> {);}}- await _savePersonLinkChanges();+ await _savePersonLinkChanges(+ contactName: contactName,+ contactNameChanged: contactNameChanged,+ );if (!mounted) {return;}@@ -508,7 +517,10 @@ class _EditContactPageState extends State<EditContactPage> {}}- Future<void> _savePersonLinkChanges() async {+ Future<void> _savePersonLinkChanges({+ required String contactName,+ required bool contactNameChanged,+ }) async {final previousPerson = _initialLinkedPerson;final selectedPerson = _unlinkDraft ? null : _draftLinkedPerson;final updatedPersons = <PersonEntity>[];@@ -530,12 +542,26 @@ class _EditContactPageState extends State<EditContactPage> {previousPerson?.remoteID != selectedPerson.remoteID ||selectedPerson.data.userID != widget.contactUserId ||!contactLinkEmailMatches(selectedPerson.data.email, widget.email);+ final shouldUpdateSelectedName =+ contactNameChanged &&+ contactName.isNotEmpty &&+ selectedPerson.data.name.trim() != contactName;if (shouldUpdateSelectedLink) {updatedPersons.add(- await PersonService.instance.updateContactLink(+ await PersonService.instance.updateAttributes(selectedPerson.remoteID,+ name: shouldUpdateSelectedName ? contactName : null,userID: widget.contactUserId,email: widget.email,+ syncLinkedContactName: false,+ ),+ );+ } else if (shouldUpdateSelectedName) {+ updatedPersons.add(+ await PersonService.instance.updateAttributes(+ selectedPerson.remoteID,+ name: contactName,+ syncLinkedContactName: false,),);}@@ -731,48 +757,6 @@ class _ReadOnlyContactTextInput extends StatelessWidget {}}-class _ContactSaveButton extends StatelessWidget {- const _ContactSaveButton({- required this.label,- required this.isDisabled,- required this.onTap,- });-- final String label;- final bool isDisabled;- final VoidCallback? onTap;-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- final enabled = !isDisabled && onTap != null;- return GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: enabled ? onTap : null,- child: AnimatedContainer(- duration: Motion.standard,- curve: Curves.easeInOutCubic,- width: double.infinity,- height: 48,- alignment: Alignment.center,- padding: const EdgeInsets.symmetric(horizontal: Spacing.xxl),- decoration: BoxDecoration(- color: enabled ? colors.primary : colors.fillDark,- borderRadius: BorderRadius.circular(Radii.button),- ),- child: Text(- label,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: TextStyles.body.copyWith(- color: enabled ? colors.specialWhite : colors.textLightest,- ),- ),- ),- );- }-}-class _AvatarActionButton extends StatelessWidget {final double size;final bool isUnlink;diff --git a/mobile/apps/photos/test/models/ml/face/person_contact_link_test.dart b/mobile/apps/photos/test/models/ml/face/person_contact_link_test.dartindex 640625c050..6e405cd845 100644--- a/mobile/apps/photos/test/models/ml/face/person_contact_link_test.dart+++ b/mobile/apps/photos/test/models/ml/face/person_contact_link_test.dart@@ -1,16 +1,38 @@import "dart:convert";+import "package:dio/dio.dart";+import "package:ente_contacts/contacts.dart" as contacts;import "package:flutter_test/flutter_test.dart";+import "package:package_info_plus/package_info_plus.dart";import "package:photos/db/ml/db.dart";import "package:photos/gateways/entity/models/type.dart";import "package:photos/models/local_entity_data.dart";import "package:photos/models/ml/face/person.dart";+import "package:photos/service_locator.dart";import "package:photos/services/entity_service.dart";import "package:photos/services/machine_learning/face_ml/person/person_service.dart";+import "package:photos/services/photos_contacts_service.dart";import "package:photos/utils/person_contact_linking_util.dart";import "package:shared_preferences/shared_preferences.dart";void main() {+ setUpAll(() async {+ SharedPreferences.setMockInitialValues({});+ final prefs = await SharedPreferences.getInstance();+ ServiceLocator.instance.init(+ prefs,+ Dio(),+ Dio(),+ Dio(),+ PackageInfo(+ appName: "Photos",+ packageName: "photos",+ version: "1.0.0",+ buildNumber: "1",+ ),+ );+ });+group("PersonData contact link", () {test("copyWith preserves link fields when omitted", () {final data = PersonData(@@ -42,6 +64,7 @@ void main() {group("PersonService contact link", () {late _FakeEntityService entityService;+ late _FakePhotosContactsService contactsService;late PersonService personService;setUp(() async {@@ -53,10 +76,28 @@ void main() {PersonData(name: "Alex", email: "[email protected]", userID: 3),),);+ contactsService = _FakePhotosContactsService()+ ..seed(+ const contacts.ContactRecord(+ id: "contact-1",+ contactUserId: 3,+ email: "[email protected]",+ data: contacts.ContactData(+ contactUserId: 3,+ name: "Old Contact",+ birthDate: "2001-04-02",+ ),+ profilePictureAttachmentId: null,+ isDeleted: false,+ createdAt: 1,+ updatedAt: 2,+ ),+ );personService = _TestPersonService(entityService,_FakeMLDataDB(),await SharedPreferences.getInstance(),+ contactsService: contactsService,);});@@ -88,19 +129,62 @@ void main() {expect(storedJson["email"], isNull);});- test(- "updateAttributes preserves contact link fields when omitted",- () async {- final updated = await personService.updateAttributes(- "person-1",- name: "Alex R",- );+ test("updateAttributes syncs changed name to linked contact", () async {+ final updated = await personService.updateAttributes(+ "person-1",+ name: "Alex R",+ );- expect(updated.data.name, "Alex R");- expect(updated.data.userID, 3);- expect(updated.data.email, "[email protected]");- },- );+ expect(updated.data.name, "Alex R");+ expect(updated.data.userID, 3);+ expect(updated.data.email, "[email protected]");+ expect(contactsService.createOrUpdateCalls, 1);+ expect(contactsService.lastUpdatedContactUserId, 3);+ expect(contactsService.lastUpdatedName, "Alex R");+ expect(contactsService.lastUpdatedBirthDate, "2001-04-02");+ });++ test("updateAttributes does not sync unchanged person name", () async {+ final updated = await personService.updateAttributes(+ "person-1",+ name: "Alex",+ );++ expect(updated.data.name, "Alex");+ expect(contactsService.createOrUpdateCalls, 0);+ expect(contactsService.lastUpdatedName, isNull);+ });++ test("updateAttributes can skip linked contact name sync", () async {+ final updated = await personService.updateAttributes(+ "person-1",+ name: "Alex R",+ syncLinkedContactName: false,+ );++ expect(updated.data.name, "Alex R");+ expect(contactsService.createOrUpdateCalls, 0);+ expect(contactsService.lastUpdatedName, isNull);+ });++ test("updateAttributes clears userID when explicitly provided", () async {+ final updated = await personService.updateAttributes(+ "person-1",+ email: null,+ userID: null,+ );++ expect(updated.data.userID, isNull);+ expect(updated.data.email, isNull);++ final stored = await entityService.getEntity(+ EntityType.cgroup,+ "person-1",+ );+ final storedJson = jsonDecode(stored!.data) as Map<String, dynamic>;+ expect(storedJson["userID"], isNull);+ expect(storedJson["email"], isNull);+ });});group("contact link conflict rules", () {@@ -167,7 +251,12 @@ void main() {}class _TestPersonService extends PersonService {- _TestPersonService(super.entityService, super.faceMLDataDB, super.prefs);+ _TestPersonService(+ super.entityService,+ super.faceMLDataDB,+ super.prefs, {+ super.contactsService,+ });@overrideFuture<void> refreshPersonCache({@@ -176,6 +265,67 @@ class _TestPersonService extends PersonService {}) async {}}+class _FakePhotosContactsService implements PhotosContactsService {+ contacts.ContactRecord? contact;+ int createOrUpdateCalls = 0;+ int? lastUpdatedContactUserId;+ String? lastUpdatedName;+ String? lastUpdatedBirthDate;++ void seed(contacts.ContactRecord value) {+ contact = value;+ }++ @override+ Future<contacts.ContactRecord?> getContact({+ int? contactUserId,+ String? email,+ }) async {+ final saved = contact;+ if (saved == null || saved.isDeleted) {+ return null;+ }+ if (contactUserId != null) {+ return saved.contactUserId == contactUserId ? saved : null;+ }+ final normalizedEmail = email?.trim().toLowerCase();+ if (normalizedEmail == null || normalizedEmail.isEmpty) {+ return null;+ }+ return saved.email?.trim().toLowerCase() == normalizedEmail ? saved : null;+ }++ @override+ Future<contacts.ContactRecord> createOrUpdateContact({+ required int contactUserId,+ required String name,+ String? birthDate,+ }) async {+ createOrUpdateCalls += 1;+ lastUpdatedContactUserId = contactUserId;+ lastUpdatedName = name.trim();+ lastUpdatedBirthDate = birthDate;+ final saved = contact;+ return contacts.ContactRecord(+ id: saved?.id ?? "contact-$contactUserId",+ contactUserId: contactUserId,+ email: saved?.email,+ data: contacts.ContactData(+ contactUserId: contactUserId,+ name: name.trim(),+ birthDate: birthDate,+ ),+ profilePictureAttachmentId: saved?.profilePictureAttachmentId,+ isDeleted: false,+ createdAt: saved?.createdAt ?? 1,+ updatedAt: (saved?.updatedAt ?? 1) + 1,+ );+ }++ @override+ dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);+}+class _FakeEntityService implements EntityService {final Map<String, LocalEntityData> _entities = {};int _updatedAt = 1;