π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
norm + hidden - wip 5
Manav Rathic8715ca84675
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 017d7d026e..d8417a764a 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -80,7 +80,7 @@ import {} from "ente-new/photos/services/photos-fdb";import {filterSearchableFiles,- setSearchCollectionsAndFiles,+ updateSearchCollectionsAndFiles,} from "ente-new/photos/services/search";import type { SearchOption } from "ente-new/photos/services/search/types";import { initSettings } from "ente-new/photos/services/settings";@@ -259,9 +259,6 @@ const Page: React.FC = () => {// Local aliases.const {user,- normalCollections,- normalFiles,- hiddenFiles,favoriteFileIDs,collectionNameByID,fileNormalCollectionIDs,@@ -346,13 +343,6 @@ const Page: React.FC = () => {};}, []);- useEffect(() => {- setSearchCollectionsAndFiles({- collections: normalCollections,- files: normalFiles,- });- }, [normalCollections, normalFiles]);-useEffect(() => {if (typeof activeCollectionID == "undefined" || !router.isReady) {return;@@ -376,6 +366,14 @@ const Page: React.FC = () => {}}, [router.isReady]);+ useEffect(() => {+ updateSearchCollectionsAndFiles(+ state.collections,+ state.hiddenCollectionIDs,+ state.collectionFiles,+ );+ }, [state.collections, state.hiddenCollectionIDs, state.collectionFiles]);+useEffect(() => {dispatch({ type: "setPeopleState", peopleState });}, [peopleState]);@@ -684,7 +682,7 @@ const Page: React.FC = () => {// passing files here instead of filteredData for hide ops because we want to move all files copies to hidden collectionconst selectedFiles = getSelectedFiles(selected,- op == "hide" ? normalFiles : filteredFiles,+ op == "hide" ? state.collectionFiles : filteredFiles,);const toProcessFiles =op == "download"@@ -927,7 +925,7 @@ const Page: React.FC = () => {// show "selectable" normalCollectionSummaries. See:// [Note: Picking from selectable collection summaries].findCollectionCreatingUncategorizedIfNeeded(- normalCollections,+ state.collections,id,)!}@@ -965,7 +963,7 @@ const Page: React.FC = () => {activeCollectionID={activeCollectionID}selectedCollection={getSelectedCollection(selected.collectionID,- normalCollections,+ state.collections,)}isFavoriteCollection={normalCollectionSummaries.get(@@ -1078,8 +1076,7 @@ const Page: React.FC = () => {<WhatsNew {...whatsNewVisibilityProps} />{!isInSearchMode &&!isFirstLoad &&- !normalFiles?.length &&- !hiddenFiles?.length &&+ !state.collectionFiles.length &&activeCollectionID === PseudoCollectionID.all ? (<GalleryEmptyStateisUploadInProgress={uploadManager.isUploadInProgress()}@@ -1098,7 +1095,7 @@ const Page: React.FC = () => {files={filteredFiles}enableDownload={true}showAppDownloadBanner={- normalFiles.length < 30 && !isInSearchMode+ state.collectionFiles.length < 30 && !isInSearchMode}selectable={true}selected={selected}diff --git a/web/apps/photos/tests/upload.test.ts b/web/apps/photos/tests/upload.test.tsindex 17eacfd919..8421e00850 100644--- a/web/apps/photos/tests/upload.test.ts+++ b/web/apps/photos/tests/upload.test.ts@@ -15,7 +15,7 @@ import {} from "ente-media/file-metadata";import { FileType } from "ente-media/file-type";import { getLocalCollections } from "ente-new/photos/services/collections";-import { savedNormalFiles } from "ente-new/photos/services/photos-fdb";+import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";import { getUserDetailsV2 } from "ente-new/photos/services/user-details";const DATE_TIME_PARSING_TEST_FILE_NAMES = [@@ -191,7 +191,7 @@ async function totalCollectionCountCheck(expectedState) {}async function collectionWiseFileCount(expectedState) {- const files = await savedNormalFiles();+ const files = await savedCollectionFiles();const collections = await getLocalCollections();const collectionToFilesMap = groupFilesByCollectionID(files);const collectionIDToNameMap = new Map(@@ -220,7 +220,7 @@ async function collectionWiseFileCount(expectedState) {}async function thumbnailGenerationFailedFilesCheck(expectedState) {- const files = await savedNormalFiles();+ const files = await savedCollectionFiles();const filesWithStaticThumbnail = files.filter((file) => file.metadata.hasStaticThumbnail,);@@ -262,7 +262,7 @@ async function thumbnailGenerationFailedFilesCheck(expectedState) {}async function livePhotoClubbingCheck(expectedState) {- const files = await savedNormalFiles();+ const files = await savedCollectionFiles();const livePhotos = files.filter((file) => file.metadata.fileType == FileType.livePhoto,);@@ -297,7 +297,7 @@ async function livePhotoClubbingCheck(expectedState) {}async function exifDataParsingCheck(expectedState) {- const files = await savedNormalFiles();+ const files = await savedCollectionFiles();Object.entries(expectedState.exif).map(([fileName, exifValues]) => {const matchingFile = files.find((file) => fileFileName(file) == fileName,@@ -330,7 +330,7 @@ async function exifDataParsingCheck(expectedState) {}async function fileDimensionExtractionCheck(expectedState) {- const files = await savedNormalFiles();+ const files = await savedCollectionFiles();Object.entries(expectedState.file_dimensions).map(([fileName, dimensions]) => {const matchingFile = files.find(@@ -357,7 +357,7 @@ async function fileDimensionExtractionCheck(expectedState) {}async function googleMetadataReadingCheck(expectedState) {- const files = await savedNormalFiles();+ const files = await savedCollectionFiles();Object.entries(expectedState.google_import).map(([fileName, metadata]) => {const matchingFile = files.find((file) => fileFileName(file) == fileName,diff --git a/web/packages/gallery/services/video.ts b/web/packages/gallery/services/video.tsindex bfa039ff2d..b88ce419a7 100644--- a/web/packages/gallery/services/video.ts+++ b/web/packages/gallery/services/video.ts@@ -13,7 +13,7 @@ import { uniqueFilesByID } from "ente-gallery/utils/files";import { fileLogID, type EnteFile } from "ente-media/file";import { FileType } from "ente-media/file-type";import { updateFilePublicMagicMetadata } from "ente-new/photos/services/file";-import { savedFiles } from "ente-new/photos/services/photos-fdb";+import { savedCollectionFiles } from "ente-new/photos/services/photos-fdb";import { getLocalTrashFileIDs } from "ente-new/photos/services/trash";import { gunzip, gzip } from "ente-new/photos/utils/gzip";import { randomSample } from "ente-utils/array";@@ -877,7 +877,7 @@ const processQueue = async () => {const backfillQueue = async (userID: number,): Promise<VideoProcessingQueueItem[]> => {- const allCollectionFiles = await savedFiles();+ const allCollectionFiles = await savedCollectionFiles();const localTrashFileIDs = await getLocalTrashFileIDs();const videoFiles = uniqueFilesByID(allCollectionFiles.filter(diff --git a/web/packages/new/photos/services/collection.ts b/web/packages/new/photos/services/collection.tsindex 4297a1d35b..32eb961fec 100644--- a/web/packages/new/photos/services/collection.ts+++ b/web/packages/new/photos/services/collection.ts@@ -244,6 +244,15 @@ export const savedNormalCollections = (): Promise<Collection[]> =>(cs) => splitByPredicate(cs, isHiddenCollection)[1],);+/**+ * Return all hidden collections that are present in our local+ * database.+ */+export const savedHiddenCollections = (): Promise<Collection[]> =>+ savedCollections().then(+ (cs) => splitByPredicate(cs, isHiddenCollection)[0],+ );+/*** Return a map of the (user-facing) collection name, indexed by collection ID.*/diff --git a/web/packages/new/photos/services/dedup.ts b/web/packages/new/photos/services/dedup.tsindex 0bf4f1c9ea..7991f77825 100644--- a/web/packages/new/photos/services/dedup.ts+++ b/web/packages/new/photos/services/dedup.ts@@ -7,9 +7,10 @@ import {addToCollection,createCollectionNameByID,moveToTrash,+ savedNormalCollections,} from "./collection";import { getLocalCollections } from "./collections";-import { getLocalFiles } from "./files";+import { savedCollectionFiles } from "./photos-fdb";import { syncCollectionAndFiles } from "./sync";/**@@ -105,21 +106,18 @@ export const deduceDuplicates = async () => {// Find all non-hidden collections owned by the user, and also use that to// keep a map of their names (we'll attach this info to the result later).- const nonHiddenCollections = await getLocalCollections("normal");- const nonHiddenOwnedCollections = nonHiddenCollections.filter(+ const normalCollections = await savedNormalCollections();+ const normalOwnedCollections = normalCollections.filter(({ owner }) => owner.id == userID,);const allowedCollectionIDs = new Set(- nonHiddenOwnedCollections.map(({ id }) => id),- );- const collectionNameByID = createCollectionNameByID(- nonHiddenOwnedCollections,+ normalOwnedCollections.map(({ id }) => id),);+ const collectionNameByID = createCollectionNameByID(normalOwnedCollections);- // Find all non-hidden collection files owned by the user that are in a- // non-hidden owned collection.- const nonHiddenCollectionFiles = await getLocalFiles("normal");- const filteredCollectionFiles = nonHiddenCollectionFiles.filter((f) =>+ // Find all eligible collection files.+ const collectionFiles = await savedCollectionFiles();+ const filteredCollectionFiles = collectionFiles.filter((f) =>allowedCollectionIDs.has(f.collectionID),);diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.tsindex 35d53a5a46..2202edf92b 100644--- a/web/packages/new/photos/services/ml/people.ts+++ b/web/packages/new/photos/services/ml/people.ts@@ -3,7 +3,8 @@ import log from "ente-base/log";import type { EnteFile } from "ente-media/file";import { fileCreationTime } from "ente-media/file-metadata";import { randomSample } from "ente-utils/array";-import { savedNormalFiles } from "../photos-fdb";+import { savedHiddenCollections } from "../collection";+import { savedCollectionFiles } from "../photos-fdb";import {savedCGroups,updateOrCreateUserEntities,@@ -213,8 +214,7 @@ export interface PeopleState {* construct an in-memory list of {@link Person}s on which the UI will operate.*/export const reconstructPeopleState = async (): Promise<PeopleState> => {- const files = await savedNormalFiles();- const fileByID = new Map(files.map((f) => [f.id, f]));+ const fileByID = await savedNormalFileByFileID();// "Person face"s are faces annotated with their corresponding local files.//@@ -379,6 +379,22 @@ export const reconstructPeopleState = async (): Promise<PeopleState> => {return { people, visiblePeople, personByFaceID };};+/**+ * Read the saved data directly from files DB, and construct a map from fileID+ * to file for all normal (non-hidden) files.+ */+const savedNormalFileByFileID = async () => {+ const hiddenCollections = await savedHiddenCollections();+ const hiddenCollectionIDs = new Set(hiddenCollections.map((c) => c.id));++ const collectionFiles = await savedCollectionFiles();+ const normalCollectionFiles = collectionFiles.filter(+ (f) => !hiddenCollectionIDs.has(f.collectionID),+ );++ return new Map(normalCollectionFiles.map((f) => [f.id, f]));+};+/*** Older versions of the mobile app set the avatarFileID as the avatarFaceID.* Use the format of the string to detect such cases, and as a workaround,@@ -520,8 +536,7 @@ export const _suggestionsAndChoicesForPerson = async (// Annotate the clusters with the information that the UI needs to show its// preview faces.- const files = await savedNormalFiles();- const fileByID = new Map(files.map((f) => [f.id, f]));+ const fileByID = await savedNormalFileByFileID();const toPreviewable = (cluster: FaceCluster) => {const previewFaces: PreviewableFace[] = [];diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.tsindex d06447638b..c11f06590b 100644--- a/web/packages/new/photos/services/search/index.ts+++ b/web/packages/new/photos/services/search/index.ts@@ -2,6 +2,8 @@ import log from "ente-base/log";import { ensureMasterKeyFromSession } from "ente-base/session";import { ComlinkWorker } from "ente-base/worker/comlink-worker";import { uniqueFilesByID } from "ente-gallery/utils/files";+import type { Collection } from "ente-media/collection";+import type { EnteFile } from "ente-media/file";import { FileType } from "ente-media/file-type";import i18n, { t } from "i18next";import { clipMatches, isMLEnabled, isMLSupported } from "../ml";@@ -10,7 +12,6 @@ import type {LabelledFileType,LabelledSearchDateComponents,LocalizedSearchData,- SearchCollectionsAndFiles,SearchSuggestion,} from "./types";import type { SearchWorker } from "./worker";@@ -53,19 +54,27 @@ export const searchDataSync = () =>worker().then((w) => ensureMasterKeyFromSession().then((k) => w.sync(k)));/**- * Set the collections and files over which we should search.+ * Update the collections and files over which we should search.*/-export const setSearchCollectionsAndFiles = ({- collections,- files,-}: Omit<SearchCollectionsAndFiles, "collectionFiles">) =>+export const updateSearchCollectionsAndFiles = (+ collections: Collection[],+ hiddenCollectionIDs: Set<number>,+ collectionFiles: EnteFile[],+) => {+ const normalCollections = collections.filter(+ (c) => !hiddenCollectionIDs.has(c.id),+ );+ const normalCollectionFiles = collectionFiles.filter(+ (f) => !hiddenCollectionIDs.has(f.collectionID),+ );void worker().then((w) =>w.setCollectionsAndFiles({- collections: collections,- files: uniqueFilesByID(files),- collectionFiles: files,+ collections: normalCollections,+ files: uniqueFilesByID(normalCollectionFiles),+ collectionFiles: normalCollectionFiles,}),);+};/*** Set the (named) people that we should search across.