π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add join album flow for public album reactions and fix anon comment delete
Anand Baburajaneb4bafb0e482
diff --git a/web/apps/photos/src/components/FileListWithViewer.tsx b/web/apps/photos/src/components/FileListWithViewer.tsxindex 7492c0d223..596cd8546e 100644--- a/web/apps/photos/src/components/FileListWithViewer.tsx+++ b/web/apps/photos/src/components/FileListWithViewer.tsx@@ -127,6 +127,7 @@ export type FileListWithViewerProps = {| "onSelectPerson"| "publicAlbumsCredentials"| "collectionKey"+ | "onJoinAlbum">;/**@@ -180,6 +181,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({onPendingNavigationConsumed,publicAlbumsCredentials,collectionKey,+ onJoinAlbum,}) => {const [openFileViewer, setOpenFileViewer] = useState(false);const [currentIndex, setCurrentIndex] = useState(0);@@ -378,6 +380,7 @@ export const FileListWithViewer: React.FC<FileListWithViewerProps> = ({onSelectPerson,publicAlbumsCredentials,collectionKey,+ onJoinAlbum,}}onTriggerRemotePull={handleTriggerRemotePull}onDownload={handleDownload}diff --git a/web/apps/photos/src/components/TripLayout/index.tsx b/web/apps/photos/src/components/TripLayout/index.tsxindex 4d31451ef8..54e457f817 100644--- a/web/apps/photos/src/components/TripLayout/index.tsx+++ b/web/apps/photos/src/components/TripLayout/index.tsx@@ -6,6 +6,7 @@ import { FileViewer } from "ente-gallery/components/viewer/FileViewer";import { downloadAndSaveCollectionFiles } from "ente-gallery/services/save";import { type Collection } from "ente-media/collection";import { type EnteFile } from "ente-media/file";+import { useJoinAlbum } from "hooks/useJoinAlbum";import { useEffect, useRef, useState } from "react";// Import extracted components@@ -79,6 +80,14 @@ export const TripLayout: React.FC<TripLayoutProps> = ({handleTriggerRemotePull,} = useFileViewer({ files, onSetOpenFileViewer, onRemotePull });+ // Join album hook for file viewer's public like modal+ const { handleJoinAlbum } = useJoinAlbum({+ publicCollection: collection,+ accessToken,+ collectionKey,+ credentials,+ });+// Download all files functionalityconst downloadAllFiles = () => {if (!collection) return;@@ -516,6 +525,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({}}publicAlbumsCredentials={credentials?.current}collectionKey={collectionKey}+ onJoinAlbum={handleJoinAlbum}/>{/* Download progress notifications */}diff --git a/web/apps/photos/src/pages/shared-albums.tsx b/web/apps/photos/src/pages/shared-albums.tsxindex 6bcfd48d33..7c6ee455b4 100644--- a/web/apps/photos/src/pages/shared-albums.tsx+++ b/web/apps/photos/src/pages/shared-albums.tsx@@ -369,6 +369,14 @@ export default function PublicCollectionGallery() {setTimeout(hideLoadingBar, 0);}, [showLoadingBar, hideLoadingBar]);+ // Join album handler for use in file viewer's public like modal+ const { handleJoinAlbum } = useJoinAlbum({+ publicCollection,+ accessToken: credentials.current?.accessToken,+ collectionKey: collectionKey.current,+ credentials,+ });+const handleSubmitPassword: SingleInputFormProps["onSubmit"] = async (password,setFieldError,@@ -587,6 +595,7 @@ export default function PublicCollectionGallery() {onAddSaveGroup={onAddSaveGroup}publicAlbumsCredentials={credentials.current}collectionKey={collectionKey.current}+ onJoinAlbum={handleJoinAlbum}/></>)}diff --git a/web/packages/gallery/components/viewer/AddNameModal.tsx b/web/packages/gallery/components/viewer/AddNameModal.tsxindex 78b81afbaa..9e68dbf122 100644--- a/web/packages/gallery/components/viewer/AddNameModal.tsx+++ b/web/packages/gallery/components/viewer/AddNameModal.tsx@@ -167,6 +167,10 @@ export interface AddNameModalProps extends ModalVisibilityProps {* Defaults to 'like'.*/actionType?: "like" | "comment";+ /**+ * Called after the modal's exit animation completes.+ */+ onExited?: () => void;}/**@@ -177,6 +181,7 @@ export const AddNameModal: React.FC<AddNameModalProps> = ({onClose,onSubmit,actionType = "like",+ onExited,}) => {const [name, setName] = useState("");const isComment = actionType === "comment";@@ -194,7 +199,11 @@ export const AddNameModal: React.FC<AddNameModalProps> = ({};return (- <StyledDialog open={open} onClose={handleClose}>+ <StyledDialog+ open={open}+ onClose={handleClose}+ TransitionProps={{ onExited }}+ ><DialogWrapper><CloseButton onClick={handleClose}><CloseIcon sx={{ fontSize: 20 }} />@@ -233,9 +242,7 @@ export const AddNameModal: React.FC<AddNameModalProps> = ({onClick={handleSubmit}hasName={!!name.trim()}>- {isComment- ? "Set name and comment"- : "Set name and like"}+ {isComment ? "Set name" : "Set name and like"}</SubmitButton></ContentContainer></DialogWrapper>diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsxindex 5e64dc2ec0..1a709046d1 100644--- a/web/packages/gallery/components/viewer/CommentsSidebar.tsx+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx@@ -18,7 +18,10 @@ import log from "ente-base/log";import { downloadManager } from "ente-gallery/services/download";import { getAvatarColor } from "ente-gallery/utils/avatar-colors";import type { EnteFile } from "ente-media/file";-import { addPublicComment } from "ente-new/albums/services/public-comment";+import {+ addPublicComment,+ deletePublicComment,+} from "ente-new/albums/services/public-comment";import {addPublicCommentReaction,createAnonIdentity,@@ -445,6 +448,11 @@ export interface CommentsSidebarProps extends ModalVisibilityProps {* Map of anonymous user ID to decrypted user name.*/anonUserNames?: Map<string, string>;+ /**+ * Called when user clicks "Join album to like" in the public like modal.+ * Should trigger the join album flow (with mobile deep link fallback).+ */+ onJoinAlbum?: () => void;}/**@@ -475,6 +483,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({publicAlbumsCredentials,collectionKey,anonUserNames,+ onJoinAlbum,}) => {const [commentText, setCommentText] = useState("");const [replyingTo, setReplyingTo] = useState<Comment | null>(null);@@ -486,11 +495,12 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({const [showPublicCommentModal, setShowPublicCommentModal] = useState(false);const [showAddNameModal, setShowAddNameModal] = useState(false);const [showPublicLikeModal, setShowPublicLikeModal] = useState(false);- const [pendingComment, setPendingComment] = useState("");const [pendingCommentLike, setPendingCommentLike] =useState<Comment | null>(null);/** Tracks whether the AddNameModal was triggered by a comment like action */const [addNameForCommentLike, setAddNameForCommentLike] = useState(false);+ /** Tracks whether the user has set up their anonymous identity for commenting */+ const [hasAnonIdentity, setHasAnonIdentity] = useState(false);const [loading, setLoading] = useState(false);const [sending, setSending] = useState(false);const inputRef = useRef<HTMLInputElement>(null);@@ -720,9 +730,22 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({const canDeleteComment = useCallback((comment: Comment): boolean => {// Comment author can always delete their own comment+ // For logged-in users, check userIDif (comment.userID === currentUserID) {return true;}+ // For anonymous users, check anonUserID+ if (selectedCollectionInfo) {+ const storedIdentity = getStoredAnonIdentity(+ selectedCollectionInfo.id,+ );+ if (+ storedIdentity &&+ comment.anonUserID === storedIdentity.anonUserID+ ) {+ return true;+ }+ }// Check if user is owner or admin of the selected collectionconst collectionID = selectedCollectionInfo?.id;@@ -859,6 +882,16 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}}, [hasCollectionContext, selectedCollectionID, commentsByCollection]);+ // Update hasAnonIdentity when collection changes (for public albums)+ useEffect(() => {+ if (isPublicAlbum && selectedCollectionInfo) {+ const storedIdentity = getStoredAnonIdentity(+ selectedCollectionInfo.id,+ );+ setHasAnonIdentity(!!storedIdentity);+ }+ }, [isPublicAlbum, selectedCollectionInfo]);+// Fetch thumbnails for each collection's cover fileuseEffect(() => {if (!open || collectionsInfo.length === 0) {@@ -952,8 +985,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({// User already has identity, send directlyawait sendPublicComment(commentText.trim());} else {- // Show modal to choose anonymous or sign in- setPendingComment(commentText.trim());+ // Show modal to choose anonymous or join albumsetShowPublicCommentModal(true);}return;@@ -1091,10 +1123,9 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({setShowAddNameModal(true);};- const handleSignInAndComment = () => {+ const handleJoinAlbumToComment = () => {setShowPublicCommentModal(false);- // Redirect to web.ente.io for sign in- window.open("https://web.ente.io", "_blank");+ onJoinAlbum?.();};const handleLikeAnonymously = () => {@@ -1103,11 +1134,10 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({setShowAddNameModal(true);};- const handleSignInAndLike = () => {+ const handleJoinAlbumToLike = () => {setShowPublicLikeModal(false);setPendingCommentLike(null);- // Redirect to web.ente.io for sign in- window.open("https://web.ente.io", "_blank");+ onJoinAlbum?.();};const handleNameSubmit = async (name: string) => {@@ -1118,7 +1148,6 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({!publicAlbumsCredentials ||!collectionKey) {- setPendingComment("");setPendingCommentLike(null);setAddNameForCommentLike(false);return;@@ -1170,6 +1199,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return next;});onCommentReactionAdded?.(newReaction);+ setHasAnonIdentity(true);} catch (e) {log.error("Failed to create identity and like comment", e);} finally {@@ -1179,76 +1209,40 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({return;}- // Handle comment action- if (!file) {- setPendingComment("");- return;- }-- setSending(true);+ // Handle comment action - just create identity, don't send comment+ // User will type and send the comment afterwardstry {- // Create anonymous identity with the provided name- const identity = await createAnonIdentity(+ await createAnonIdentity(publicAlbumsCredentials,collectionID,name,collectionKey,);-- // Now post the comment using the new identity- const newCommentID = await addPublicComment(- publicAlbumsCredentials,- collectionID,- file.id,- pendingComment,- collectionKey,- replyingTo?.id,- identity,- );-- // Add the new comment to local state- const newComment: Comment = {- id: newCommentID,- collectionID,- fileID: file.id,- text: pendingComment,- parentCommentID: replyingTo?.id,- isDeleted: false,- userID: 0, // Anonymous user- anonUserID: identity.anonUserID,- createdAt: Date.now() * 1000, // Microseconds to match server format- updatedAt: Date.now() * 1000,- };- setComments((prev) => [...prev, newComment]);- setCommentsByCollection((prev) => {- const next = new Map(prev);- const existing = next.get(collectionID) ?? [];- next.set(collectionID, [...existing, newComment]);- return next;- });-- setCommentText("");- setReplyingTo(null);-- // Notify parent to update its comments state- onCommentAdded?.(newComment);-- // Scroll to bottom after adding comment- setTimeout(() => {- if (commentsContainerRef.current) {- commentsContainerRef.current.scrollTop = 0;- }- }, 0);+ // Identity created, user can now type and send comments+ setHasAnonIdentity(true);} catch (e) {- log.error("Failed to create identity and add comment", e);- } finally {- setSending(false);- setPendingComment("");+ log.error("Failed to create anonymous identity", e);}};+ // Check if user needs to set up identity before commenting (public album without identity)+ const needsIdentityToComment =+ isPublicAlbum && selectedCollectionInfo && !hasAnonIdentity;+const handleReply = (commentToReply: Comment) => {setReplyingTo(commentToReply);++ // For public albums, check if we have an identity+ if (needsIdentityToComment) {+ setShowPublicCommentModal(true);+ }+ };++ // Handler for clicking the comment input area on public albums+ const handleInputClick = () => {+ if (needsIdentityToComment) {+ setShowPublicCommentModal(true);+ }};const handleCollectionSelect = (collectionID: number) => {@@ -1447,7 +1441,27 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({break;case "delete":try {- await deleteComment(targetComment.id);+ // Use public API for anonymous users in public albums+ if (isPublicAlbum && publicAlbumsCredentials) {+ const storedIdentity = selectedCollectionInfo+ ? getStoredAnonIdentity(selectedCollectionInfo.id)+ : undefined;+ if (storedIdentity) {+ await deletePublicComment(+ publicAlbumsCredentials,+ targetComment.collectionID,+ targetComment.id,+ storedIdentity,+ );+ } else {+ log.error(+ "No stored identity for public comment delete",+ );+ return;+ }+ } else {+ await deleteComment(targetComment.id);+ }// Update local statesetComments((prev) =>@@ -1759,7 +1773,9 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({!showOwnTimestamp &&commentIsOwn &&!!prevComment &&- prevComment.userID !== currentUserID+ prevComment.userID !== currentUserID &&+ prevComment.anonUserID !==+ storedIdentity?.anonUserID}isLastOwn={isLastInSequence}isHighlighted={@@ -1980,12 +1996,36 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({</IconButton></ReplyingToBar>)}- <InputWrapper>+ <InputWrapper+ onClick={handleInputClick}+ sx={+ needsIdentityToComment+ ? (theme) => ({+ cursor: "pointer",+ borderRadius: "20px",+ overflow: "hidden",+ transition: "background-color 0.15s ease",+ "&:hover": {+ backgroundColor:+ "rgba(0, 0, 0, 0.04)",+ ...theme.applyStyles("dark", {+ backgroundColor:+ "rgba(255, 255, 255, 0.08)",+ }),+ },+ "& .MuiInputBase-root, & .MuiInputBase-input":+ {+ cursor: "pointer",+ },+ })+ : undefined+ }+ ><StyledTextFieldfullWidthmultilineminRows={1}- autoFocus+ autoFocus={!needsIdentityToComment}placeholder="Say something nice!"variant="standard"value={commentText}@@ -2011,7 +2051,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({open={showPublicCommentModal}onClose={() => setShowPublicCommentModal(false)}onCommentAnonymously={handleCommentAnonymously}- onSignInAndComment={handleSignInAndComment}+ onJoinAlbumToComment={handleJoinAlbumToComment}/><PublicLikeModalopen={showPublicLikeModal}@@ -2020,14 +2060,17 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({setPendingCommentLike(null);}}onLikeAnonymously={handleLikeAnonymously}- onSignInAndLike={handleSignInAndLike}+ onJoinAlbumToLike={handleJoinAlbumToLike}/><AddNameModalopen={showAddNameModal}onClose={() => {setShowAddNameModal(false);- setPendingComment("");setPendingCommentLike(null);+ }}+ onExited={() => {+ // Reset actionType after modal has fully closed to avoid+ // visual glitch of icon changing during exit animationsetAddNameForCommentLike(false);}}onSubmit={handleNameSubmit}diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex d06b46faa1..871074fb96 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -340,6 +340,11 @@ export type FileViewerProps = ModalVisibilityProps & {* Required when viewing a public album (no logged in user).*/collectionKey?: string;+ /**+ * Called when user clicks "Join album to like" in the public like modal.+ * Should trigger the join album flow (with mobile deep link fallback).+ */+ onJoinAlbum?: () => void;} & Pick<FileInfoProps,"collectionNameByID" | "onSelectCollection" | "onSelectPerson"@@ -381,6 +386,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({activeCollectionID,publicAlbumsCredentials,collectionKey,+ onJoinAlbum,}) => {const { onGenericError } = useBaseContext();@@ -1185,9 +1191,10 @@ export const FileViewer: React.FC<FileViewerProps> = ({setOpenAddNameModal(true);}, []);- const handleSignInAndLike = useCallback(() => {- window.open("https://web.ente.io", "_blank");- }, []);+ const handleJoinAlbumToLike = useCallback(() => {+ setOpenPublicLikeModal(false);+ onJoinAlbum?.();+ }, [onJoinAlbum]);const handleAddNameModalClose = useCallback(() => setOpenAddNameModal(false),@@ -2291,6 +2298,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({publicAlbumsCredentials={publicAlbumsCredentials}collectionKey={collectionKey}anonUserNames={anonUserNames}+ onJoinAlbum={onJoinAlbum}/><LikesSidebaropen={openLikes}@@ -2318,7 +2326,7 @@ export const FileViewer: React.FC<FileViewerProps> = ({open={openPublicLikeModal}onClose={handlePublicLikeModalClose}onLikeAnonymously={handleLikeAnonymously}- onSignInAndLike={handleSignInAndLike}+ onJoinAlbumToLike={handleJoinAlbumToLike}/><AddNameModalopen={openAddNameModal}diff --git a/web/packages/gallery/components/viewer/PublicCommentModal.tsx b/web/packages/gallery/components/viewer/PublicCommentModal.tsxindex aca1c53778..e8431b6b5f 100644--- a/web/packages/gallery/components/viewer/PublicCommentModal.tsx+++ b/web/packages/gallery/components/viewer/PublicCommentModal.tsx@@ -99,9 +99,9 @@ export interface PublicCommentModalProps extends ModalVisibilityProps {*/onCommentAnonymously: () => void;/**- * Called when user clicks "Sign in and comment".+ * Called when user clicks "Join album and comment".*/- onSignInAndComment: () => void;+ onJoinAlbumToComment: () => void;}/**@@ -112,7 +112,7 @@ export const PublicCommentModal: React.FC<PublicCommentModalProps> = ({open,onClose,onCommentAnonymously,- onSignInAndComment,+ onJoinAlbumToComment,}) => {return (<StyledDialog open={open} onClose={onClose}>@@ -146,9 +146,9 @@ export const PublicCommentModal: React.FC<PublicCommentModalProps> = ({<SignInButtonvariant="contained"fullWidth- onClick={onSignInAndComment}+ onClick={onJoinAlbumToComment}>- Sign in and comment+ Join album and comment</SignInButton></ButtonsSection></ContentContainer>diff --git a/web/packages/gallery/components/viewer/PublicLikeModal.tsx b/web/packages/gallery/components/viewer/PublicLikeModal.tsxindex 0afbb2ee00..a821bb3248 100644--- a/web/packages/gallery/components/viewer/PublicLikeModal.tsx+++ b/web/packages/gallery/components/viewer/PublicLikeModal.tsx@@ -87,9 +87,9 @@ export interface PublicLikeModalProps extends ModalVisibilityProps {*/onLikeAnonymously: () => void;/**- * Called when user clicks "Sign in and like".+ * Called when user clicks "Join album to like".*/- onSignInAndLike: () => void;+ onJoinAlbumToLike: () => void;}/**@@ -100,7 +100,7 @@ export const PublicLikeModal: React.FC<PublicLikeModalProps> = ({open,onClose,onLikeAnonymously,- onSignInAndLike,+ onJoinAlbumToLike,}) => {return (<StyledDialog open={open} onClose={onClose}>@@ -134,9 +134,9 @@ export const PublicLikeModal: React.FC<PublicLikeModalProps> = ({<SignInButtonvariant="contained"fullWidth- onClick={onSignInAndLike}+ onClick={onJoinAlbumToLike}>- Sign in and like+ Join album and like</SignInButton></ButtonsSection></ContentContainer>