Skip to content

armgit / ente

Public Imported from GitHub
0

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

Match mobile File Info ignored face labels and ordering

Aswin Asok0f0a36b1029f
diff --git a/web/packages/gallery/components/FileInfo.tsx b/web/packages/gallery/components/FileInfo.tsx
index 5a466189a7..7555d03909 100644
--- a/web/packages/gallery/components/FileInfo.tsx
+++ b/web/packages/gallery/components/FileInfo.tsx
@@ -169,7 +169,6 @@ export const FileInfo: React.FC<FileInfoProps> = ({
return (peopleState?.people ?? []).filter(
(p) =>
p.type == "cgroup" &&
- !!p.name &&
p.cgroup.data.manuallyAssigned.includes(file.id) &&
!detectedPersonIDs.has(p.id),
);
@@ -200,7 +199,7 @@ export const FileInfo: React.FC<FileInfoProps> = ({
return () => {
didCancel = true;
};
- }, [file, open]);
+ }, [file, open, peopleState]);
const handleClose = () => {
if (captionEditState == "saving") return;
diff --git a/web/packages/new/photos/components/PeopleList.tsx b/web/packages/new/photos/components/PeopleList.tsx
index 2f1cf02f33..150e18e7cd 100644
--- a/web/packages/new/photos/components/PeopleList.tsx
+++ b/web/packages/new/photos/components/PeopleList.tsx
@@ -133,54 +133,63 @@ export const FilePeopleList: React.FC<FilePeopleListProps> = ({
onAddPerson,
addPersonTitle,
addPersonLabel,
-}) => (
- <FilePeopleList_>
- {annotatedFaceIDs.map((annotatedFaceID) => (
- <AnnotatedFaceButton
- key={annotatedFaceID.faceID}
- onClick={() => onSelectFace(annotatedFaceID)}
- >
- <FaceCropImageView
- faceID={annotatedFaceID.faceID}
- file={file}
- placeholderDimension={65}
- />
- <Typography variant="small" sx={{ color: "text.muted" }}>
- {annotatedFaceID.personName}
- </Typography>
- </AnnotatedFaceButton>
- ))}
- {manuallyAssignedPeople?.map((person) => (
- <ManuallyAssignedPersonButton
- key={person.id}
- onClick={() => onSelectPerson?.(person.id)}
- >
- <FaceCropImageView
- faceID={person.displayFaceID}
- file={person.displayFaceFile}
- placeholderDimension={65}
- />
- <Typography variant="small" sx={{ color: "text.muted" }}>
- {person.name}
- </Typography>
- </ManuallyAssignedPersonButton>
- ))}
- {onAddPerson && (
- <AddPersonButton
- onClick={onAddPerson}
- title={addPersonTitle}
- aria-label={addPersonTitle}
- >
- <AddPersonAvatar>
- <PersonAddIcon />
- </AddPersonAvatar>
- <Typography variant="small" sx={{ color: "text.muted" }}>
- {addPersonLabel}
- </Typography>
- </AddPersonButton>
- )}
- </FilePeopleList_>
-);
+}) => {
+ const entries = [
+ ...(manuallyAssignedPeople ?? [])
+ .toSorted((a, b) => {
+ const an = (a.name ?? "").toLowerCase();
+ const bn = (b.name ?? "").toLowerCase();
+ return an < bn ? -1 : an > bn ? 1 : 0;
+ })
+ .map((person) => ({
+ key: person.id,
+ faceID: person.displayFaceID,
+ file: person.displayFaceFile,
+ name: person.name,
+ isIgnored: person.type == "cgroup" && person.isHidden,
+ onClick: () => onSelectPerson?.(person.id),
+ })),
+ ...annotatedFaceIDs.map((face) => ({
+ key: face.faceID,
+ faceID: face.faceID,
+ file,
+ name: face.personName,
+ isIgnored: face.isIgnored,
+ onClick: () => onSelectFace(face),
+ })),
+ ];
+
+ return (
+ <FilePeopleList_>
+ {entries.map(({ key, faceID, file, name, isIgnored, onClick }) => (
+ <AnnotatedFaceButton key={key} onClick={onClick}>
+ <FaceCropImageView
+ faceID={faceID}
+ file={file}
+ placeholderDimension={65}
+ />
+ <Typography variant="small" sx={{ color: "text.muted" }}>
+ {isIgnored ? `(${t("ignored")})` : name}
+ </Typography>
+ </AnnotatedFaceButton>
+ ))}
+ {onAddPerson && (
+ <AddPersonButton
+ onClick={onAddPerson}
+ title={addPersonTitle}
+ aria-label={addPersonTitle}
+ >
+ <AddPersonAvatar>
+ <PersonAddIcon />
+ </AddPersonAvatar>
+ <Typography variant="small" sx={{ color: "text.muted" }}>
+ {addPersonLabel}
+ </Typography>
+ </AddPersonButton>
+ )}
+ </FilePeopleList_>
+ );
+};
const FilePeopleList_ = styled("div")`
display: flex;
@@ -208,8 +217,6 @@ const AnnotatedFaceButton = styled(UnstyledButton)(
`,
);
-const ManuallyAssignedPersonButton = AnnotatedFaceButton;
-
const AddPersonButton = styled(UnstyledButton)(
({ theme }) => `
width: 65px;
diff --git a/web/packages/new/photos/services/ml/face.ts b/web/packages/new/photos/services/ml/face.ts
index a6d8501e1f..7fe4bff9ff 100644
--- a/web/packages/new/photos/services/ml/face.ts
+++ b/web/packages/new/photos/services/ml/face.ts
@@ -1,4 +1,42 @@
import { assertionFailed } from "ente-base/assert";
+import type { Person } from "./people";
+
+export interface AnnotatedFaceID {
+ faceID: string;
+ personID: string;
+ personName: string | undefined;
+ isIgnored: boolean;
+}
+
+export const annotateFileFaces = (
+ faces: Face[],
+ personByFaceID: ReadonlyMap<string, Person>,
+): AnnotatedFaceID[] => {
+ const annotatedFaces = faces.flatMap(({ faceID, score }) => {
+ const person = personByFaceID.get(faceID);
+ if (!person) return [];
+ return [
+ {
+ annotation: {
+ faceID,
+ personID: person.id,
+ personName: person.name,
+ isIgnored: person.type == "cgroup" && person.isHidden,
+ },
+ isAssigned: person.type == "cgroup",
+ score,
+ },
+ ];
+ });
+
+ annotatedFaces.sort((a, b) => {
+ if (a.annotation.isIgnored != b.annotation.isIgnored)
+ return a.annotation.isIgnored ? 1 : -1;
+ if (a.isAssigned != b.isAssigned) return a.isAssigned ? -1 : 1;
+ return b.score - a.score;
+ });
+ return annotatedFaces.map(({ annotation }) => annotation);
+};
export const faceIndexingVersion = 1;
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 3dd4f9b6c7..0a62456c0f 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -25,7 +25,11 @@ import { deleteUserEntity } from "../user-entity/remote";
import type { ClusterFacesReason, FaceCluster } from "./cluster";
import { regenerateFaceCrops } from "./crop";
import { clearMLDB, savedFaceIndex, savedIndexCounts } from "./db";
-import { fileIDFromFaceID } from "./face";
+import {
+ annotateFileFaces,
+ fileIDFromFaceID,
+ type AnnotatedFaceID,
+} from "./face";
import {
_applyPersonSuggestionUpdates,
filterNamedPeople,
@@ -333,11 +337,7 @@ export const clipMatches = (
): Promise<CLIPMatches | undefined> =>
worker().then((w) => w.clipMatches(searchPhrase));
-export interface AnnotatedFaceID {
- faceID: string;
- personID: string;
- personName: string | undefined;
-}
+export type { AnnotatedFaceID } from "./face";
export const getAnnotatedFacesForFile = async (
file: EnteFile,
@@ -350,22 +350,7 @@ export const getAnnotatedFacesForFile = async (
const personByFaceID = _state.peopleStateSnapshot?.personByFaceID;
if (!personByFaceID) return [];
- const sortableFaces: [AnnotatedFaceID, number][] = [];
- for (const { faceID } of index.faces) {
- const person = personByFaceID.get(faceID);
- if (!person) continue;
- sortableFaces.push([
- { faceID, personID: person.id, personName: person.name },
- person.fileIDs.length,
- ]);
- }
-
- sortableFaces.sort((a, b) => {
- if (a[0].personName && !b[0].personName) return -1;
- if (!a[0].personName && b[0].personName) return 1;
- return b[1] - a[1];
- });
- return sortableFaces.map(([f]) => f);
+ return annotateFileFaces(index.faces, personByFaceID);
};
export const faceCrop = async (faceID: string, file: EnteFile) => {
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index 8ea002b8d2..d1005fc672 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -108,8 +108,8 @@ export const reconstructPeopleState = async (): Promise<PeopleState> => {
let isHidden = data.isHidden;
- // Older mobile clients encoded hidden cgroups with an empty name.
- if (!name) isHidden = true;
+ // Older mobile clients encoded ignored people in the name.
+ if (!name || name == "(hidden)" || name == "(ignored)") isHidden = true;
let assignedFaceIDs: string[][];
if (data.rejectedFaceIDs.length == 0) {