Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Consistent face thumbnails in hierarchical

laurenspriem733fd45d6f00
diff --git a/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart b/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
index 4f88ac0256..69bcf8d03c 100644
--- a/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
+++ b/mobile/lib/ui/viewer/gallery/hierarchical_search_gallery.dart
@@ -175,6 +175,7 @@ class _HierarchicalSearchGalleryState extends State<HierarchicalSearchGallery> {
clusterID:
_firstUnnamedAppliedFaceFilter!.clusterId,
thumbnailFallback: false,
+ cannotTrustFile: true,
),
actionIcon: Icons.add_outlined,
text: S.of(context).savePerson,
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
index 20fda3f9c5..67d99be854 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/face_filter_chip.dart
@@ -77,6 +77,7 @@ class _FaceFilterChipState extends State<FaceFilterChip> {
clusterID: widget.clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
),
diff --git a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
index ce0d9efa5c..29972cc8ea 100644
--- a/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
+++ b/mobile/lib/ui/viewer/hierarchicial_search/chip_widgets/only_them_filter_chip.dart
@@ -92,6 +92,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters.first.clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
);
@@ -108,6 +109,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters.first.clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
const SizedBox(width: 1),
@@ -120,6 +122,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters.last.clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
],
@@ -139,6 +142,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters[0].clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
const SizedBox(width: 1),
@@ -158,6 +162,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters[1].clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
),
@@ -175,6 +180,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters[2].clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
),
@@ -204,6 +210,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters[0].clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
),
@@ -221,6 +228,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters[1].clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
),
@@ -243,6 +251,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters[2].clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
),
@@ -260,6 +269,7 @@ class _OnlyThemFilterThumbnail extends StatelessWidget {
clusterID: faceFilters[3].clusterId,
thumbnailFallback: false,
useFullFile: false,
+ cannotTrustFile: true,
),
),
),
diff --git a/mobile/lib/ui/viewer/search/result/person_face_widget.dart b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
index bd4e971e32..fbe034448b 100644
--- a/mobile/lib/ui/viewer/search/result/person_face_widget.dart
+++ b/mobile/lib/ui/viewer/search/result/person_face_widget.dart
@@ -8,6 +8,7 @@ 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/services/machine_learning/face_ml/person/person_service.dart";
+import "package:photos/services/machine_learning/ml_result.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/viewer/file/thumbnail_widget.dart";
@@ -19,6 +20,7 @@ class PersonFaceWidget extends StatelessWidget {
final String? clusterID;
final bool useFullFile;
final bool thumbnailFallback;
+ final bool cannotTrustFile;
final Uint8List? faceCrop;
// PersonFaceWidget constructor checks that both personId and clusterID are not null
@@ -29,6 +31,7 @@ class PersonFaceWidget extends StatelessWidget {
this.clusterID,
this.useFullFile = true,
this.thumbnailFallback = true,
+ this.cannotTrustFile = false,
this.faceCrop,
super.key,
}) : assert(
@@ -79,16 +82,42 @@ class PersonFaceWidget extends StatelessWidget {
Future<Uint8List?> _getFaceCrop() async {
try {
+ EnteFile? fileForFaceCrop = file;
String? personAvatarFaceID;
if (personId != null) {
final PersonEntity? personEntity =
await PersonService.instance.getPerson(personId!);
if (personEntity != null) {
personAvatarFaceID = personEntity.data.avatarFaceID;
+ if (personAvatarFaceID == null && cannotTrustFile) {
+ final allFaces =
+ await MLDataDB.instance.getFaceIDsForPerson(personId!);
+ final allFileIDs = allFaces.map((e) => getFileIdFromFaceId(e));
+ final fileIDToCreationTime =
+ await FilesDB.instance.getFileIDToCreationTime();
+ // Get the file with the most recent creation time
+ final recentFileID = allFileIDs.reduce((a, b) {
+ final aTime = fileIDToCreationTime[a];
+ final bTime = fileIDToCreationTime[b];
+ if (aTime == null) {
+ return b;
+ }
+ if (bTime == null) {
+ return a;
+ }
+ return (aTime >= bTime) ? a : b;
+ });
+ if (fileForFaceCrop.uploadedFileID != recentFileID) {
+ fileForFaceCrop =
+ await FilesDB.instance.getAnyUploadedFile(recentFileID);
+ if (fileForFaceCrop == null) return null;
+ }
+ }
}
}
+
final Face? face = await MLDataDB.instance.getCoverFaceForPerson(
- recentFileID: file.uploadedFileID!,
+ recentFileID: fileForFaceCrop.uploadedFileID!,
avatarFaceId: personAvatarFaceID,
personID: personId,
clusterID: clusterID,
@@ -99,13 +128,10 @@ class PersonFaceWidget extends StatelessWidget {
);
return null;
}
- EnteFile? fileForFaceCrop = file;
- if (face.fileID != file.uploadedFileID!) {
+ if (face.fileID != fileForFaceCrop.uploadedFileID!) {
fileForFaceCrop =
await FilesDB.instance.getAnyUploadedFile(face.fileID);
- }
- if (fileForFaceCrop == null) {
- return null;
+ if (fileForFaceCrop == null) return null;
}
final cropMap = await getCachedFaceCrops(
fileForFaceCrop,
@@ -122,5 +148,4 @@ class PersonFaceWidget extends StatelessWidget {
return null;
}
}
-
}