π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Rename
Manav Rathi6e045affa4e5
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex 03fb49fa75..46d2241565 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -169,6 +169,8 @@ export interface GalleryState {hiddenFileIDs: Set<number>;/*** File IDs of all the files that the user has marked as a favorite.+ *+ * Includes the effects of {@link unsyncedFavoriteUpdates}.*/favoriteFileIDs: Set<number>;/**@@ -213,29 +215,30 @@ export interface GalleryState {tempHiddenFileIDs: Set<number>;/*** Updates to the favorite status of files that have just been toggled by- * the user in the file viewer.+ * the user in the file viewer, but whose effects on remote have not been+ * yet synced back to our local DB.** Each entry is from a file ID to `true` (if that file should be considered* as part of the favorites) or `false` (if that file should not be* considered as part of the favorites).** When the user marks a file as a favorite (or unmarks it as a favorite),- * we add the override to this map so that we can give them immediate- * feedback in the UI.+ * we add an entry in this map so that we can give them immediate feedback+ * in the UI.** The request to update the favorite status on remote proceeds in parallel.- * If that request fails, we remove the override from here.+ * If that request fails, we remove the entry from here.** If the remote request succeeds, we still need to sync the files and* collections in our local DB with the remote state, but that happens in a* batch when the user exits the viewer. So until that point, these updates- * remain in this overrides map.+ * remain in this in-flight updates map.** Once the remote file + collection sync completes, we can clear this map- * since now just the {@link favoriteFileIDs} derived from our local files- * would reflect the correct state on remote too.+ * since just deriving {@link favoriteFileIDs} from our local files would+ * reflect the correct state on remote too.*/- favoriteFileIDOverrides: Map<number, boolean>;+ unsyncedFavoriteUpdates: Map<number, boolean>;/*--< State that underlies transient UI state >--*/@@ -360,8 +363,8 @@ export type GalleryAction =| { type: "clearTempDeleted" }| { type: "markTempHidden"; files: EnteFile[] }| { type: "clearTempHidden" }- | { type: "addFavoriteOverride"; fileID: number; isFavorite: boolean }- | { type: "clearFavoriteOverrides" }+ | { type: "addUnsyncedFavoriteUpdate"; fileID: number; isFavorite: boolean }+ | { type: "clearUnsyncedFavoriteUpdates" }| { type: "showAll" }| { type: "showHidden" }| { type: "showAlbums" }@@ -395,7 +398,7 @@ const initialGalleryState: GalleryState = {hiddenCollectionSummaries: new Map(),tempDeletedFileIDs: new Set(),tempHiddenFileIDs: new Set(),- favoriteFileIDOverrides: new Map(),+ unsyncedFavoriteUpdates: new Map(),selectedCollectionSummaryID: undefined,selectedPersonID: undefined,extraVisiblePerson: undefined,@@ -443,7 +446,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (favoriteFileIDs: deriveFavoriteFileIDs(collections,action.files,- state.favoriteFileIDOverrides,+ state.unsyncedFavoriteUpdates,),allCollectionNameByID: createCollectionNameByID(action.allCollections,@@ -495,7 +498,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (favoriteFileIDs: deriveFavoriteFileIDs(collections,state.files,- state.favoriteFileIDOverrides,+ state.unsyncedFavoriteUpdates,),allCollectionNameByID: createCollectionNameByID(collections.concat(state.hiddenCollections),@@ -559,7 +562,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (favoriteFileIDs: deriveFavoriteFileIDs(collections,state.files,- state.favoriteFileIDOverrides,+ state.unsyncedFavoriteUpdates,),allCollectionNameByID: createCollectionNameByID(collections.concat(hiddenCollections),@@ -585,7 +588,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (favoriteFileIDs: deriveFavoriteFileIDs(state.collections,files,- state.favoriteFileIDOverrides,+ state.unsyncedFavoriteUpdates,),fileCollectionIDs: createFileCollectionIDs(action.files),collectionSummaries: deriveCollectionSummaries(@@ -616,7 +619,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (favoriteFileIDs: deriveFavoriteFileIDs(state.collections,files,- state.favoriteFileIDOverrides,+ state.unsyncedFavoriteUpdates,),fileCollectionIDs: createFileCollectionIDs(action.files),collectionSummaries: deriveCollectionSummaries(@@ -643,7 +646,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (favoriteFileIDs: deriveFavoriteFileIDs(state.collections,files,- state.favoriteFileIDOverrides,+ state.unsyncedFavoriteUpdates,),fileCollectionIDs: createFileCollectionIDs(files),// TODO: Consider batching this instead of doing it per file@@ -765,36 +768,36 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (tempHiddenFileIDs: new Set(),});- case "addFavoriteOverride": {- const favoriteFileIDOverrides = new Map(- state.favoriteFileIDOverrides,+ case "addUnsyncedFavoriteUpdate": {+ const unsyncedFavoriteUpdates = new Map(+ state.unsyncedFavoriteUpdates,);- favoriteFileIDOverrides.set(action.fileID, action.isFavorite);- // stateByUpdatingFilteredFiles doesn't currently depend on- // favorite fileIDs or overrides, so skipping it.+ unsyncedFavoriteUpdates.set(action.fileID, action.isFavorite);+ // Skipping a call to stateByUpdatingFilteredFiles since it+ // currently doesn't depend on favorites.return {...state,favoriteFileIDs: deriveFavoriteFileIDs(state.collections,state.files,- favoriteFileIDOverrides,+ unsyncedFavoriteUpdates,),- favoriteFileIDOverrides,+ unsyncedFavoriteUpdates,};}- case "clearFavoriteOverrides": {- const favoriteFileIDOverrides = new Map<number, boolean>();- // stateByUpdatingFilteredFiles doesn't currently depend on- // favorite fileIDs or overrides, so skipping it.+ case "clearUnsyncedFavoriteUpdates": {+ const unsyncedFavoriteUpdates = new Map<number, boolean>();+ // Skipping a call to stateByUpdatingFilteredFiles since it+ // currently doesn't depend on favorites.return {...state,favoriteFileIDs: deriveFavoriteFileIDs(state.collections,state.files,- favoriteFileIDOverrides,+ unsyncedFavoriteUpdates,),- favoriteFileIDOverrides,+ unsyncedFavoriteUpdates,};}@@ -993,7 +996,7 @@ const deriveHiddenFileIDs = (hiddenFiles: EnteFile[]) =>const deriveFavoriteFileIDs = (collections: Collection[],files: EnteFile[],- favoriteFileIDOverrides: GalleryState["favoriteFileIDOverrides"],+ unsyncedFavoriteUpdates: GalleryState["unsyncedFavoriteUpdates"],): Set<number> => {let favoriteFileIDs = new Set<number>();for (const collection of collections) {@@ -1006,7 +1009,7 @@ const deriveFavoriteFileIDs = (break;}}- for (const [fileID, isFavorite] of favoriteFileIDOverrides.entries()) {+ for (const [fileID, isFavorite] of unsyncedFavoriteUpdates.entries()) {if (isFavorite) favoriteFileIDs.add(fileID);else favoriteFileIDs.delete(fileID);}