π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Simplify Space web hydration
Neeraj Gupta44307a76e9fe
diff --git a/web/apps/space/src/components/SpaceFileViewer.tsx b/web/apps/space/src/components/SpaceFileViewer.tsxindex 9f929e8cdb..e9c01568f3 100644--- a/web/apps/space/src/components/SpaceFileViewer.tsx+++ b/web/apps/space/src/components/SpaceFileViewer.tsx@@ -132,6 +132,7 @@ export interface SpaceViewerPhoto {imageUrl: string;name: string;postId?: number;+ spaceId?: string;timestampMs: number;viewerLiked?: boolean;width?: number;@@ -154,7 +155,11 @@ interface SpaceFileViewerProps {caption: string,edit: SpaceViewerDraftPostEdit,) => Promise<void>;- onReplyToPost?: (postId: number, text: string) => Promise<void>;+ onReplyToPost?: (+ spaceId: string,+ postId: number,+ text: string,+ ) => Promise<void>;onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;onSwipeLeft?: () => void;onSwipeRight?: () => void;@@ -397,7 +402,7 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({(!onPublishDraftPost && !canQueueDraftPostPublish);const isReplyActionRunning = replyActionPhase != null;const canReplyToPost = Boolean(- !isDraftPost && activePhoto.postId && onReplyToPost,+ !isDraftPost && activePhoto.spaceId && activePhoto.postId && onReplyToPost,);const isReplyMode =canReplyToPost &&@@ -548,12 +553,23 @@ export const SpaceFileViewer: React.FC<SpaceFileViewerProps> = ({const sendReply = () => {const text = replyText.trim();- if (!canSendReply || !activePhoto.postId || !onReplyToPost) return;+ if (+ !canSendReply ||+ !activePhoto.spaceId ||+ !activePhoto.postId ||+ !onReplyToPost+ ) {+ return;+ }setReplyActionPhase("busy");void (async () => {try {- await onReplyToPost(activePhoto.postId!, text);+ await onReplyToPost(+ activePhoto.spaceId!,+ activePhoto.postId!,+ text,+ );setReplyText("");setReplyActionPhase("done");} catch (error) {diff --git a/web/apps/space/src/pages/app/friends/[spaceId].tsx b/web/apps/space/src/pages/app/friends/[spaceId].tsxindex fe0b0040cf..c5ac08280b 100644--- a/web/apps/space/src/pages/app/friends/[spaceId].tsx+++ b/web/apps/space/src/pages/app/friends/[spaceId].tsx@@ -226,8 +226,8 @@ const Page: React.FC = () => {}}onBack={goBack}onLoadPostImage={loadCurrentSpacePostAssetURL}- onReplyToPost={(postId, text) =>- replyToCurrentPost(actorSpaceId, postId, text)+ onReplyToPost={(postSpaceId, postId, text) =>+ replyToCurrentPost(actorSpaceId, postSpaceId, postId, text)}onSetPostLiked={(postId, liked) =>setCurrentPostLiked(actorSpaceId, postId, liked)diff --git a/web/apps/space/src/pages/app/index.tsx b/web/apps/space/src/pages/app/index.tsxindex 8a601f5d16..fbeba4bff5 100644--- a/web/apps/space/src/pages/app/index.tsx+++ b/web/apps/space/src/pages/app/index.tsx@@ -314,8 +314,18 @@ const Page: React.FC = () => {onReplyToPost={profile?.spaceId? (- (spaceId) => (postId: number, text: string) =>- replyToCurrentPost(spaceId, postId, text)+ (actorSpaceId) =>+ (+ postSpaceId: string,+ postId: number,+ text: string,+ ) =>+ replyToCurrentPost(+ actorSpaceId,+ postSpaceId,+ postId,+ text,+ ))(profile.spaceId): undefined}diff --git a/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx b/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsxindex 27347b5d35..2530112455 100644--- a/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx+++ b/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx@@ -52,6 +52,7 @@ const viewerPhotoFromPost = (post: SpacePost) => ({imageUrl: post.imageUrl ?? "",name: post.name,postId: post.postId,+ spaceId: post.spaceId,timestampMs: post.timestampMs,viewerLiked: post.viewerLiked,width: post.width,@@ -165,8 +166,13 @@ const Page: React.FC = () => {onReplyToPost={isOwnPost? undefined- : (nextPostId, text) =>- replyToCurrentPost(actorSpaceId, nextPostId, text)+ : (postSpaceId, nextPostId, text) =>+ replyToCurrentPost(+ actorSpaceId,+ postSpaceId,+ nextPostId,+ text,+ )}onSetPostLiked={(nextPostId, liked) =>setCurrentPostLiked(actorSpaceId, nextPostId, liked)diff --git a/web/apps/space/src/screens/HomeScreen.tsx b/web/apps/space/src/screens/HomeScreen.tsxindex f34753140a..c43bf7d6a2 100644--- a/web/apps/space/src/screens/HomeScreen.tsx+++ b/web/apps/space/src/screens/HomeScreen.tsx@@ -126,7 +126,11 @@ interface HomeScreenProps {onOpenFriend?: (friendID: string) => void;onOpenMessages?: () => void;onOpenProfile?: () => void;- onReplyToPost?: (postId: number, text: string) => Promise<void>;+ onReplyToPost?: (+ postSpaceId: string,+ postId: number,+ text: string,+ ) => Promise<void>;onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;profileLink?: string;profile: SetupProfile | null;@@ -185,6 +189,7 @@ interface FeedItemProps {onOpenProfile?: () => void;onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;postId: number;+ spaceId?: string;thumbHash?: string;timestampStatus?: FeedTimestampStatus;timestampMs: number;@@ -655,6 +660,7 @@ const FeedItem: React.FC<FeedItemProps> = ({onOpenProfile,onSetPostLiked,postId,+ spaceId,thumbHash,timestampStatus,timestampMs,@@ -745,6 +751,7 @@ const FeedItem: React.FC<FeedItemProps> = ({imageUrl: displayImageUrl,name,postId,+ spaceId,timestampMs,viewerLiked: isLiked,width: photoDimensions.width,@@ -1577,6 +1584,7 @@ export const HomeScreen: React.FC<HomeScreenProps> = ({onOpenProfile={onOpenProfile}onSetPostLiked={onSetPostLiked}postId={item.postId}+ spaceId={item.spaceId}thumbHash={item.thumbHash}timestampStatus={timestampStatus}timestampMs={item.timestampMs}diff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex 9636eaa08c..c6f5642e2e 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -154,19 +154,6 @@ const Avatar: React.FC<{ avatarUrl?: string | null; size: number }> = ({</Box>);-const messagePreview = (message: SpaceMessage) => {- if (message.kind == "post_like") {- return message.text;- }- if (message.kind == "post_reply") {- return message.text || "Replied to a post";- }- if (message.replyMessageId) {- return message.text || "Replied to a message";- }- return message.text;-};-const truncateMessageText = (text: string): string => {const lines = text.split("\n");const firstLine = lines[0] ?? text;@@ -192,10 +179,7 @@ const isCurrentProfileActor = (return actor.username == profile.username;};-const conversationPreview = (- conversation: SpaceMessageConversation,- profile: SetupProfile,-) => {+const conversationPreview = (conversation: SpaceMessageConversation) => {const activity = conversation.latestActivity;if (activity.type == "empty") {return "You are now friends";@@ -203,6 +187,9 @@ const conversationPreview = (if (activity.type == "friend_request") {return "Friend request";}+ if (activity.type == "friend_added") {+ return "You are now friends";+ }if (activity.type == "post_like") {return activity.outgoing ? "You liked a post" : "Liked your post";}@@ -210,48 +197,15 @@ const conversationPreview = (return "Replied";}if (activity.type == "message_like") {- const text = activity.message?.text.trim();- return text- ? `${activity.outgoing ? "You liked" : "Liked"} "${truncateMessageText(text)}"`- : activity.outgoing- ? "You liked a message"- : "Liked a message";+ return activity.outgoing ? "You liked a message" : "Liked a message";}- const message = activity.message;- if (!message) return "";- const preview = messagePreview(message);- return isCurrentProfileMessage(message, profile)- ? `You: ${preview}`- : preview;-};--const quotedConversationActivityPreview = (- activity: SpaceMessageConversation["latestActivity"],-) => {- const text = activity.message?.text.trim();- if (!text) return undefined;- const previewText = truncateMessageText(text);-- if (activity.type == "message_like") {- return {- prefix: activity.outgoing ? 'You liked "' : 'Liked "',- previewText,- suffix: '"',- };- }- if (activity.type == "post_reply") {- return { prefix: "", previewText, suffix: "" };- }- return undefined;+ return activity.outgoing ? "You sent a message" : "Message";};const ConversationPreviewLine: React.FC<{conversation: SpaceMessageConversation;- profile: SetupProfile;-}> = ({ conversation, profile }) => {- const activity = conversation.latestActivity;- const quotedPreview = quotedConversationActivityPreview(activity);+}> = ({ conversation }) => {const previewLineSx = {color: textSecondary,fontFamily: '"Inter Variable", Inter, sans-serif',@@ -264,33 +218,9 @@ const ConversationPreviewLine: React.FC<{whiteSpace: "nowrap",};- if (!quotedPreview) {- return (- <Box sx={previewLineSx}>- {conversationPreview(conversation, profile)}- </Box>- );- }-return (- <Box sx={{ ...previewLineSx, alignItems: "baseline", display: "flex" }}>- <Box component="span" sx={{ flexShrink: 0 }}>- {quotedPreview.prefix}- </Box>- <Box- component="span"- sx={{- minWidth: 0,- overflow: "hidden",- textOverflow: "ellipsis",- whiteSpace: "nowrap",- }}- >- {quotedPreview.previewText}- </Box>- <Box component="span" sx={{ flexShrink: 0 }}>- {quotedPreview.suffix}- </Box>+ <Box sx={previewLineSx}>+ {conversationPreview(conversation)}</Box>);};@@ -447,7 +377,6 @@ const ConversationListItem: React.FC<{) => Promise<void>;onLoadActivityPost?: (post: SpaceMessageActivityPost) => void;onOpenThread: (conversation: SpaceMessageConversation) => void;- profile: SetupProfile;}> = ({activityPost,conversation,@@ -455,7 +384,6 @@ const ConversationListItem: React.FC<{onDeleteFriendRequest,onLoadActivityPost,onOpenThread,- profile,}) => {const name =conversation.friend.fullName.trim() || conversation.friend.username;@@ -627,10 +555,7 @@ const ConversationListItem: React.FC<{{timestampLabel}</Box></Box>- <ConversationPreviewLine- conversation={conversation}- profile={profile}- />+ <ConversationPreviewLine conversation={conversation} /></Box>{postThumbnailUrl && (<Box@@ -708,7 +633,6 @@ const ConversationSection: React.FC<{) => Promise<void>;onLoadActivityPost?: (post: SpaceMessageActivityPost) => void;onOpenThread: (conversation: SpaceMessageConversation) => void;- profile: SetupProfile;section: ConversationSection;}> = ({activityPostsByKey,@@ -716,7 +640,6 @@ const ConversationSection: React.FC<{onDeleteFriendRequest,onLoadActivityPost,onOpenThread,- profile,section,}) => {if (section.items.length == 0) return null;@@ -756,7 +679,6 @@ const ConversationSection: React.FC<{onDeleteFriendRequest={onDeleteFriendRequest}onLoadActivityPost={onLoadActivityPost}onOpenThread={onOpenThread}- profile={profile}/>))}</Box>@@ -775,7 +697,7 @@ const bodyBubblesCanGroup = () => {if (!first || !second) return false;if (!sameMessageSender(first, second)) return false;- if (first.kind == "post_like") return false;+ if (first.kind == "post_like" || first.kind == "friend_added") return false;if (second.kind != "regular" || second.replyMessageId) return false;if (!isSameLocalDate(@@ -1184,9 +1106,12 @@ const MessageBubble: React.FC<{? `20px ${groupsWithPrevious ? "6px" : "20px"} ${groupsWithNext ? "6px" : "20px"} 20px`: `${groupsWithPrevious ? "6px" : "20px"} 20px 20px ${groupsWithNext ? "6px" : "20px"}`;const isSyntheticPostLike = message.kind == "post_like";+ const isFriendAdded = message.kind == "friend_added";const isPostReply = message.kind == "post_reply";const hasMessageReply = Boolean(message.replyMessageId);- const actionLabel = isSyntheticPostLike+ const actionLabel = isFriendAdded+ ? "You are now friends"+ : isSyntheticPostLike? isOwn? "You liked their post": "Liked your post"@@ -1199,7 +1124,7 @@ const MessageBubble: React.FC<{? "You replied": "Replied to you": undefined;- const hasBodyBubble = !isSyntheticPostLike;+ const hasBodyBubble = !isSyntheticPostLike && !isFriendAdded;const longPressTimerRef = React.useRef<number | undefined>(undefined);const longPressStartRef = React.useRef<{ x: number; y: number } | undefined@@ -2572,7 +2497,6 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({loadActivityPost}onOpenThread={onOpenThread}- profile={profile}section={section}/>))}diff --git a/web/apps/space/src/screens/ProfileScreen.tsx b/web/apps/space/src/screens/ProfileScreen.tsxindex e88ec04ba7..b53e782cde 100644--- a/web/apps/space/src/screens/ProfileScreen.tsx+++ b/web/apps/space/src/screens/ProfileScreen.tsx@@ -73,6 +73,7 @@ export interface ProfilePostItem {imageUrl?: string;name?: string;postId?: number;+ spaceId?: string;timestampMs: number;thumbHash?: string;viewerLiked?: boolean;@@ -533,7 +534,11 @@ interface ProfileScreenProps {onOpenProfilePhoto?: () => void;onOpenSettings?: () => void;onLoadPostImage?: (asset: SpacePostAsset) => Promise<string>;- onReplyToPost?: (postId: number, text: string) => Promise<void>;+ onReplyToPost?: (+ postSpaceId: string,+ postId: number,+ text: string,+ ) => Promise<void>;onSetPostLiked?: (postId: number, liked: boolean) => Promise<void>;postGroups?: ProfilePostGroup[];profile: SetupProfile;@@ -789,6 +794,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({imageUrl,name: displayName,postId: item.postId,+ spaceId: item.spaceId,timestampMs: item.timestampMs,viewerLiked: item.viewerLiked,width: dimensions.width,@@ -815,6 +821,7 @@ export const ProfileScreen: React.FC<ProfileScreenProps> = ({: ""),name: displayName,postId: item.postId,+ spaceId: item.spaceId,timestampMs: item.timestampMs,viewerLiked: item.viewerLiked,width: dimensions.width,diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.tsindex 506aec7e0f..09f9381032 100644--- a/web/apps/space/src/services/space.ts+++ b/web/apps/space/src/services/space.ts@@ -44,8 +44,6 @@ interface SpaceProfileResponse {interface SpaceActor {avatar?: SpaceAvatar;- friends?: number;- posts?: number;profile?: string;publicKey?: string;spaceId: string;@@ -82,25 +80,19 @@ interface SpacePostPageResponse {type SpaceMessageConversationActivityType =| "empty"| "friend_request"+ | "friend_added"| "message"| "message_like"| "post_like"| "post_reply";-interface SpaceMessageConversationPostResponse {- isDeleted?: boolean;- objects?: SpacePostObject[];- postId: number;- spaceId: string;- spaceSlug: string;-}-interface SpaceMessageConversationActivity {createdAt: string;id: string;- message?: SpaceMessageResponse;+ messageId?: string;outgoing?: boolean;- post?: SpaceMessageConversationPostResponse;+ postId?: number;+ postSpaceId?: string;type: SpaceMessageConversationActivityType;}@@ -110,7 +102,11 @@ interface SpaceFriend {shareKeyVersion: number;}-type SpaceMessageKindResponse = "post_like" | "post_reply" | "regular";+type SpaceMessageKindResponse =+ | "friend_added"+ | "post_like"+ | "post_reply"+ | "regular";interface SpaceMessageQuoteResponse {caption?: string;@@ -276,7 +272,7 @@ export interface SpaceMessageActivityPost {export interface SpaceMessageActivity {createdAtMs: number;id: string;- message?: SpaceMessage;+ messageId?: string;outgoing: boolean;post?: SpaceMessageActivityPost;type: SpaceMessageActivityType;@@ -356,7 +352,7 @@ const actorProfile = (actor: SpaceActor): FriendProfile => {avatarSize: actor.avatar?.size,avatarUpdatedAt: actor.avatar?.updatedAt,avatarUrl: null,- friendsCount: actor.friends ?? 0,+ friendsCount: 0,fullName,id: actor.spaceId || username,username,@@ -492,25 +488,6 @@ const cacheAccountPostAssetURL = async (await rememberCachedSpaceMediaBlobURL(key, blob);};-const accountPostAssetURLByPostId = (- ctx: SpaceAccountCtxHandle,- spaceId: string,- postId: number,- objectKey: string,- viewerSpaceId?: string,- mediaType?: string,-) =>- cachedSpaceMediaBlobURL(- spacePostMediaCacheKey(spaceId, objectKey),- () =>- ctx.download_post_asset(- BigInt(postId),- viewerSpaceId ?? null,- objectKey,- ),- mediaType,- );-const accountPostAssetURLFromQuote = (ctx: SpaceAccountCtxHandle,quote: SpaceMessageQuoteResponse,@@ -719,39 +696,17 @@ const messageFromSpaceMessage = async (};};-const messageActivityPostFromSpacePost = async (- ctx: SpaceAccountCtxHandle,- post: SpaceMessageConversationPostResponse | undefined,- viewerSpaceId?: string,-): Promise<SpaceMessageActivityPost | undefined> => {- if (!post) return undefined;-- const object = firstObject(post);- const spacePost: SpaceMessageActivityPost = {- height: object?.height,- mediaType: object?.mediaType,- isDeleted: Boolean(post.isDeleted),- objectKey: object?.objectKey,- postId: post.postId,- spaceId: post.spaceId,- spaceSlug: post.spaceSlug,- width: object?.width,- };- if (post.isDeleted || !object?.objectKey) return spacePost;-- try {- spacePost.imageUrl = await accountPostAssetURLByPostId(- ctx,- post.spaceId,- post.postId,- object.objectKey,- viewerSpaceId,- object.mediaType,- );- } catch (error) {- console.warn("Failed to load message activity post image", error);+const messageActivityPostFromActivity = (+ activity: SpaceMessageConversationActivity,+): SpaceMessageActivityPost | undefined => {+ if (typeof activity.postId != "number" || !activity.postSpaceId) {+ return undefined;}- return spacePost;+ return {+ postId: activity.postId,+ spaceId: activity.postSpaceId,+ spaceSlug: "",+ };};export const loadCurrentMessageActivityPostPreview = async (@@ -776,25 +731,15 @@ export const loadCurrentMessageActivityPostPreview = async (};const messageActivityFromSpaceActivity = async (- ctx: SpaceAccountCtxHandle,+ _ctx: SpaceAccountCtxHandle,activity: SpaceMessageConversationActivity,- viewerSpaceId?: string,+ _viewerSpaceId?: string,): Promise<SpaceMessageActivity> => {- const [message, post] = await Promise.all([- activity.message- ? messageFromSpaceMessage(- ctx,- activity.message,- false,- viewerSpaceId,- )- : undefined,- messageActivityPostFromSpacePost(ctx, activity.post, viewerSpaceId),- ]);+ const post = messageActivityPostFromActivity(activity);return {createdAtMs: timestampMsFromSpaceDate(activity.createdAt),id: activity.id,- message,+ messageId: activity.messageId,outgoing: Boolean(activity.outgoing),post,type: activity.type,@@ -984,6 +929,7 @@ export const loadCurrentSpacePost = async (const post = await postFromAccountPost(ctx,(await ctx.get_post(+ spaceId,BigInt(postId),viewerSpaceId ?? null,)) as SpacePostResponse,@@ -1110,14 +1056,20 @@ export const setCurrentPostLiked = async (};export const replyToCurrentPost = async (- spaceId: string,+ actorSpaceId: string,+ postSpaceId: string,postId: number,text: string,) => {const messageText = normalizeSpaceMessageText(text);const ctx = await ensureCurrentSpaceContext();try {- await ctx.reply_to_post(spaceId, BigInt(postId), messageText);+ await ctx.reply_to_post(+ actorSpaceId,+ postSpaceId,+ BigInt(postId),+ messageText,+ );} finally {releaseCurrentSpaceContext(ctx);}