From dd8cef3ddf7a330b77e2f438d46f3662e4792a3e Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Sat, 23 Nov 2024 16:07:11 +0530 Subject: [PATCH] [mob][photos] keep face crops for clusters as well --- .../search/result/person_face_widget.dart | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) 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 fd1ac4fc7d..8afad975bc 100644 --- a/mobile/lib/ui/viewer/search/result/person_face_widget.dart +++ b/mobile/lib/ui/viewer/search/result/person_face_widget.dart @@ -88,6 +88,7 @@ class _PersonFaceWidgetState extends State { try { EnteFile? fileForFaceCrop = widget.file; String? personAvatarFaceID; + Iterable? allFaces; if (widget.personId != null) { final PersonEntity? personEntity = await PersonService.instance.getPerson(widget.personId!); @@ -99,30 +100,35 @@ class _PersonFaceWidgetState extends State { if (tryCache != null) return tryCache; } if (personAvatarFaceID == null && widget.cannotTrustFile) { - final allFaces = + allFaces = await MLDataDB.instance.getFaceIDsForPerson(widget.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; - } } } + } else if (widget.clusterID != null && widget.cannotTrustFile) { + allFaces = + await MLDataDB.instance.getFaceIDsForCluster(widget.clusterID!); + } + if (allFaces != null) { + 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(