Skip to content

armgit / ente

Public Imported from GitHub
0

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

Link self person by user ID

Neeraj Gupta19f4f5ffad6b
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 49e1547e2a..e737b88361 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
@@ -308,6 +308,7 @@ class PersonService {
bool hideFromMemories = false,
String? birthdate,
String? email,
+ int? userID,
}) async {
final faceIds = await faceMLDataDB.getFaceIDsForCluster(clusterID);
final data = PersonData(
@@ -320,6 +321,7 @@ class PersonService {
hideFromMemories: hideFromMemories,
birthDate: birthdate,
email: email,
+ userID: userID,
);
final result = await _addOrUpdateEntity(EntityType.cgroup, data.toJson());
await faceMLDataDB.assignClusterToPerson(
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 8d9aa875da..875af6c9be 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
@@ -359,11 +359,18 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
try {
final personEntity = await PersonService.instance.getPerson(personID);
late final PersonEntity updatedPerson;
+ final currentUserID = _currentUserIDForEmail(email);
if (personEntity == null) {
throw AssertionError(
"Cannot link email to non-existent person. First save the person",
);
+ } else if (currentUserID != null) {
+ updatedPerson = await PersonService.instance.updateAttributes(
+ personID,
+ email: email,
+ userID: currentUserID,
+ );
} else {
updatedPerson = await PersonService.instance.updateAttributes(
personID,
@@ -387,3 +394,14 @@ class _LinkEmailScreen extends State<LinkEmailScreen> {
}
}
}
+
+bool _matchesCurrentUserEmail(String email) {
+ final currentEmail = Configuration.instance.getEmail()?.trim().toLowerCase();
+ return currentEmail != null && email.trim().toLowerCase() == currentEmail;
+}
+
+int? _currentUserIDForEmail(String email) {
+ return _matchesCurrentUserEmail(email)
+ ? Configuration.instance.getUserID()
+ : null;
+}
diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_util.dart b/mobile/apps/photos/lib/ui/viewer/people/people_util.dart
index 1270f1d30a..e018a8209d 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/people_util.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/people_util.dart
@@ -3,11 +3,17 @@ import "package:photos/services/machine_learning/face_ml/person/person_service.d
Future<bool> isMeAssigned() async {
final personEntities = await PersonService.instance.getPersons();
- final currentUserEmail = Configuration.instance.getEmail();
+ final currentUserEmail = Configuration.instance
+ .getEmail()
+ ?.trim()
+ .toLowerCase();
+ final currentUserID = Configuration.instance.getUserID();
bool isAssigned = false;
for (final personEntity in personEntities) {
- if (personEntity.data.email == currentUserEmail) {
+ final personEmail = personEntity.data.email?.trim().toLowerCase();
+ if ((currentUserEmail != null && personEmail == currentUserEmail) ||
+ (currentUserID != null && personEntity.data.userID == currentUserID)) {
isAssigned = true;
break;
}
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 deb6253c37..b3e88f23d7 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
@@ -66,6 +66,20 @@ String? _trimEmptyToNull(String? value) {
return trimmedValue;
}
+bool _matchesCurrentUserEmail(String? email) {
+ final currentEmail = _trimEmptyToNull(Configuration.instance.getEmail());
+ final candidateEmail = _trimEmptyToNull(email);
+ return currentEmail != null &&
+ candidateEmail != null &&
+ candidateEmail.toLowerCase() == currentEmail.toLowerCase();
+}
+
+int? _currentUserIDForEmail(String? email) {
+ return _matchesCurrentUserEmail(email)
+ ? Configuration.instance.getUserID()
+ : null;
+}
+
class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
static const int _maxSuggestedPersons = 3;
bool isKeypadOpen = false;
@@ -84,12 +98,22 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
String? get _emailToSave => _trimEmptyToNull(_email);
+ int? get _currentUserIDToSave => _currentUserIDForEmail(_emailToSave);
+
bool get _shouldClearContactUserID =>
widget.isEditing &&
_contactLinkEmailCleared &&
person?.data.userID != null &&
_emailToSave == null;
+ bool get _shouldSetCurrentUserID =>
+ widget.isEditing &&
+ _currentUserIDToSave != null &&
+ person?.data.userID != _currentUserIDToSave;
+
+ bool get _shouldUpdateContactUserID =>
+ _shouldClearContactUserID || _shouldSetCurrentUserID;
+
@override
void initState() {
super.initState();
@@ -632,6 +656,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
hideFromMemories: _hideFromMemories,
birthdate: birthdate,
email: email,
+ userID: _currentUserIDForEmail(email),
);
final bool extraPhotosFound = await ClusterFeedbackService.instance
.checkAndDoAutomaticMerges(personEntity, personClusterID: clusterID);
@@ -658,7 +683,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
? (_inputName.trim() != person!.data.name ||
_selectedDate != person!.data.birthDate ||
_emailToSave != _trimEmptyToNull(person!.data.email) ||
- _shouldClearContactUserID ||
+ _shouldUpdateContactUserID ||
_isPinned != person!.data.isPinned ||
_hideFromMemories != person!.data.hideFromMemories)
: _inputName.trim().isNotEmpty;
@@ -674,7 +699,10 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
}
final String name = _inputName.trim();
final String? birthDate = _selectedDate;
- final personEntity = _shouldClearContactUserID
+ final userIDToSave = _shouldClearContactUserID
+ ? null
+ : _currentUserIDToSave;
+ final personEntity = _shouldUpdateContactUserID
? await PersonService.instance.updateAttributes(
person!.remoteID,
name: name,
@@ -682,7 +710,7 @@ class _SaveOrEditPersonState extends State<SaveOrEditPerson> {
isPinned: _isPinned,
hideFromMemories: _hideFromMemories,
email: emailToSave,
- userID: null,
+ userID: userIDToSave,
)
: await PersonService.instance.updateAttributes(
person!.remoteID,