Skip to content

armgit / ente

Public Imported from GitHub
0

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

Remote

Manav Rathidca7e9099483
diff --git a/web/packages/new/photos/components/gallery/PeopleHeader.tsx b/web/packages/new/photos/components/gallery/PeopleHeader.tsx
index e544b1cc9c..1ad04aa848 100644
--- a/web/packages/new/photos/components/gallery/PeopleHeader.tsx
+++ b/web/packages/new/photos/components/gallery/PeopleHeader.tsx
@@ -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()) {
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index f3469a7dd0..f203080b9c 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -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 } }],