Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix current user contact links

Neeraj Gupta9cdc2555d1ec
diff --git a/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart b/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart
index 03f0d27ac4..9caa185684 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart
@@ -315,7 +315,10 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
String personID,
BuildContext context,
) async {
- final linkedPerson = await findPersonLinkedToEmail(email);
+ final linkedPerson = await findPersonLinkedToEmail(
+ email,
+ excludedPersonId: personID,
+ );
if (linkedPerson != null) {
await showAlreadyLinkedEmailDialog(
context,
diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart b/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart
index a9e2527336..9a8c33e69b 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/people_app_bar.dart
@@ -29,6 +29,7 @@ import "package:photos/ui/viewer/people/person_cluster_suggestion.dart";
import "package:photos/ui/viewer/people/person_selection_action_widgets.dart";
import "package:photos/ui/viewer/people/save_or_edit_person.dart";
import "package:photos/utils/dialog_util.dart";
+import "package:photos/utils/person_contact_linking_util.dart";
const kShowUnnamedIgnoredPersonEventSource =
"_AppBarWidgetState._showPersonUnnamedDelete";
@@ -125,7 +126,10 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
required PersonEntity sourcePerson,
required String? title,
}) {
- if (sourcePerson.data.email == Configuration.instance.getEmail()) {
+ if (isCurrentUserContactLink(
+ email: sourcePerson.data.email,
+ userID: sourcePerson.data.userID,
+ )) {
if (title == null) {
return context.l10n.me;
}
@@ -185,7 +189,8 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
if (oldWidget.title != widget.title ||
oldWidget.person.remoteID != widget.person.remoteID ||
oldWidget.person.data.name != widget.person.data.name ||
- oldWidget.person.data.email != widget.person.data.email) {
+ oldWidget.person.data.email != widget.person.data.email ||
+ oldWidget.person.data.userID != widget.person.data.userID) {
person = widget.person;
_appBarTitle = _resolveAppBarTitle(
sourcePerson: person,
@@ -341,8 +346,10 @@ class _AppBarWidgetState extends State<PeopleAppBar> {
iconColor,
),
),
- if (person.data.email != null &&
- (person.data.email == Configuration.instance.getEmail()))
+ if (isCurrentUserContactLink(
+ email: person.data.email,
+ userID: person.data.userID,
+ ))
EntePopupMenuOption(
value: PeoplePopupAction.reassignMe,
label: context.l10n.reassignMe,
diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart b/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart
index 42c2c7d7d7..6b3099dc63 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart
@@ -511,7 +511,10 @@ class _LinkContactToPersonSelectionPageState
required String emailToLink,
required PersonEntity personEntity,
}) async {
- final linkedPerson = await findPersonLinkedToEmail(emailToLink);
+ final linkedPerson = await findPersonLinkedToEmail(
+ emailToLink,
+ excludedPersonId: personEntity.remoteID,
+ );
if (linkedPerson != null) {
await showAlreadyLinkedEmailDialog(
context,
@@ -603,7 +606,8 @@ class _ReassignMeSelectionPageState extends State<ReassignMeSelectionPage> {
_personEntities = PersonService.instance.getPersons().then((persons) async {
final List<PersonEntity> result = [];
for (final person in persons) {
- if ((person.data.email != null && person.data.email!.isNotEmpty) ||
+ if (person.data.userID != null ||
+ (person.data.email != null && person.data.email!.isNotEmpty) ||
(person.data.isIgnored)) {
continue;
}
@@ -714,10 +718,12 @@ class _ReassignMeSelectionPageState extends State<ReassignMeSelectionPage> {
}) async {
try {
final email = Configuration.instance.getEmail();
+ final userID = Configuration.instance.getUserID();
final updatedPerson1 = await PersonService.instance.updateAttributes(
currentPersonID,
- email: '',
+ email: null,
+ userID: null,
);
Bus.instance.fire(
PeopleChangedEvent(
@@ -730,6 +736,7 @@ class _ReassignMeSelectionPageState extends State<ReassignMeSelectionPage> {
final updatedPerson2 = await PersonService.instance.updateAttributes(
newPersonID,
email: email,
+ userID: userID,
);
Bus.instance.fire(
PeopleChangedEvent(
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.dart
index 27106abd79..12029c8d8f 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
@@ -686,7 +686,10 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
final emailToSave = _emailToSave;
if (emailToSave != null &&
emailToSave != _trimEmptyToNull(person!.data.email)) {
- final linkedPerson = await findPersonLinkedToEmail(emailToSave);
+ final linkedPerson = await findPersonLinkedToEmail(
+ emailToSave,
+ excludedPersonId: person!.remoteID,
+ );
if (linkedPerson != null) {
await showAlreadyLinkedEmailDialog(
context,
diff --git a/mobile/apps/photos/lib/utils/person_contact_linking_util.dart b/mobile/apps/photos/lib/utils/person_contact_linking_util.dart
index 8ed0fbf814..9c1d142fcc 100644
--- a/mobile/apps/photos/lib/utils/person_contact_linking_util.dart
+++ b/mobile/apps/photos/lib/utils/person_contact_linking_util.dart
@@ -59,14 +59,34 @@ Future<PersonEntity?> findPersonLinkedToContact({
);
}
-Future<PersonEntity?> findPersonLinkedToEmail(String? email) async {
+Future<PersonEntity?> findPersonLinkedToEmail(
+ String? email, {
+ String? excludedPersonId,
+}) async {
final normalizedEmail = normalizeContactLinkEmail(email);
if (normalizedEmail == null) {
return null;
}
final persons = await PersonService.instance.getPersons();
+ bool includePerson(PersonEntity person) =>
+ person.remoteID != excludedPersonId;
+ if (isCurrentUserContactLinkEmail(normalizedEmail)) {
+ final currentUserMatch = persons.firstWhereOrNull(
+ (person) =>
+ includePerson(person) &&
+ isCurrentUserContactLink(
+ email: person.data.email,
+ userID: person.data.userID,
+ ),
+ );
+ if (currentUserMatch != null) {
+ return currentUserMatch;
+ }
+ }
return persons.firstWhereOrNull(
- (person) => contactLinkEmailMatches(person.data.email, normalizedEmail),
+ (person) =>
+ includePerson(person) &&
+ contactLinkEmailMatches(person.data.email, normalizedEmail),
);
}