Filter out rejected face IDs when using remote cgroups
This commit is contained in:
@@ -67,6 +67,9 @@ export interface CGroupUserEntityData {
|
||||
/**
|
||||
* An unordered set of faces (IDs) that the user has manually marked as not
|
||||
* belonging to this group.
|
||||
*
|
||||
* For ease of transportation and persistence this is an array, but it
|
||||
* should conceptually be thought of as a set.
|
||||
*/
|
||||
rejectedFaceIDs: string[];
|
||||
/**
|
||||
@@ -265,11 +268,20 @@ export const reconstructPeopleState = async (): Promise<PeopleState> => {
|
||||
// their name to an empty string.
|
||||
if (!name) isHidden = true;
|
||||
|
||||
let assignedFaceIDs: string[][];
|
||||
if (data.rejectedFaceIDs.length == 0) {
|
||||
// Fast path for when there are no rejected faces.
|
||||
assignedFaceIDs = assigned.map(({ faces }) => faces);
|
||||
} else {
|
||||
const rejectedFaceIDs = new Set(data.rejectedFaceIDs);
|
||||
assignedFaceIDs = assigned.map(({ faces }) =>
|
||||
faces.filter((id) => !rejectedFaceIDs.has(id)),
|
||||
);
|
||||
}
|
||||
|
||||
// Person faces from all the clusters assigned to this cgroup, sorted by
|
||||
// recency (then score).
|
||||
const faces = personFacesSortedNewestFirst(
|
||||
assigned.map(({ faces }) => faces).flat(),
|
||||
);
|
||||
const faces = personFacesSortedNewestFirst(assignedFaceIDs.flat());
|
||||
|
||||
// Ignore this cgroup if we don't have visible faces left in it.
|
||||
const mostRecentFace = faces[0];
|
||||
|
||||
@@ -2,7 +2,11 @@ import { authenticatedRequestHeaders, ensureOk } from "@/base/http";
|
||||
import { getKV, setKV } from "@/base/kv";
|
||||
import { apiURL, familyAppOrigin, paymentsAppOrigin } from "@/base/origins";
|
||||
import { ensure } from "@/utils/ensure";
|
||||
import { nullishToZero, nullToUndefined } from "@/utils/transform";
|
||||
import {
|
||||
nullishToEmpty,
|
||||
nullishToZero,
|
||||
nullToUndefined,
|
||||
} from "@/utils/transform";
|
||||
import { getData, LS_KEYS, setLSUser } from "@ente/shared/storage/localStorage";
|
||||
import isElectron from "is-electron";
|
||||
import { z } from "zod";
|
||||
@@ -112,9 +116,7 @@ const BonusData = z.object({
|
||||
/**
|
||||
* List of bonuses applied for the user.
|
||||
*/
|
||||
storageBonuses: Bonus.array()
|
||||
.nullish()
|
||||
.transform((v) => v ?? []),
|
||||
storageBonuses: Bonus.array().nullish().transform(nullishToEmpty),
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
encryptBoxB64,
|
||||
generateNewBlobOrStreamKey,
|
||||
} from "@/base/crypto";
|
||||
import { nullToUndefined } from "@/utils/transform";
|
||||
import { nullishToEmpty, nullToUndefined } from "@/utils/transform";
|
||||
import { z } from "zod";
|
||||
import { gunzip, gzip } from "../../utils/gzip";
|
||||
import type { CGroupUserEntityData } from "../ml/people";
|
||||
@@ -85,7 +85,7 @@ const RemoteFaceCluster = z.object({
|
||||
const RemoteCGroupData = z.object({
|
||||
name: z.string().nullish().transform(nullToUndefined),
|
||||
assigned: z.array(RemoteFaceCluster),
|
||||
rejectedFaceIDs: z.array(z.string()).nullish().transform(nullToUndefined),
|
||||
rejectedFaceIDs: z.array(z.string()).nullish().transform(nullishToEmpty),
|
||||
isHidden: z.boolean(),
|
||||
avatarFaceID: z.string().nullish().transform(nullToUndefined),
|
||||
});
|
||||
|
||||
@@ -8,3 +8,8 @@ export const nullToUndefined = <T>(v: T | null | undefined): T | undefined =>
|
||||
* Convert `null` and `undefined` to `0`, passthrough everything else unchanged.
|
||||
*/
|
||||
export const nullishToZero = (v: number | null | undefined) => v ?? 0;
|
||||
|
||||
/**
|
||||
* Convert `null` and `undefined` to `[]`, passthrough everything else unchanged.
|
||||
*/
|
||||
export const nullishToEmpty = <T>(v: T[] | null | undefined) => v ?? [];
|
||||
|
||||
Reference in New Issue
Block a user