π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(gallery):adding-favoring-shared-album-files-from-gallery
Aswin Asokc49696b0e898
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex 45cfbe8acf..8bb2b25a49 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -58,7 +58,7 @@ import { useSaveGroups } from "ente-gallery/components/utils/save-groups";import { type FileViewerInitialSidebar } from "ente-gallery/components/viewer/FileViewer";import { CollectionSubType, type Collection } from "ente-media/collection";import { type EnteFile } from "ente-media/file";-import { ItemVisibility } from "ente-media/file-metadata";+import { ItemVisibility, metadataHash } from "ente-media/file-metadata";import { AssignPersonDialog } from "ente-new/photos/components/AssignPersonDialog";import {CollectionSelector,@@ -92,7 +92,10 @@ import {useGalleryReducer,type GalleryBarMode,} from "ente-new/photos/components/gallery/reducer";-import { notifyOthersFilesDialogAttributes } from "ente-new/photos/components/utils/dialog-attributes";+import {+ notifyOthersFilesDialogAttributes,+ notifyUnsupportedSharedFavoritesDialogAttributes,+} from "ente-new/photos/components/utils/dialog-attributes";import { useIsOffline } from "ente-new/photos/components/utils/use-is-offline";import {usePeopleStateSnapshot,@@ -1052,6 +1055,67 @@ const Page: React.FC = () => {[createOnSelectForCollectionOp, remotePull],);+ const handleFavoriteFileOp = async (+ op: Extract<FileOp, "favorite" | "unfavorite">,+ selectedFiles: EnteFile[],+ ) => {+ const filesWithTargetState =+ op == "unfavorite"+ ? selectedFiles.filter((file) => favoriteFileIDs.has(file.id))+ : selectedFiles;+ const filesToProcess: EnteFile[] = [];+ let skippedUnsupportedSharedFile = false;++ for (const file of filesWithTargetState) {+ if (file.ownerID == user!.id || metadataHash(file.metadata)) {+ filesToProcess.push(file);+ } else {+ skippedUnsupportedSharedFile = true;+ }+ }++ if (!filesToProcess.length) {+ return { processed: false, skippedUnsupportedSharedFile };+ }++ const isFavorite = op == "favorite";+ const previousFavoriteByFileID = new Map(+ filesToProcess.map((file) => [+ file.id,+ favoriteFileIDs.has(file.id),+ ]),+ );++ for (const file of filesToProcess) {+ dispatch({ type: "addPendingFavoriteUpdate", fileID: file.id });+ dispatch({ type: "unsyncedFavoriteUpdate", file, isFavorite });+ }++ try {+ const action = isFavorite+ ? addToFavoritesCollection+ : removeFromFavoritesCollection;+ await action(filesToProcess);+ return { processed: true, skippedUnsupportedSharedFile };+ } catch (e) {+ for (const file of filesToProcess) {+ dispatch({+ type: "unsyncedFavoriteUpdate",+ file,+ isFavorite: previousFavoriteByFileID.get(file.id)!,+ });+ }+ throw e;+ } finally {+ for (const file of filesToProcess) {+ dispatch({+ type: "removePendingFavoriteUpdate",+ fileID: file.id,+ });+ }+ }+ };+const createFileOpHandler =(op: FileOp, options?: { suppressSelectionBar?: boolean }) => () => {void (async () => {@@ -1108,6 +1172,21 @@ const Page: React.FC = () => {): filteredFiles;const selectedFiles = getSelectedFiles(selected, opFiles);+ if (op == "favorite" || op == "unfavorite") {+ const { processed, skippedUnsupportedSharedFile } =+ await handleFavoriteFileOp(op, selectedFiles);+ clearSelection();+ if (processed) {+ await remotePull({ silent: true });+ }+ if (skippedUnsupportedSharedFile) {+ showMiniDialog(+ notifyUnsupportedSharedFavoritesDialogAttributes(),+ );+ }+ return;+ }+const ownedSelectedFiles =op == "download"? selectedFiles@@ -1115,16 +1194,10 @@ const Page: React.FC = () => {// There'll be a user if files are being selected.(file) => file.ownerID == user!.id,);- const toProcessFiles =- op == "unfavorite"- ? ownedSelectedFiles.filter((file) =>- favoriteFileIDs.has(file.id),- )- : ownedSelectedFiles;- if (toProcessFiles.length > 0) {+ if (ownedSelectedFiles.length > 0) {await performFileOp(op,- toProcessFiles,+ ownedSelectedFiles,onAddSaveGroup,handleMarkTempDeleted,() => dispatch({ type: "clearTempDeleted" }),diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.jsonindex c57dc9c8d7..67d5cf2e3f 100644--- a/web/packages/base/locales/en-US/translation.json+++ b/web/packages/base/locales/en-US/translation.json@@ -805,6 +805,7 @@"shared_favorites": "Shared favorites","added_by_name": "Added by {{name}}","unowned_files_not_processed": "Files added by other users were not processed",+ "unsupported_shared_favorites_not_processed": "Some shared files could not be updated because they are missing file metadata.","custom_domains": "Custom domains","custom_domains_desc": "Use your own domain when sharing","link_your_domain": "Link your domain",diff --git a/web/packages/new/photos/components/SelectedFileOptions.tsx b/web/packages/new/photos/components/SelectedFileOptions.tsxindex b272fa5ede..cf75881f4a 100644--- a/web/packages/new/photos/components/SelectedFileOptions.tsx+++ b/web/packages/new/photos/components/SelectedFileOptions.tsx@@ -429,6 +429,7 @@ export const SelectedFileOptions: React.FC<SelectedFileOptionsProps> = ({{selectedOwnFileCount > 0 && (<SendLinkButton onClick={handleSendLink} />)}+ {favoriteActionButton}<DownloadButton onClick={handleDownload} />{!!onShowAssignPersonDialog && (<AddPersonButtondiff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.tsindex 7011e5c64c..022c71aed0 100644--- a/web/packages/new/photos/components/gallery/reducer.ts+++ b/web/packages/new/photos/components/gallery/reducer.ts@@ -956,16 +956,27 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (}case "clearUnsyncedState": {+ const collectionFiles = state.lastSyncedCollectionFiles;+ const syncedFavoriteFileIDs = deriveFavoriteFileIDs(+ state.user!,+ state.collections,+ collectionFiles,+ new Map(),+ );const unsyncedFavoriteUpdates: GalleryState["unsyncedFavoriteUpdates"] =- new Map();+ preserveUnreflectedFavoriteUpdates(+ state.user!,+ collectionFiles,+ syncedFavoriteFileIDs,+ state.unsyncedFavoriteUpdates,+ );const favoriteFileIDs = deriveFavoriteFileIDs(state.user!,state.collections,- state.collectionFiles,+ collectionFiles,unsyncedFavoriteUpdates,);- const collectionFiles = state.lastSyncedCollectionFiles;const unsyncedPrivateMagicMetadataUpdates: GalleryState["unsyncedPrivateMagicMetadataUpdates"] =new Map();@@ -979,7 +990,7 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (pendingFavoriteUpdates: new Set(),pendingVisibilityUpdates: new Set(),unsyncedPrivateMagicMetadataUpdates,- unsyncedFavoriteUpdates: new Map(),+ unsyncedFavoriteUpdates,},collectionFiles,),@@ -1355,6 +1366,39 @@ const deriveFavoriteFileIDs = (return favoriteFileIDs;};+const preserveUnreflectedFavoriteUpdates = (+ user: LocalUser,+ collectionFiles: GalleryState["collectionFiles"],+ syncedFavoriteFileIDs: GalleryState["favoriteFileIDs"],+ unsyncedFavoriteUpdates: GalleryState["unsyncedFavoriteUpdates"],+) => {+ const preservedUpdates: GalleryState["unsyncedFavoriteUpdates"] = new Map();++ for (const [key, update] of unsyncedFavoriteUpdates.entries()) {+ const updatedFileIDs = update.fileHashAndTypeKey+ ? collectionFiles+ .filter(+ (file) =>+ file.ownerID != user.id &&+ favoriteFileHashAndTypeKey(file) ==+ update.fileHashAndTypeKey,+ )+ .map((file) => file.id)+ : [update.fileID];++ if (+ updatedFileIDs.some(+ (fileID) =>+ syncedFavoriteFileIDs.has(fileID) != update.isFavorite,+ )+ ) {+ preservedUpdates.set(key, update);+ }+ }++ return preservedUpdates;+};+/*** Earlier the UnsyncedFavoriteUpdate was just an fileID* because we only had the option to favorite the owner files.diff --git a/web/packages/new/photos/components/utils/dialog-attributes.tsx b/web/packages/new/photos/components/utils/dialog-attributes.tsxindex c01c4cd1db..95d7532849 100644--- a/web/packages/new/photos/components/utils/dialog-attributes.tsx+++ b/web/packages/new/photos/components/utils/dialog-attributes.tsx@@ -11,3 +11,15 @@ export const notifyOthersFilesDialogAttributes = () => ({message: t("unowned_files_not_processed"),cancel: t("ok"),});++/**+ * Create attributes for a {@link MiniDialog} notifying the user that some+ * shared files could not be favorited because they do not have the metadata+ * needed to match them with a user-owned favorite copy.+ */+export const notifyUnsupportedSharedFavoritesDialogAttributes = () => ({+ title: t("note"),+ icon: <InfoOutlinedIcon />,+ message: t("unsupported_shared_favorites_not_processed"),+ cancel: t("ok"),+});diff --git a/web/packages/new/photos/utils/file-actions.ts b/web/packages/new/photos/utils/file-actions.tsindex b070360c9d..7e0a825aa3 100644--- a/web/packages/new/photos/utils/file-actions.ts+++ b/web/packages/new/photos/utils/file-actions.ts@@ -143,7 +143,7 @@ function getBaseActions(// Shared incoming actionsif (collectionSummary?.attributes.has("sharedIncoming")) {- return ["download", "removeFromAlbum"];+ return ["favorite", "download", "removeFromAlbum"];}// Hidden albums mode actions