Skip to content

armgit / ente

Public Imported from GitHub
0

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

Merge remote-tracking branch 'upstream/main' into contacts_changes

Neeraj Guptae0f748a2e5fe
diff --cc mobile/apps/photos/lib/ui/viewer/people/link_email_screen.dart
index 9caa185684,741755921f..1f6f0831d9
--- 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,16 -320,9 +320,17 @@@ class _LinkEmailScreen extends State<Li
String personID,
BuildContext context,
) async {
- if (await checkIfEmailAlreadyAssignedToAPerson(email)) {
+ final linkedPerson = await findPersonLinkedToEmail(
+ email,
+ excludedPersonId: personID,
+ );
+ if (linkedPerson != null) {
+ if (!context.mounted) return false;
- await showAlreadyLinkedEmailDialog(context, email);
+ await showAlreadyLinkedEmailDialog(
+ context,
+ email,
+ linkedPerson: linkedPerson,
+ );
return false;
}
diff --cc mobile/apps/photos/lib/ui/viewer/people/person_selection_action_widgets.dart
index 9f7b6498e6,9f0dd0d53f..87bc5a177e
--- 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,16 -524,9 +513,17 @@@ class _LinkContactToPersonSelectionPage
required String emailToLink,
required PersonEntity personEntity,
}) async {
- if (await checkIfEmailAlreadyAssignedToAPerson(emailToLink)) {
+ final linkedPerson = await findPersonLinkedToEmail(
+ emailToLink,
+ excludedPersonId: personEntity.remoteID,
+ );
+ if (linkedPerson != null) {
+ if (!context.mounted) return null;
- await showAlreadyLinkedEmailDialog(context, emailToLink);
+ await showAlreadyLinkedEmailDialog(
+ context,
+ emailToLink,
+ linkedPerson: linkedPerson,
+ );
return null;
}
diff --cc mobile/apps/photos/lib/ui/viewer/people/save_or_edit_person.dart
index 5a52e38f5b,11d1886aa7..572e201024
--- 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
@@@ -620,19 -592,15 +620,20 @@@ class _SaveOrEditPersonState extends St
String? birthdate,
String? email,
}) async {
- if (email != null &&
- email.isNotEmpty &&
- await checkIfEmailAlreadyAssignedToAPerson(email)) {
- _logger.severe(
- "Failed to addNewPerson, email is already assigned to a person",
- );
- if (!context.mounted) return null;
- await showAlreadyLinkedEmailDialog(context, email);
- return null;
+ if (email != null && email.isNotEmpty) {
+ final linkedPerson = await findPersonLinkedToEmail(email);
+ if (linkedPerson != null) {
+ _logger.severe(
+ "Failed to addNewPerson, email is already assigned to a person",
+ );
++ if (!context.mounted) return null;
+ await showAlreadyLinkedEmailDialog(
+ context,
+ email,
+ linkedPerson: linkedPerson,
+ );
+ return null;
+ }
}
try {
@@@ -684,21 -651,13 +686,22 @@@
Future<PersonEntity?> updatePerson(BuildContext context) async {
try {
- if (_email != null &&
- _email!.isNotEmpty &&
- _email != person!.data.email &&
- await checkIfEmailAlreadyAssignedToAPerson(_email!)) {
- if (!context.mounted) return null;
- await showAlreadyLinkedEmailDialog(context, _email!);
- return null;
+ final emailToSave = _emailToSave;
+ if (emailToSave != null &&
+ emailToSave != _trimEmptyToNull(person!.data.email)) {
+ final linkedPerson = await findPersonLinkedToEmail(
+ emailToSave,
+ excludedPersonId: person!.remoteID,
+ );
+ if (linkedPerson != null) {
++ if (!context.mounted) return null;
+ await showAlreadyLinkedEmailDialog(
+ context,
+ emailToSave,
+ linkedPerson: linkedPerson,
+ );
+ return null;
+ }
}
final String name = _inputName.trim();
final String? birthDate = _selectedDate;
diff --cc mobile/apps/photos/lib/ui/viewer/search/result/edit_contact_page.dart
index 9b34fde2d1,dabfcfdf3d..7f6d458636
--- 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
@@@ -1,18 -1,26 +1,19 @@@
-import "dart:async";
import "dart:typed_data";
+import "package:collection/collection.dart";
+import "package:ente_components/ente_components.dart";
import "package:ente_contacts/contacts.dart" as contacts;
import "package:ente_pure_utils/ente_pure_utils.dart";
-import "package:figma_squircle/figma_squircle.dart";
import "package:flutter/material.dart";
-import "package:intl/intl.dart";
+import "package:hugeicons/hugeicons.dart";
import "package:logging/logging.dart";
-import "package:photos/core/constants.dart";
-import "package:photos/db/files_db.dart";
-import "package:photos/db/ml/db.dart";
+import "package:photos/core/event_bus.dart";
+import "package:photos/events/people_changed_event.dart";
import "package:photos/generated/l10n.dart";
-import "package:photos/models/file/file.dart";
import "package:photos/models/ml/face/person.dart";
-import "package:photos/models/search/generic_search_result.dart";
-import "package:photos/models/search/search_constants.dart";
+ import "package:photos/module/download/thumbnail.dart";
-import "package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart";
import "package:photos/services/machine_learning/face_ml/person/person_service.dart";
-import "package:photos/services/machine_learning/ml_result.dart";
import "package:photos/services/photos_contacts_service.dart";
-import "package:photos/services/search_service.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/components/action_sheet_widget.dart";
@@@ -20,13 -28,13 +21,12 @@@ import "package:photos/ui/components/bu
import "package:photos/ui/components/models/button_type.dart";
import "package:photos/ui/notification/toast.dart";
import "package:photos/ui/viewer/people/face_thumbnail_squircle.dart";
-import "package:photos/ui/viewer/people/person_face_widget.dart";
-import "package:photos/ui/viewer/people/person_selection_action_widgets.dart";
+import "package:photos/ui/viewer/search/result/contact_person_picker_page.dart";
import "package:photos/ui/viewer/search/result/contact_photo_adjust_page.dart";
import "package:photos/ui/viewer/search/result/contact_photo_picker_sheet.dart";
+import "package:photos/utils/contact_photo_util.dart";
import "package:photos/utils/dialog_util.dart";
-import "package:photos/utils/face/face_thumbnail_cache.dart";
+import "package:photos/utils/person_contact_linking_util.dart";
- import "package:photos/utils/thumbnail_util.dart";
class EditContactPage extends StatefulWidget {
final int contactUserId;
diff --cc mobile/apps/photos/lib/utils/contact_photo_util.dart
index db80ccc25b,0000000000..8b8fa8a4a1
mode 100644,000000..100644
--- a/mobile/apps/photos/lib/utils/contact_photo_util.dart
+++ b/mobile/apps/photos/lib/utils/contact_photo_util.dart
@@@ -1,93 -1,0 +1,93 @@@
+import "dart:typed_data";
+
+import "package:photos/core/constants.dart";
+import "package:photos/db/files_db.dart";
+import "package:photos/db/ml/db.dart";
+import "package:photos/models/file/file.dart";
+import "package:photos/models/ml/face/face.dart";
+import "package:photos/models/ml/face/person.dart";
++import "package:photos/module/download/thumbnail.dart";
+import "package:photos/services/machine_learning/ml_result.dart";
+import "package:photos/services/search_service.dart";
+import "package:photos/utils/face/face_thumbnail_cache.dart";
- import "package:photos/utils/file_util.dart";
+
+const _maxContactPhotoCompressionAttempts = 2;
+
+Future<Uint8List> normalizeContactPhotoAttachmentBytes(
+ Uint8List sourceBytes,
+) async {
+ var bytes = sourceBytes;
+ var attempts = 0;
+ while (bytes.length > thumbnailDataLimit &&
+ attempts < _maxContactPhotoCompressionAttempts) {
+ bytes = await compressThumbnail(bytes);
+ attempts++;
+ }
+ return bytes;
+}
+
+Future<Uint8List?> buildContactPhotoAttachmentBytesFromFace({
+ required EnteFile file,
+ required Face face,
+}) async {
+ final crops = await getCachedFaceCrops(
+ file,
+ [face],
+ useFullFile: true,
+ useTempCache: false,
+ );
+ final croppedBytes = crops?[face.faceID];
+ if (croppedBytes == null) {
+ return null;
+ }
+ return normalizeContactPhotoAttachmentBytes(croppedBytes);
+}
+
+Future<Uint8List?> buildContactPhotoAttachmentBytesFromPerson(
+ PersonEntity person,
+) async {
+ final hiddenFileIds = await SearchService.instance.getHiddenFiles().then(
+ (files) => files.map((file) => file.uploadedFileID).toSet(),
+ );
+ final faceIds = await MLDataDB.instance.getFaceIDsForPersonOrderedByScore(
+ person.remoteID,
+ );
+ EnteFile? sourceFile;
+ String? faceId = person.data.avatarFaceID;
+
+ if (faceId != null) {
+ final fileId = getFileIdFromFaceId<int>(faceId);
+ if (!hiddenFileIds.contains(fileId)) {
+ sourceFile = await FilesDB.instance.getAnyUploadedFile(fileId);
+ }
+ }
+
+ if (sourceFile == null) {
+ for (final candidateFaceId in faceIds) {
+ final fileId = getFileIdFromFaceId<int>(candidateFaceId);
+ if (hiddenFileIds.contains(fileId)) {
+ continue;
+ }
+ sourceFile = await FilesDB.instance.getAnyUploadedFile(fileId);
+ if (sourceFile != null) {
+ faceId = candidateFaceId;
+ break;
+ }
+ }
+ }
+
+ if (sourceFile == null || sourceFile.uploadedFileID == null) {
+ return null;
+ }
+
+ final face = await MLDataDB.instance.getCoverFaceForPerson(
+ recentFileID: sourceFile.uploadedFileID!,
+ avatarFaceId: faceId,
+ personID: person.remoteID,
+ );
+ if (face == null) {
+ return null;
+ }
+
+ return buildContactPhotoAttachmentBytesFromFace(file: sourceFile, face: face);
+}