π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
refractor(people.ts):handling-to-pass-currentUserId-explictly-for-non-window-contexts
Aswin Asok562d30c3d496
diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex ba51dd90dd..25b5d7c8d9 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -7,6 +7,7 @@ import {encryptBox,generateKey,} from "ente-base/crypto";+import { haveWindow } from "ente-base/env";import { authenticatedRequestHeaders, ensureOk } from "ente-base/http";import { apiURL } from "ente-base/origins";import { ensureMasterKeyFromSession } from "ente-base/session";@@ -486,9 +487,14 @@ export const savedNormalCollections = (): Promise<Collection[]> =>/*** Return all hidden collections that are present in our local database.*/-export const savedHiddenCollections = (): Promise<Collection[]> =>+export const savedHiddenCollections = (+ currentUserID?: number,+): Promise<Collection[]> =>savedCollections().then(- (cs) => splitByPredicate(cs, isHiddenCollection)[0],+ (cs) =>+ splitByPredicate(cs, (c) =>+ isHiddenCollection(c, currentUserID),+ )[0],);/**@@ -1350,9 +1356,24 @@ export const findDefaultHiddenCollectionIDs = (collections: Collection[]) =>** Hidden collections are those that have their visibility set to hidden for* the current user (owner or sharee).+ *+ * In one instance, the isHiddenCollection function is called outside of a window, like+ * for the people tab's review suggestions, this function was trigged from a worker.+ * In that case, since the worker has no access to the localStorage, we need to pass the currentUserID+ * explicitly.*/-export const isHiddenCollection = (collection: Collection) => {- const userID = ensureLocalUser().id;+export const isHiddenCollection = (+ collection: Collection,+ currentUserID?: number,+) => {+ const userID =+ currentUserID ?? (haveWindow() ? ensureLocalUser().id : undefined);++ if (userID === undefined) {+ throw new Error(+ "isHiddenCollection: currentUserID is required outside window context",+ );+ }if (collection.owner.id == userID) {return (collection.magicMetadata?.data.visibility == ItemVisibility.hiddendiff --git a/web/packages/new/photos/services/file.ts b/web/packages/new/photos/services/file.tsindex ee41a9a2f8..ac82b9eea3 100644--- a/web/packages/new/photos/services/file.ts+++ b/web/packages/new/photos/services/file.ts@@ -65,8 +65,10 @@ export const computeAllCollectionFilesFromSaved = async () =>* The long name and the "compute" in it is to signal that this is not just a DB* read, and that it also does some potentially non-trivial computation.*/-export const computeNormalCollectionFilesFromSaved = async () => {- const hiddenCollections = await savedHiddenCollections();+export const computeNormalCollectionFilesFromSaved = async (+ currentUserID?: number,+) => {+ const hiddenCollections = await savedHiddenCollections(currentUserID);const hiddenCollectionIDs = new Set(hiddenCollections.map((c) => c.id));const collectionFiles = await savedCollectionFiles();diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.tsindex 7257929320..d5c23bf421 100644--- a/web/packages/new/photos/services/ml/index.ts+++ b/web/packages/new/photos/services/ml/index.ts@@ -3,6 +3,7 @@*/import { proxy, transfer } from "comlink";+import { ensureLocalUser } from "ente-accounts/services/user";import { isDesktop } from "ente-base/app";import { blobCache } from "ente-base/blob-cache";import { ensureElectron } from "ente-base/electron";@@ -953,9 +954,15 @@ export const addManualFileAssignmentsToPerson = async (* Return suggestions for the given {@link person}.** The suggestion computation happens in a web worker.- */+ *+ * Since the computation is happening in a web worker, and it doesn't+ * have access to any localStorage, we need to pass the currentUserID explicitly.+ * for the isHiddenCollection checks in the process.+ * */export const suggestionsAndChoicesForPerson = async (person: CGroupPerson) =>- worker().then((w) => w.suggestionsAndChoicesForPerson(person));+ worker().then((w) =>+ w.suggestionsAndChoicesForPerson(person, ensureLocalUser().id),+ );/*** Implementation for the "save" action on the SuggestionsDialog.diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.tsindex 213a747912..db698065bf 100644--- a/web/packages/new/photos/services/ml/people.ts+++ b/web/packages/new/photos/services/ml/people.ts@@ -487,6 +487,7 @@ export interface PersonSuggestionsAndChoices {*/export const _suggestionsAndChoicesForPerson = async (person: CGroupPerson,+ currentUserID: number,): Promise<PersonSuggestionsAndChoices> => {const startTime = Date.now();@@ -565,7 +566,8 @@ export const _suggestionsAndChoicesForPerson = async (// Annotate the clusters with the information that the UI needs to show its// preview faces.- const normalCollectionFiles = await computeNormalCollectionFilesFromSaved();+ const normalCollectionFiles =+ await computeNormalCollectionFilesFromSaved(currentUserID);const fileByID = new Map(normalCollectionFiles.map((f) => [f.id, f]));const toPreviewable = (cluster: FaceCluster) => {diff --git a/web/packages/new/photos/services/ml/worker.ts b/web/packages/new/photos/services/ml/worker.tsindex 8e06024b1a..919f9fef77 100644--- a/web/packages/new/photos/services/ml/worker.ts+++ b/web/packages/new/photos/services/ml/worker.ts@@ -339,8 +339,11 @@ export class MLWorker {/*** Return suggestions and choices for the given cgroup {@link person}.*/- async suggestionsAndChoicesForPerson(person: CGroupPerson) {- return _suggestionsAndChoicesForPerson(person);+ async suggestionsAndChoicesForPerson(+ person: CGroupPerson,+ currentUserID: number,+ ) {+ return _suggestionsAndChoicesForPerson(person, currentUserID);}}