π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Simplify comment structure to store only text in encrypted payload
Anand Baburajan9ad13d6ea4fa
diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsxindex 62748aead6..5269133c94 100644--- a/web/packages/gallery/components/viewer/CommentsSidebar.tsx+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx@@ -237,17 +237,13 @@ const QuotedReply: React.FC<QuotedReplyProps> = ({currentUserID,userIDToEmail,}) => {- // Get the author name - for deleted comments, fall back to email from userIDToEmail+ // Get the author name from userIDconst getAuthorName = (): string => {if (parentComment.userID === currentUserID) {return "You";}- if (!parentComment.isDeleted && parentComment.encData?.userName) {- return parentComment.encData.userName;- }- // For deleted comments, try to get email from userIDToEmail mapconst email = userIDToEmail?.get(parentComment.userID);- return email ?? "Deleted user";+ return email ?? "User";};return (@@ -290,7 +286,7 @@ const QuotedReply: React.FC<QuotedReplyProps> = ({})),})}>- {truncateCommentText(parentComment.encData.text)}+ {truncateCommentText(parentComment.text)}</Typography>)}</QuotedReplyContainer>@@ -854,14 +850,11 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({setSending(true);try {const collection = await getCollectionByID(collectionID);- const userName =- prefetchedUserIDToEmail?.get(currentUserID ?? 0) ?? "User";- const commentData = { text, userName };const newCommentID = await addComment(collectionID,file.id,- commentData,+ text,collection.key,replyingTo?.id,);@@ -871,7 +864,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({id: newCommentID,collectionID,fileID: file.id,- encData: commentData,+ text,parentCommentID: replyingTo?.id,isDeleted: false,userID: currentUserID ?? 0,@@ -905,13 +898,13 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}};- const addLocalComment = (text: string, userName: string) => {+ const addLocalComment = (text: string) => {// Used for anonymous comments in public albumsconst newComment: Comment = {id: String(Date.now()),collectionID: selectedCollectionInfo?.id ?? 0,fileID: file?.id,- encData: { text, userName },+ text,parentCommentID: replyingTo?.id,isDeleted: false,userID: currentUserID ?? 0,@@ -940,9 +933,10 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({window.open("https://web.ente.io", "_blank");};- const handleNameSubmit = (name: string) => {+ const handleNameSubmit = (_name: string) => {setShowAddNameModal(false);- addLocalComment(pendingComment, name);+ // TODO: Store name via anon profile API+ addLocalComment(pendingComment);setPendingComment("");};@@ -1299,7 +1293,11 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({<Box key={comment.id}>{showHeader && (<CommentHeader- userName={comment.encData.userName}+ userName={+ prefetchedUserIDToEmail?.get(+ comment.userID,+ ) ?? "User"+ }timestamp={comment.createdAt}/>)}@@ -1359,7 +1357,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({<CommentTextisOwn={commentIsOwn}>- {comment.encData.text}+ {comment.text}</CommentText></CommentBubble>{!contextMenu && (@@ -1464,7 +1462,9 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({Replying to{" "}{replyingTo.userID === currentUserID? "yourself"- : replyingTo.encData.userName}+ : (prefetchedUserIDToEmail?.get(+ replyingTo.userID,+ ) ?? "User")}...</Typography><Typography@@ -1479,9 +1479,7 @@ export const CommentsSidebar: React.FC<CommentsSidebarProps> = ({}),})}>- {truncateCommentText(- replyingTo.encData.text,- )}+ {truncateCommentText(replyingTo.text)}</Typography></Box><IconButtondiff --git a/web/packages/gallery/components/viewer/FeedSidebar.tsx b/web/packages/gallery/components/viewer/FeedSidebar.tsxindex e9c1926899..0bb5faeef8 100644--- a/web/packages/gallery/components/viewer/FeedSidebar.tsx+++ b/web/packages/gallery/components/viewer/FeedSidebar.tsx@@ -339,8 +339,8 @@ const processFeedItems = (for (const c of comments) {if (c.isDeleted) continue;- // For comments, userName from encData might be an email- const email = users.get(c.userID) ?? c.encData.userName;+ // Look up display name from userID+ const displayName = users.get(c.userID) ?? "User";// Only show "Replied to your comment" if the parent comment belongs to// the current user. Otherwise show "Commented on your photo".@@ -360,8 +360,8 @@ const processFeedItems = (user: {userID: c.userID,anonUserID: c.anonUserID,- userName: c.encData.userName,- email,+ userName: displayName,+ email: displayName,},});} else {@@ -377,8 +377,8 @@ const processFeedItems = (user: {userID: c.userID,anonUserID: c.anonUserID,- userName: c.encData.userName,- email,+ userName: displayName,+ email: displayName,},});}diff --git a/web/packages/new/photos/services/comment.ts b/web/packages/new/photos/services/comment.tsindex e30070fdbb..24661ebeab 100644--- a/web/packages/new/photos/services/comment.ts+++ b/web/packages/new/photos/services/comment.ts@@ -3,15 +3,6 @@ import { authenticatedRequestHeaders, ensureOk } from "ente-base/http";import { apiURL } from "ente-base/origins";import { z } from "zod";-/**- * Encrypted comment data structure.- */-export interface CommentData {- text: string;- userName: string;- userAvatar?: string;-}-/*** A decrypted comment.*/@@ -24,7 +15,8 @@ export interface Comment {parentCommentUserID?: number;userID: number;anonUserID?: string;- encData: CommentData;+ /** The decrypted comment text. */+ text: string;isDeleted: boolean;createdAt: number;updatedAt: number;@@ -66,7 +58,7 @@ export const getFileComments = async (parentCommentID: comment.parentCommentID ?? undefined,userID: comment.userID,anonUserID: comment.anonUserID ?? undefined,- encData: { text: "", userName: "" },+ text: "",isDeleted: comment.isDeleted,createdAt: comment.createdAt,updatedAt: comment.updatedAt,@@ -78,22 +70,22 @@ export const getFileComments = async ({ encryptedData: comment.cipher, nonce: comment.nonce },collectionKey,);- const decryptedStr = new TextDecoder().decode(+ const text = new TextDecoder().decode(Uint8Array.from(atob(decryptedB64), (c) => c.charCodeAt(0)),);- const encData = JSON.parse(decryptedStr) as CommentData;- decryptedComments.push({+ const decryptedComment = {id: comment.id,collectionID: comment.collectionID,fileID: comment.fileID ?? undefined,parentCommentID: comment.parentCommentID ?? undefined,userID: comment.userID,anonUserID: comment.anonUserID ?? undefined,- encData,+ text,isDeleted: comment.isDeleted,createdAt: comment.createdAt,updatedAt: comment.updatedAt,- });+ };+ decryptedComments.push(decryptedComment);} catch (e) {// Log and skip comments that fail to decryptconsole.error("Failed to decrypt comment", comment.id, e);@@ -107,7 +99,7 @@ export const getFileComments = async (** @param collectionID The ID of the collection containing the file.* @param fileID The ID of the file to comment on.- * @param commentData The comment data to encrypt.+ * @param text The comment text to encrypt.* @param collectionKey The decrypted collection key (base64 encoded).* @param parentCommentID Optional parent comment ID for replies.* @returns The ID of the created comment.@@ -115,12 +107,12 @@ export const getFileComments = async (export const addComment = async (collectionID: number,fileID: number,- commentData: CommentData,+ text: string,collectionKey: string,parentCommentID?: string,): Promise<string> => {const { encryptedData: cipher, nonce } = await encryptBox(- new TextEncoder().encode(JSON.stringify(commentData)),+ new TextEncoder().encode(text),collectionKey,);@@ -147,16 +139,16 @@ export const addComment = async (* Update a comment's content.** @param commentID The ID of the comment to update.- * @param commentData The new comment data.+ * @param text The new comment text.* @param collectionKey The decrypted collection key (base64 encoded).*/export const updateComment = async (commentID: string,- commentData: CommentData,+ text: string,collectionKey: string,): Promise<void> => {const { encryptedData: cipher, nonce } = await encryptBox(- new TextEncoder().encode(JSON.stringify(commentData)),+ new TextEncoder().encode(text),collectionKey,);diff --git a/web/packages/new/photos/services/social.ts b/web/packages/new/photos/services/social.tsindex 2507eba23e..96276cb0fa 100644--- a/web/packages/new/photos/services/social.ts+++ b/web/packages/new/photos/services/social.ts@@ -2,7 +2,7 @@ import { decryptBox } from "ente-base/crypto";import { authenticatedRequestHeaders, ensureOk } from "ente-base/http";import { apiURL } from "ente-base/origins";import { z } from "zod";-import type { Comment, CommentData } from "./comment";+import type { Comment } from "./comment";/*** Remove null byte padding from a decrypted reaction type.@@ -115,7 +115,7 @@ const decryptSocialDiff = async (parentCommentUserID: comment.parentCommentUserID ?? undefined,userID: comment.userID,anonUserID: comment.anonUserID ?? undefined,- encData: { text: "", userName: "" },+ text: "",isDeleted: comment.isDeleted,createdAt: comment.createdAt,updatedAt: comment.updatedAt,@@ -127,11 +127,10 @@ const decryptSocialDiff = async ({ encryptedData: comment.cipher, nonce: comment.nonce },collectionKey,);- const decryptedStr = new TextDecoder().decode(+ const text = new TextDecoder().decode(Uint8Array.from(atob(decryptedB64), (c) => c.charCodeAt(0)),);- const encData = JSON.parse(decryptedStr) as CommentData;- comments.push({+ const decryptedComment = {id: comment.id,collectionID: comment.collectionID,fileID: comment.fileID ?? undefined,@@ -139,11 +138,12 @@ const decryptSocialDiff = async (parentCommentUserID: comment.parentCommentUserID ?? undefined,userID: comment.userID,anonUserID: comment.anonUserID ?? undefined,- encData,+ text,isDeleted: comment.isDeleted,createdAt: comment.createdAt,updatedAt: comment.updatedAt,- });+ };+ comments.push(decryptedComment);} catch {// Skip comments that fail to decrypt}@@ -181,12 +181,13 @@ const decryptSocialDiff = async (}}- return {+ const result = {comments,reactions,hasMoreComments: data.hasMoreComments,hasMoreReactions: data.hasMoreReactions,};+ return result;};const RemoteComment = z.object({