Remote
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
||||
type PersonSuggestionsAndChoices,
|
||||
type PreviewableCluster,
|
||||
} from "@/new/photos/services/ml/people";
|
||||
import { ensure } from "@/utils/ensure";
|
||||
import OverflowMenu from "@ente/shared/components/OverflowMenu/menu";
|
||||
import { OverflowMenuOption } from "@ente/shared/components/OverflowMenu/option";
|
||||
import AddIcon from "@mui/icons-material/Add";
|
||||
@@ -647,7 +648,7 @@ const saveSuggestionsAndChoices = async (
|
||||
if (choice) {
|
||||
return { id, faces: choice.faces };
|
||||
}
|
||||
throw new Error(`Unexpected cluster ${id}`);
|
||||
return undefined;
|
||||
};
|
||||
|
||||
let didUpdateAssigned = false;
|
||||
@@ -660,7 +661,7 @@ const saveSuggestionsAndChoices = async (
|
||||
}
|
||||
|
||||
// Add it to the list of assigned clusters for the person.
|
||||
assignedClusters.push(clusterForID(clusterID));
|
||||
assignedClusters.push(ensure(clusterForID(clusterID)));
|
||||
didUpdateAssigned = true;
|
||||
// Remove it from the list of rejected clusters (if needed).
|
||||
if (rejectedClusterIDs.includes(clusterID)) {
|
||||
@@ -688,6 +689,14 @@ const saveSuggestionsAndChoices = async (
|
||||
}
|
||||
}
|
||||
|
||||
if (didUpdateAssigned) {
|
||||
addClusterToCGroup(
|
||||
ensure(person.cgroup),
|
||||
cluster,
|
||||
),
|
||||
|
||||
}
|
||||
|
||||
const newlyAddedClusterIDs = new Set<string>();
|
||||
const newlyRemovedClusterIDs = new Set<string>();
|
||||
for (const [clusterID, assigned] of state.marks.entries()) {
|
||||
|
||||
@@ -750,9 +750,25 @@ export const addCGroup = async (name: string, cluster: FaceCluster) => {
|
||||
export const addClusterToCGroup = async (
|
||||
cgroup: CGroup,
|
||||
cluster: FaceCluster,
|
||||
) =>
|
||||
updateAssignedClustersForCGroup(
|
||||
cgroup,
|
||||
cgroup.data.assigned.concat([cluster]),
|
||||
);
|
||||
|
||||
/**
|
||||
* Update the clusters assigned to an existing named person.
|
||||
*
|
||||
* @param cgroup The existing cgroup underlying the person. This is the (remote)
|
||||
* user entity that will get updated.
|
||||
*
|
||||
* @param cluster The new value of the face clusters assigned to this person.
|
||||
*/
|
||||
export const updateAssignedClustersForCGroup = async (
|
||||
cgroup: CGroup,
|
||||
assigned: FaceCluster[],
|
||||
) => {
|
||||
const masterKey = await masterKeyFromSession();
|
||||
const assigned = cgroup.data.assigned.concat([cluster]);
|
||||
await updateOrCreateUserEntities(
|
||||
"cgroup",
|
||||
[{ ...cgroup, data: { ...cgroup.data, assigned } }],
|
||||
|
||||
Reference in New Issue
Block a user