π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use most recent face as the auto-cover
Manav Rathia2841a8af203
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.tsindex dbf67ec3d9..ef30e36707 100644--- a/web/packages/new/photos/services/ml/people.ts+++ b/web/packages/new/photos/services/ml/people.ts@@ -161,6 +161,20 @@ export const reconstructPeople = async (): Promise<Person[]> => {}}+ // Return annotated "person faces" corresponding to the given face ids,+ // sorting them by the creation time of the file they belong to.+ //+ // Within the same file, sort by the face score.+ const personFacesSortedNewestFirst = (faceIDs: string[]) =>+ faceIDs+ .map((faceID) => personFaceByID.get(faceID))+ .filter((pf) => !!pf)+ .sort((a, b) => {+ const at = a.file.metadata.creationTime;+ const bt = b.file.metadata.creationTime;+ return bt == at ? b.score - a.score : bt - at;+ });+// Help out tsc.type Interim = (Person | undefined)[];@@ -179,17 +193,14 @@ export const reconstructPeople = async (): Promise<Person[]> => {if (!name) return undefined;// Person faces from all the clusters assigned to this cgroup, sorted by- // their score.- const faces = assigned- .map(({ faces }) =>- faces.map((id) => personFaceByID.get(id)).filter((f) => !!f),- )- .flat()- .sort((a, b) => b.score - a.score);+ // recency (then score).+ const faces = personFacesSortedNewestFirst(+ assigned.map(({ faces }) => faces).flat(),+ );// Ignore this cgroup if we don't have visible faces left in it.- const highestScoringFace = faces[0];- if (!highestScoringFace) return undefined;+ const mostRecentFace = faces[0];+ if (!mostRecentFace) return undefined;// IDs of the files containing this face.const fileIDs = [...new Set(faces.map((f) => f.file.id))];@@ -208,8 +219,8 @@ export const reconstructPeople = async (): Promise<Person[]> => {displayFaceID = avatarFaceID;displayFaceFile = avatarFile;} else {- displayFaceID = highestScoringFace.faceID;- displayFaceFile = highestScoringFace.file;+ displayFaceID = mostRecentFace.faceID;+ displayFaceFile = mostRecentFace.file;}return {@@ -226,25 +237,23 @@ export const reconstructPeople = async (): Promise<Person[]> => {// Convert local-only clusters to people.const localClusters = await savedFaceClusters();const clusterPeople: Interim = localClusters.map((cluster) => {- const faces = cluster.faces- .map((id) => personFaceByID.get(id))- .filter((f) => !!f);+ const faces = personFacesSortedNewestFirst(cluster.faces);++ // Ignore this cluster if we don't have visible faces left in it.+ const mostRecentFace = faces[0];+ if (!mostRecentFace) return undefined;// Ignore clusters with too few visible faces.if (faces.length < 10) return undefined;- const topFace = faces.reduce((top, face) =>- top.score > face.score ? top : face,- );-return {type: "cluster",cluster,id: cluster.id,name: undefined,fileIDs: [...new Set(faces.map((f) => f.file.id))],- displayFaceID: topFace.faceID,- displayFaceFile: topFace.file,+ displayFaceID: mostRecentFace.faceID,+ displayFaceFile: mostRecentFace.file,};});