π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Sort contact picker clusters by photo count
Neeraj Guptae8485ed8a5bf
diff --git a/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dart b/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dartindex 79b9227866..f0bee384c7 100644--- a/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dart+++ b/mobile/apps/photos/lib/ui/viewer/search/result/contact_person_picker_page.dart@@ -4,6 +4,7 @@ import "package:flutter/material.dart";import "package:hugeicons/hugeicons.dart";import "package:photos/generated/l10n.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/ui/viewer/people/face_thumbnail_squircle.dart";import "package:photos/ui/viewer/people/person_face_widget.dart";@@ -20,35 +21,49 @@ class ContactPersonPickerPersonCandidate extends ContactPersonPickerCandidate {}class ContactPersonPickerClusterCandidate extends ContactPersonPickerCandidate {- const ContactPersonPickerClusterCandidate(this.clusterID);+ const ContactPersonPickerClusterCandidate(+ this.clusterID, {+ required this.fileCount,+ });final String clusterID;+ final int fileCount;}List<ContactPersonPickerCandidate> buildContactPersonPickerCandidates({- required Iterable<Map<String, dynamic>> faceResultParams,+ required Iterable<GenericSearchResult> faceResults,required Iterable<PersonEntity> persons,}) {final personsByID = {for (final person in persons) person.remoteID: person};- final candidates = <ContactPersonPickerCandidate>[];+ final personCandidates = <ContactPersonPickerPersonCandidate>[];+ final clusterCandidates = <ContactPersonPickerClusterCandidate>[];- for (final params in faceResultParams) {+ for (final result in faceResults) {+ final params = result.params;final personID = params[kPersonParamID] as String?;if (personID != null) {final person = personsByID[personID];if (person != null) {- candidates.add(ContactPersonPickerPersonCandidate(person));+ personCandidates.add(ContactPersonPickerPersonCandidate(person));}continue;}final clusterID = params[kClusterParamId] as String?;if (clusterID != null) {- candidates.add(ContactPersonPickerClusterCandidate(clusterID));+ clusterCandidates.add(+ ContactPersonPickerClusterCandidate(+ clusterID,+ fileCount: result.fileCount(),+ ),+ );}}- return candidates;+ clusterCandidates.sort(+ (first, second) => second.fileCount.compareTo(first.fileCount),+ );+ return [...personCandidates, ...clusterCandidates];}abstract class ContactPersonPickerResult {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 6dbf303075..5699d8f07a 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@@ -334,7 +334,7 @@ class _EditContactPageState extends State<EditContactPage> {minClusterSize: kMinimumClusterSizeAllFaces,);candidates = buildContactPersonPickerCandidates(- faceResultParams: faceResults.map((result) => result.params),+ faceResults: faceResults,persons: await PersonService.instance.getPersons(),);} catch (e, s) {diff --git a/mobile/apps/photos/test/ui/viewer/search/result/contact_person_picker_page_test.dart b/mobile/apps/photos/test/ui/viewer/search/result/contact_person_picker_page_test.dartindex ddf1c488a8..726d14aeb4 100644--- a/mobile/apps/photos/test/ui/viewer/search/result/contact_person_picker_page_test.dart+++ b/mobile/apps/photos/test/ui/viewer/search/result/contact_person_picker_page_test.dart@@ -1,28 +1,57 @@import "package:flutter_test/flutter_test.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/hierarchical/face_filter.dart";import "package:photos/models/search/search_constants.dart";+import "package:photos/models/search/search_types.dart";import "package:photos/ui/viewer/search/result/contact_person_picker_page.dart";void main() {- test("includes unassigned face clusters alongside existing people", () {+ test("orders unassigned face clusters by photo frequency", () {final person = PersonEntity("person-1", PersonData(name: "Alex"));final candidates = buildContactPersonPickerCandidates(- faceResultParams: const [- {kPersonParamID: "person-1"},- {kClusterParamId: "cluster-1"},+ faceResults: [+ _faceResult(personID: "person-1", fileCount: 2),+ _faceResult(clusterID: "cluster-small", fileCount: 1),+ _faceResult(clusterID: "cluster-large", fileCount: 5),],persons: [person],);- expect(candidates, hasLength(2));+ expect(candidates, hasLength(3));expect((candidates.first as ContactPersonPickerPersonCandidate).person,same(person),);expect(- (candidates.last as ContactPersonPickerClusterCandidate).clusterID,- "cluster-1",+ candidates+ .skip(1)+ .cast<ContactPersonPickerClusterCandidate>()+ .map((candidate) => candidate.clusterID),+ ["cluster-large", "cluster-small"],);});}++GenericSearchResult _faceResult({+ String? personID,+ String? clusterID,+ required int fileCount,+}) {+ final files = List.generate(fileCount, (_) => EnteFile());+ return GenericSearchResult(+ ResultType.faces,+ "",+ files,+ params: {kPersonParamID: ?personID, kClusterParamId: ?clusterID},+ hierarchicalSearchFilter: FaceFilter(+ personId: personID,+ clusterId: clusterID,+ faceName: null,+ faceFile: files.first,+ occurrence: fileCount,+ ),+ );+}