π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle self person in wrapped cards
laurenspriemd90ba69c6d26
diff --git a/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart b/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dartindex 4bcd938791..2b741b8e33 100644--- a/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart+++ b/mobile/apps/photos/lib/services/wrapped/builders/people_candidate_builder.dart@@ -75,10 +75,13 @@ class PeopleCandidateBuilder extends WrappedCandidateBuilder {? "${numberFormat.format(uniqueMoments)} moments with $mention.": "One unforgettable moment with $mention.";+ final List<int> candidateIds = topPerson.topMediaFileIDs(6);+ final Map<int, double> scoreHints = topPerson.mediaScoreHints();final List<MediaRef> media = WrappedMediaSelector.selectMediaRefs(context: context,- candidateUploadedFileIDs: topPerson.topMediaFileIDs(6),+ candidateUploadedFileIDs: candidateIds,maxCount: 3,+ scoreHints: scoreHints,preferNamedPeople: true,minimumSpacing: const Duration(days: 30),);@@ -136,10 +139,23 @@ class PeopleCandidateBuilder extends WrappedCandidateBuilder {.expand((List<int> ids) => ids).toList(growable: false);+ final Map<int, double> scoreHints = <int, double>{};+ for (final _PersonStats stats in topThree) {+ final Map<int, double> personHints = stats.mediaScoreHints();+ for (final MapEntry<int, double> entry in personHints.entries) {+ scoreHints.update(+ entry.key,+ (double value) => value + entry.value,+ ifAbsent: () => entry.value,+ );+ }+ }+final List<MediaRef> media = WrappedMediaSelector.selectMediaRefs(context: context,candidateUploadedFileIDs: candidateIds,maxCount: 3,+ scoreHints: scoreHints,preferNamedPeople: true,minimumSpacing: const Duration(days: 21),);@@ -299,10 +315,23 @@ class PeopleCandidateBuilder extends WrappedCandidateBuilder {.expand((List<int> ids) => ids).toList(growable: false);+ final Map<int, double> scoreHints = <int, double>{};+ for (final _PersonStats stats in highlights) {+ final Map<int, double> personHints = stats.mediaScoreHints();+ for (final MapEntry<int, double> entry in personHints.entries) {+ scoreHints.update(+ entry.key,+ (double value) => value + entry.value,+ ifAbsent: () => entry.value,+ );+ }+ }+final List<MediaRef> media = WrappedMediaSelector.selectMediaRefs(context: context,candidateUploadedFileIDs: candidateIds,maxCount: 3,+ scoreHints: scoreHints,preferNamedPeople: true,minimumSpacing: const Duration(days: 30),);@@ -339,6 +368,7 @@ class _PeopleDataset {required this.year,required List<_PersonStats> topPeople,required List<_PersonStats> topNamedPeople,+ required this.selfPersonID,required this.totalNamedFaceCount,required this.totalFaceMoments,required this.groupMoments,@@ -354,6 +384,7 @@ class _PeopleDataset {final int year;final List<_PersonStats> _topPeople;final List<_PersonStats> _topNamedPeople;+ final String? selfPersonID;final int totalNamedFaceCount;final int totalFaceMoments;final int groupMoments;@@ -398,6 +429,7 @@ class _PeopleDataset {return _PeopleDataset._empty(year);}+ final String? selfPersonID = context.selfPersonID;final Map<String, _PersonStats> personStats = <String, _PersonStats>{};final Map<String, int> firstSeenYear = <String, int>{for (final MapEntry<String, int> entry@@ -420,6 +452,10 @@ class _PeopleDataset {continue;}final List<WrappedFaceRef> faces = file.faces;+ final bool includesSelf = selfPersonID != null &&+ faces.any(+ (WrappedFaceRef face) => face.personID == selfPersonID,+ );final int highQualityCount =faces.where((WrappedFaceRef face) => face.isHighQuality).length;final int effectiveCount =@@ -456,8 +492,11 @@ class _PeopleDataset {if (personID == null) {continue;}+ if (selfPersonID != null && personID == selfPersonID) {+ continue;+ }final WrappedPersonEntry? personEntry = context.persons[personID];- if (personEntry == null || personEntry.isHidden) {+ if (personEntry == null || personEntry.isHidden || personEntry.isMe) {continue;}totalNamedFaceCount += 1;@@ -465,7 +504,11 @@ class _PeopleDataset {personID,() => _PersonStats(personEntry),);- stats.addFace(file, face);+ stats.addFace(+ file: file,+ face: face,+ includesSelf: includesSelf,+ );}}@@ -507,6 +550,7 @@ class _PeopleDataset {year: year,topPeople: orderedPeople,topNamedPeople: orderedNamedPeople,+ selfPersonID: selfPersonID,totalNamedFaceCount: totalNamedFaceCount,totalFaceMoments: totalFaceMoments,groupMoments: groupMoments,@@ -522,6 +566,7 @@ class _PeopleDataset {year: year,topPeople: const <_PersonStats>[],topNamedPeople: const <_PersonStats>[],+ selfPersonID: null,totalNamedFaceCount: 0,totalFaceMoments: 0,groupMoments: 0,@@ -552,19 +597,28 @@ class _PersonStats {String get mentionForSentence =>hasName ? personEntry.displayName.trim() : "someone special";- void addFace(WrappedPeopleFile file, WrappedFaceRef face) {+ void addFace({+ required WrappedPeopleFile file,+ required WrappedFaceRef face,+ required bool includesSelf,+ }) {faceCount += 1;if (face.isHighQuality) {highQualityFaces += 1;}- final _PersonCapture capture = _captures.putIfAbsent(- file.uploadedFileID,- () => _PersonCapture(+ _PersonCapture? capture = _captures[file.uploadedFileID];+ if (capture == null) {+ capture = _PersonCapture(fileID: file.uploadedFileID,captureMicros: file.captureMicros,- ),+ includesSelf: includesSelf,+ );+ _captures[file.uploadedFileID] = capture;+ }+ capture.registerFace(+ face,+ includesSelf: includesSelf,);- capture.registerFace(face);}List<int> topMediaFileIDs(int count) {@@ -572,6 +626,9 @@ class _PersonStats {_captures.values.toList(growable: false)..sort((_PersonCapture a, _PersonCapture b) {+ if (a.includesSelf != b.includesSelf) {+ return a.includesSelf ? -1 : 1;+ }if (b.highQualityFaces != a.highQualityFaces) {return b.highQualityFaces.compareTo(a.highQualityFaces);}@@ -587,20 +644,41 @@ class _PersonStats {.take(count).toList(growable: false);}++ Map<int, double> mediaScoreHints({double withSelfBoost = 0.25}) {+ if (withSelfBoost <= 0) {+ return <int, double>{};+ }+ final Map<int, double> hints = <int, double>{};+ for (final _PersonCapture capture in _captures.values) {+ if (capture.includesSelf && capture.fileID > 0) {+ hints[capture.fileID] = (hints[capture.fileID] ?? 0) + withSelfBoost;+ }+ }+ return hints;+ }}class _PersonCapture {_PersonCapture({required this.fileID,required this.captureMicros,+ this.includesSelf = false,});final int fileID;final int captureMicros;double? bestScore;int highQualityFaces = 0;-- void registerFace(WrappedFaceRef face) {+ bool includesSelf;++ void registerFace(+ WrappedFaceRef face, {+ required bool includesSelf,+ }) {+ if (includesSelf) {+ this.includesSelf = true;+ }if (bestScore == null || face.score > bestScore!) {bestScore = face.score;}diff --git a/mobile/apps/photos/lib/services/wrapped/models.dart b/mobile/apps/photos/lib/services/wrapped/models.dartindex 2b2cea3561..92178f4339 100644--- a/mobile/apps/photos/lib/services/wrapped/models.dart+++ b/mobile/apps/photos/lib/services/wrapped/models.dart@@ -9,6 +9,7 @@ class WrappedPeopleContext {required List<WrappedPeopleFile> files,required Map<String, WrappedPersonEntry> persons,required Map<String, int> personFirstCaptureMicros,+ this.selfPersonID,}) : files = List<WrappedPeopleFile>.unmodifiable(files),persons = Map<String, WrappedPersonEntry>.unmodifiable(persons),personFirstCaptureMicros =@@ -19,12 +20,14 @@ class WrappedPeopleContext {files: const <WrappedPeopleFile>[],persons: const <String, WrappedPersonEntry>{},personFirstCaptureMicros: const <String, int>{},+ selfPersonID: null,);}final List<WrappedPeopleFile> files;final Map<String, WrappedPersonEntry> persons;final Map<String, int> personFirstCaptureMicros;+ final String? selfPersonID;bool get hasPeople => files.isNotEmpty && persons.isNotEmpty;@@ -38,6 +41,7 @@ class WrappedPeopleContext {),),"firstCaptureMicros": personFirstCaptureMicros,+ "selfPersonID": selfPersonID,};}@@ -71,6 +75,7 @@ class WrappedPeopleContext {.toList(growable: false),persons: persons,personFirstCaptureMicros: firstCaptureMicros,+ selfPersonID: json["selfPersonID"] as String?,);}}@@ -280,12 +285,14 @@ class WrappedPersonEntry {required this.displayName,required this.isHidden,required Map<String, int> clusterFaceCounts,+ this.isMe = false,}) : clusterFaceCounts = Map<String, int>.unmodifiable(clusterFaceCounts);final String personID;final String displayName;final bool isHidden;final Map<String, int> clusterFaceCounts;+ final bool isMe;int get totalClusterFaceCount {int sum = 0;@@ -301,6 +308,7 @@ class WrappedPersonEntry {"displayName": displayName,"isHidden": isHidden,"clusterFaceCounts": clusterFaceCounts,+ "isMe": isMe,};}@@ -318,6 +326,7 @@ class WrappedPersonEntry {displayName: json["displayName"] as String? ?? "",isHidden: json["isHidden"] as bool? ?? false,clusterFaceCounts: clusterFaceCounts,+ isMe: json["isMe"] as bool? ?? false,);}}diff --git a/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart b/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dartindex 16c9ae2715..5987651592 100644--- a/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart+++ b/mobile/apps/photos/lib/services/wrapped/wrapped_engine.dart@@ -1,5 +1,6 @@import "package:computer/computer.dart";import "package:logging/logging.dart";+import "package:photos/core/configuration.dart";import "package:photos/db/ml/db.dart";import "package:photos/models/file/extensions/file_props.dart";import "package:photos/models/file/file.dart";@@ -197,6 +198,9 @@ class WrappedEngine {final Map<String, int> personFirstCaptureMicros = <String, int>{};final Map<String, String> faceIdToPerson = <String, String>{};final Map<String, String> faceIdToCluster = <String, String>{};+ final String? normalizedUserEmail =+ Configuration.instance.getEmail()?.trim().toLowerCase();+ String? selfPersonID;if (PersonService.isInitialized) {try {@@ -234,11 +238,20 @@ class WrappedEngine {if (clusterFaceCounts.isEmpty) {continue;}+ final String? normalizedPersonEmail =+ data.email?.trim().toLowerCase();+ final bool isMe = normalizedUserEmail != null &&+ normalizedPersonEmail != null &&+ normalizedPersonEmail == normalizedUserEmail;+ if (isMe) {+ selfPersonID = person.remoteID;+ }personEntries[person.remoteID] = WrappedPersonEntry(personID: person.remoteID,displayName: data.name,isHidden: data.isHidden,clusterFaceCounts: clusterFaceCounts,+ isMe: isMe,);if (earliestMicros != null) {personFirstCaptureMicros[person.remoteID] = earliestMicros;@@ -294,6 +307,7 @@ class WrappedEngine {files: peopleFiles,persons: personEntries,personFirstCaptureMicros: personFirstCaptureMicros,+ selfPersonID: selfPersonID,);}