π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Open quoted Space posts
Anand Baburajan0b6d9bf02a73
diff --git a/rust/bindings/wasm/ente-wasm/src/space.rs b/rust/bindings/wasm/ente-wasm/src/space.rsindex b109039ae2..09369273eb 100644--- a/rust/bindings/wasm/ente-wasm/src/space.rs+++ b/rust/bindings/wasm/ente-wasm/src/space.rs@@ -933,6 +933,16 @@ impl SpaceAccountCtxHandle {.map_err(Into::into)}+ /// Fetch one post with its caption decrypted.+ pub async fn get_post(&self, post_id: i64) -> Result<JsValue, WasmSpaceError> {+ let post = self.inner.get_post(post_id).await?;+ let decrypted = self+ .inner+ .decrypt_post_for_space(&post.space_id, &post)+ .await?;+ swb::to_value(&account_post_to_js(&self.inner, post, decrypted).await?).map_err(Into::into)+ }+/// Create a single-photo post with optional caption.pub async fn create_photo_post(&self,diff --git a/web/apps/space/src/components/SpaceMessagesPage.tsx b/web/apps/space/src/components/SpaceMessagesPage.tsxindex 77700ad5d3..508507701a 100644--- a/web/apps/space/src/components/SpaceMessagesPage.tsx+++ b/web/apps/space/src/components/SpaceMessagesPage.tsx@@ -9,8 +9,8 @@ import {deleteCurrentMessage,loadCurrentMessageConversations,loadCurrentMessageThread,- loadCurrentSpaceProfile,loadCurrentSpaceFriends,+ loadCurrentSpaceProfile,markCurrentMessageLikesRead,markCurrentMessagesRead,replyToCurrentMessage,@@ -445,6 +445,11 @@ export const SpaceMessagesPage: React.FC<SpaceMessagesPageProps> = ({onOpenSelectedFriendProfile={(friend) =>void router.push(spaceRoutes.friend(friendSpaceId(friend)))}+ onOpenQuotePost={(quote) =>+ void router.push(+ spaceRoutes.post(quote.spaceId, quote.postId),+ )+ }onOpenThread={openConversation}onSendMessage={async (spaceId, text) => {const optimisticMessage = createLocalMessage({diff --git a/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx b/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsxnew file mode 100644index 0000000000..c3c81e84f0--- /dev/null+++ b/web/apps/space/src/pages/app/posts/[spaceId]/[postId].tsx@@ -0,0 +1,161 @@+import { SpaceFileViewer } from "components/SpaceFileViewer";+import { SpacePageMeta } from "components/SpacePageMeta";+import { SpaceRouteFallback } from "components/SpaceRouteFallback";+import { useRouter } from "next/router";+import React from "react";+import {+ loadCurrentSpacePost,+ replyToCurrentPost,+ setCurrentPostLiked,+ type SpacePost,+} from "services/space";+import { useSpaceAppState } from "state/spaceAppState";+import { spaceRoutes } from "utils/spaceRoutes";++const postBackground = "#000000";++const valueFromQuery = (value: string | string[] | undefined) =>+ Array.isArray(value) ? value[0] : value;++const postIdFromQuery = (value: string | string[] | undefined) => {+ const postIdText = valueFromQuery(value);+ if (!postIdText || !/^\d+$/.test(postIdText)) return undefined;++ const postId = Number(postIdText);+ return Number.isSafeInteger(postId) && postId > 0 ? postId : undefined;+};++const routeParamsFromPath = () => {+ if (typeof window == "undefined") return {};++ const match = /^\/app\/posts\/([^/?#]+)\/([^/?#]+)/.exec(+ window.location.pathname,+ );+ if (!match?.[1] || !match[2]) return {};++ try {+ return {+ postId: postIdFromQuery(decodeURIComponent(match[2])),+ spaceId: decodeURIComponent(match[1]),+ };+ } catch {+ return {};+ }+};++const viewerPhotoFromPost = (post: SpacePost) => ({+ alt: `${post.name} post`,+ avatarUrl: post.avatarUrl,+ caption: post.caption,+ friendID: post.friendID,+ height: post.height,+ imageUrl: post.imageUrl ?? "",+ name: post.name,+ postId: post.postId,+ timestampMs: post.timestampMs,+ viewerLiked: post.viewerLiked,+ width: post.width,+});++const Page: React.FC = () => {+ const router = useRouter();+ const { profile, profileLoadError, profileLoadStatus } = useSpaceAppState();+ const pathParams = routeParamsFromPath();+ const spaceId =+ valueFromQuery(router.query.spaceId) ?? pathParams.spaceId ?? "";+ const postId = postIdFromQuery(router.query.postId) ?? pathParams.postId;+ const [post, setPost] = React.useState<SpacePost | null>(null);+ const [postLoadError, setPostLoadError] = React.useState<string>();+ const [isPostLoading, setIsPostLoading] = React.useState(false);+ const postRouteKey = spaceId && postId ? `${spaceId}:${postId}` : "";+ const isOwnPost = Boolean(post && post.spaceId == profile?.spaceId);++ React.useEffect(() => {+ if (profileLoadStatus == "ready" && !profile) {+ void router.replace(spaceRoutes.onboarding);+ }+ }, [profile, profileLoadStatus, router]);++ React.useEffect(() => {+ if (profileLoadStatus != "ready" || !profile || !spaceId || !postId) {+ return;+ }++ let cancelled = false;+ setPost(null);+ setPostLoadError(undefined);+ setIsPostLoading(true);++ void loadCurrentSpacePost(spaceId, postId)+ .then((nextPost) => {+ if (cancelled) return;+ if (!nextPost) {+ setPostLoadError("Post unavailable.");+ return;+ }+ setPost(nextPost);+ })+ .catch((error: unknown) => {+ console.error("Failed to load space post", error);+ if (!cancelled) setPostLoadError("Post unavailable.");+ })+ .finally(() => {+ if (!cancelled) setIsPostLoading(false);+ });++ return () => {+ cancelled = true;+ };+ }, [postRouteKey, profile, profileLoadStatus, spaceId, postId]);++ const ownerProfileRoute = React.useCallback(() => {+ const ownerSpaceId = post?.spaceId ?? spaceId;+ return ownerSpaceId == profile?.spaceId+ ? spaceRoutes.profile+ : spaceRoutes.friend(ownerSpaceId);+ }, [post?.spaceId, profile?.spaceId, spaceId]);++ const closePost = React.useCallback(() => {+ if (typeof window != "undefined" && window.history.length > 1) {+ router.back();+ return;+ }+ void router.push(ownerProfileRoute());+ }, [ownerProfileRoute, router]);++ if (+ !router.isReady ||+ profileLoadStatus != "ready" ||+ !profile ||+ !spaceId ||+ !postId ||+ isPostLoading ||+ !post+ ) {+ return (+ <SpaceRouteFallback+ background="#FFFFFF"+ message={postLoadError || profileLoadError}+ />+ );+ }++ return (+ <>+ <SpacePageMeta+ themeColor={postBackground}+ title={`${post.name} Post | Ente Space`}+ />+ <SpaceFileViewer+ photo={viewerPhotoFromPost(post)}+ postActionMode={isOwnPost ? "hidden" : "like-only"}+ onClose={closePost}+ onOpenProfile={() => void router.push(ownerProfileRoute())}+ onReplyToPost={isOwnPost ? undefined : replyToCurrentPost}+ onSetPostLiked={setCurrentPostLiked}+ />+ </>+ );+};++export default Page;diff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex f51418f21e..9d42215ee5 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -12,7 +12,11 @@ import React from "react";import { flushSync } from "react-dom";import type { SetupProfile } from "screens/SetupProfileScreen";import { ShareIcon } from "screens/ShareProfileLinkScreen";-import type { SpaceMessage, SpaceMessageConversation } from "services/space";+import type {+ SpaceMessage,+ SpaceMessageConversation,+ SpaceMessageQuote,+} from "services/space";import { spaceTouchTargetSize } from "styles/touchTargets";import { firstNameFrom } from "utils/spaceDisplay";import { clampSpaceMessageText } from "utils/spaceMessageLimits";@@ -59,6 +63,7 @@ interface MessagesScreenProps {onOpenSelectedFriendProfile: (friend: SpaceMessageConversation["friend"],) => void;+ onOpenQuotePost: (quote: SpaceMessageQuote) => void;onOpenThread: (conversation: SpaceMessageConversation) => void;onReplyToMessage: (spaceId: string,@@ -654,13 +659,15 @@ const CopyIcon: React.FC = () => (</svg>);-const QuotePreview: React.FC<{ isOwn: boolean; message: SpaceMessage }> = ({- isOwn,- message,-}) => {+const QuotePreview: React.FC<{+ isOwn: boolean;+ message: SpaceMessage;+ onOpenQuotePost: (quote: SpaceMessageQuote) => void;+}> = ({ isOwn, message, onOpenQuotePost }) => {if (message.kind != "post_reply") return null;const quote = message.quote;const isUnavailable = !quote || quote.isUnavailable || !quote.imageUrl;+ const canOpen = Boolean(quote && !isUnavailable);return (<Box@@ -684,15 +691,36 @@ const QuotePreview: React.FC<{ isOwn: boolean; message: SpaceMessage }> = ({}}/><Box+ component={canOpen ? "button" : "div"}+ type={canOpen ? "button" : undefined}+ aria-label={canOpen ? "Open quoted post" : undefined}+ onClick={(event: React.MouseEvent) => {+ if (!quote || !canOpen) return;+ event.stopPropagation();+ onOpenQuotePost(quote);+ }}sx={{+ appearance: "none",alignItems: "center",+ bgcolor: "transparent",+ border: 0,+ borderRadius: "8px",+ color: "inherit",+ cursor: canOpen ? "pointer" : "default",display: "grid",gap: "10px",gridTemplateColumns: isUnavailable? "minmax(0, 1fr)": "minmax(0, 1fr) 44px",+ font: "inherit",minWidth: 0,+ p: 0,+ textAlign: "left",width: "100%",+ "&:focus-visible": {+ outline: `2px solid ${green}`,+ outlineOffset: 2,+ },}}><Box sx={{ minWidth: 0 }}>@@ -838,6 +866,7 @@ const MessageBubble: React.FC<{isLastInSequence: boolean;message: SpaceMessage;onOpenActions: (message: SpaceMessage, anchorEl: HTMLElement) => void;+ onOpenQuotePost: (quote: SpaceMessageQuote) => void;ownSpaceID?: string;parentMessage?: SpaceMessage;profile: SetupProfile;@@ -847,6 +876,7 @@ const MessageBubble: React.FC<{isLastInSequence,message,onOpenActions,+ onOpenQuotePost,ownSpaceID,parentMessage,profile,@@ -1041,7 +1071,11 @@ const MessageBubble: React.FC<{},}}>- <QuotePreview isOwn={isOwn} message={message} />+ <QuotePreview+ isOwn={isOwn}+ message={message}+ onOpenQuotePost={onOpenQuotePost}+ />{hasMessageReply && (<MessageReplyPreviewisOwn={isOwn}@@ -1192,6 +1226,7 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({onCloseThread,onDeleteMessage,onOpenSelectedFriendProfile,+ onOpenQuotePost,onOpenThread,onReplyToMessage,onSendMessage,@@ -1740,6 +1775,9 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({onOpenActions={openMessageActions}+ onOpenQuotePost={+ onOpenQuotePost+ }ownSpaceID={profile.spaceId}parentMessage={message.replyMessageId@@ -1935,11 +1973,8 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({borderLeft: `3px solid ${green}`,borderRadius: "12px",boxSizing: "border-box",- display: "grid",- gap: "8px",- gridTemplateColumns:- "minmax(0, 1fr) 24px",- p: "9px 8px 9px 12px",+ p: "9px 40px 9px 12px",+ position: "relative",width: "100%",}}>@@ -2001,12 +2036,20 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({height: spaceTouchTargetSize,justifyContent: "center",p: 0,+ position: "absolute",+ right: 0,+ top: 0,width: spaceTouchTargetSize,"&:focus-visible": {outline: `2px solid ${green}`,outlineOffset: 2,},"&:hover": { color: textBase },+ "& svg": {+ position: "absolute",+ right: 8,+ top: 8,+ },}}><HugeiconsIcondiff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.tsindex 88680d96a1..5ad921b01e 100644--- a/web/apps/space/src/services/space.ts+++ b/web/apps/space/src/services/space.ts@@ -1077,6 +1077,22 @@ export const loadCurrentSpaceProfilePostsPage = async (}};+export const loadCurrentSpacePost = async (+ spaceId: string,+ postId: number,+): Promise<SpacePost | null> => {+ const ctx = await ensureCurrentSpaceContext();+ try {+ const post = await postFromAccountPost(+ ctx,+ (await ctx.get_post(BigInt(postId))) as SpacePostResponse,+ );+ return post?.spaceId == spaceId ? post : null;+ } finally {+ releaseCurrentSpaceContext(ctx);+ }+};+export const loadCurrentSpacePostAssetURL: SpacePostAssetURLLoader = async (asset,) => {diff --git a/web/apps/space/src/utils/spaceRoutes.ts b/web/apps/space/src/utils/spaceRoutes.tsindex 7ea404ae61..49fba72a76 100644--- a/web/apps/space/src/utils/spaceRoutes.ts+++ b/web/apps/space/src/utils/spaceRoutes.ts@@ -26,6 +26,8 @@ export const spaceRoutes = {onboarding: "/",passkeysFinish: "/passkeys/finish",passkeysVerify: "/passkeys/verify",+ post: (spaceId: string, postId: number) =>+ `/app/posts/${encodeURIComponent(spaceId)}/${encodeURIComponent(String(postId))}`,editProfileCover: "/app/profile/cover-edit",editProfileCoverFrom: (source?: ProfileImageFlowSource) =>routeWithProfileImageFlowSource("/app/profile/cover-edit", source),