π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show space conversation message previews
Neeraj Gupta12cbe2b1ec20
diff --git a/rust/bindings/wasm/ente-wasm/src/space.rs b/rust/bindings/wasm/ente-wasm/src/space.rsindex 0ebd7be95c..da3870fe8c 100644--- a/rust/bindings/wasm/ente-wasm/src/space.rs+++ b/rust/bindings/wasm/ente-wasm/src/space.rs@@ -194,6 +194,7 @@ struct MessageConversationActivityJs {created_at: String,outgoing: bool,message_id: Option<String>,+ text: Option<String>,post_id: Option<i64>,post_space_id: Option<String>,}@@ -482,18 +483,58 @@ async fn account_message_response_to_js(})}-fn message_conversation_activity_to_js(+async fn message_conversation_activity_text(+ ctx: &AccountSpaceCtx,+ viewer_space_id: &str,+ activity: &MessageConversationActivity,+) -> Result<Option<String>, WasmSpaceError> {+ if activity.message_cipher.trim().is_empty()+ || activity.encrypted_message_key.trim().is_empty()+ || activity.message_id.is_none()+ {+ return Ok(None);+ }++ let message = MessageResponse {+ message_id: activity.message_id.clone().unwrap_or_default(),+ kind: if activity.kind.trim().is_empty() {+ "regular".to_owned()+ } else {+ activity.kind.clone()+ },+ sender_space_id: activity.sender_space_id.clone(),+ recipient_space_id: activity.recipient_space_id.clone(),+ message_cipher: activity.message_cipher.clone(),+ encrypted_message_key: activity.encrypted_message_key.clone(),+ text: String::new(),+ reply_post_id: activity.post_id,+ reply_message_id: activity.reply_message_id.clone(),+ liked: false,+ viewer_liked: false,+ is_deleted: false,+ created_at: activity.created_at.clone(),+ updated_at: activity.created_at.clone(),+ };+ let decrypted = ctx.decrypt_message(viewer_space_id, &message).await?;+ Ok(Some(decrypted.payload.text))+}++async fn message_conversation_activity_to_js(+ ctx: &AccountSpaceCtx,+ viewer_space_id: &str,activity: MessageConversationActivity,-) -> MessageConversationActivityJs {- MessageConversationActivityJs {+) -> Result<MessageConversationActivityJs, WasmSpaceError> {+ let text = message_conversation_activity_text(ctx, viewer_space_id, &activity).await?;+ Ok(MessageConversationActivityJs {id: activity.id,activity_type: activity.activity_type,created_at: activity.created_at,outgoing: activity.outgoing,message_id: activity.message_id,+ text,post_id: activity.post_id,post_space_id: activity.post_space_id,- }+ })}/// Open an authenticated space context for web.@@ -1102,7 +1143,12 @@ impl SpaceAccountCtxHandle {chat_summaries.insert(friend_space_id,ConversationChatSummaryJs {- latest_activity: message_conversation_activity_to_js(summary.latest_activity),+ latest_activity: message_conversation_activity_to_js(+ &self.inner,+ &space_id,+ summary.latest_activity,+ )+ .await?,unread: summary.unread,unread_count: summary.unread_count,notification_unread: summary.notification_unread,diff --git a/rust/space/src/transport.rs b/rust/space/src/transport.rsindex 9caa7f608a..8d7f3112fe 100644--- a/rust/space/src/transport.rs+++ b/rust/space/src/transport.rs@@ -177,12 +177,24 @@ pub struct MessageConversationActivity {pub id: String,#[serde(rename = "type")]pub activity_type: String,+ #[serde(default)]+ pub kind: String,pub created_at: String,#[serde(default)]pub outgoing: bool,#[serde(default)]pub message_id: Option<String>,#[serde(default)]+ pub sender_space_id: String,+ #[serde(default)]+ pub recipient_space_id: String,+ #[serde(default)]+ pub message_cipher: String,+ #[serde(default)]+ pub encrypted_message_key: String,+ #[serde(default)]+ pub reply_message_id: Option<String>,+ #[serde(default)]pub post_id: Option<i64>,#[serde(default)]pub post_space_id: Option<String>,@@ -361,10 +373,17 @@ mod tests {#[test]fn message_conversation_activity_deserializes_outgoing() {let activity: MessageConversationActivity = serde_json::from_str(- r#"{"id":"message:example","type":"message","createdAt":"2026-05-25T00:00:00Z","outgoing":true}"#,+ r#"{"id":"message:example","type":"message","kind":"regular","createdAt":"2026-05-25T00:00:00Z","outgoing":true,"messageId":"message-1","senderSpaceId":"space-a","recipientSpaceId":"space-b","messageCipher":"cipher","encryptedMessageKey":"key","replyMessageId":"parent-1"}"#,).expect("activity should deserialize");assert!(activity.outgoing);+ assert_eq!(activity.kind, "regular");+ assert_eq!(activity.message_id.as_deref(), Some("message-1"));+ assert_eq!(activity.sender_space_id, "space-a");+ assert_eq!(activity.recipient_space_id, "space-b");+ assert_eq!(activity.message_cipher, "cipher");+ assert_eq!(activity.encrypted_message_key, "key");+ assert_eq!(activity.reply_message_id.as_deref(), Some("parent-1"));}#[test]diff --git a/server/space/controller/messages.go b/server/space/controller/messages.goindex cff7b4ceb3..8365d76627 100644--- a/server/space/controller/messages.go+++ b/server/space/controller/messages.go@@ -357,6 +357,25 @@ func toMessageConversationActivityResponse(activity repo.SpaceMessageConversatiomessageID := activity.MessageID.Stringresp.MessageID = &messageID}+ if activity.Kind.Valid {+ resp.Kind = activity.Kind.String+ }+ if activity.SenderSpaceID.Valid {+ resp.SenderSpaceID = activity.SenderSpaceID.String+ }+ if activity.RecipientSpaceID.Valid {+ resp.RecipientSpaceID = activity.RecipientSpaceID.String+ }+ if len(activity.MessageCipher) > 0 {+ resp.MessageCipher = encodeSpaceField(activity.MessageCipher)+ }+ if len(activity.EncryptedMessageKey) > 0 {+ resp.EncryptedMessageKey = encodeSpaceField(activity.EncryptedMessageKey)+ }+ if activity.ReplyMessageID.Valid {+ replyMessageID := activity.ReplyMessageID.String+ resp.ReplyMessageID = &replyMessageID+ }if activity.PostID.Valid {postID := activity.PostID.Int64resp.PostID = &postIDdiff --git a/server/space/models/models.go b/server/space/models/models.goindex 3c881b18ed..6411080214 100644--- a/server/space/models/models.go+++ b/server/space/models/models.go@@ -307,13 +307,19 @@ type MessagePage struct {}type MessageConversationActivityResponse struct {- ID string `json:"id"`- Type string `json:"type"`- CreatedAt string `json:"createdAt"`- Outgoing bool `json:"outgoing,omitempty"`- MessageID *string `json:"messageId,omitempty"`- PostID *int64 `json:"postId,omitempty"`- PostSpaceID string `json:"postSpaceId,omitempty"`+ ID string `json:"id"`+ Type string `json:"type"`+ Kind string `json:"kind,omitempty"`+ CreatedAt string `json:"createdAt"`+ Outgoing bool `json:"outgoing,omitempty"`+ MessageID *string `json:"messageId,omitempty"`+ SenderSpaceID string `json:"senderSpaceId,omitempty"`+ RecipientSpaceID string `json:"recipientSpaceId,omitempty"`+ MessageCipher string `json:"messageCipher,omitempty"`+ EncryptedMessageKey string `json:"encryptedMessageKey,omitempty"`+ ReplyMessageID *string `json:"replyMessageId,omitempty"`+ PostID *int64 `json:"postId,omitempty"`+ PostSpaceID string `json:"postSpaceId,omitempty"`}type ConversationChatSummaryResponse struct {diff --git a/server/space/repo/messages.go b/server/space/repo/messages.goindex 77f7ca7c52..f94c4841d3 100644--- a/server/space/repo/messages.go+++ b/server/space/repo/messages.go@@ -76,6 +76,16 @@ FROM (CASE WHEN m.kind = 'post_like' THEN NULL::text ELSE m.message_id END AS message_id,CASE WHEN m.kind IN ('post_reply', 'post_like') THEN m.reply_post_id ELSE NULL::bigint END AS post_id,CASE WHEN m.kind IN ('post_reply', 'post_like') THEN m.recipient_space_id ELSE NULL::text END AS post_space_id,+ CASE WHEN m.kind IN ('regular', 'post_reply') THEN m.kind ELSE NULL::text END AS message_kind,+ CASE WHEN m.kind IN ('regular', 'post_reply') THEN m.sender_space_id ELSE NULL::text END AS sender_space_id,+ CASE WHEN m.kind IN ('regular', 'post_reply') THEN m.recipient_space_id ELSE NULL::text END AS recipient_space_id,+ CASE WHEN m.kind IN ('regular', 'post_reply') THEN COALESCE(m.message_cipher, '\x'::bytea) ELSE NULL::bytea END AS message_cipher,+ CASE+ WHEN m.kind IN ('regular', 'post_reply') AND m.sender_space_id = $1 THEN COALESCE(m.sender_encrypted_message_key, '\x'::bytea)+ WHEN m.kind IN ('regular', 'post_reply') THEN COALESCE(m.recipient_encrypted_message_key, '\x'::bytea)+ ELSE NULL::bytea+ END AS encrypted_message_key,+ CASE WHEN m.kind IN ('regular', 'post_reply') THEN m.reply_message_id ELSE NULL::text END AS reply_message_id,CASEWHEN m.recipient_space_id = $1 AND m.kind IN ('regular', 'post_reply', 'post_like') THEN m.created_atELSE NULL::bigint@@ -93,6 +103,12 @@ FROM (m.message_id,NULL::bigint AS post_id,NULL::text AS post_space_id,+ NULL::text AS message_kind,+ NULL::text AS sender_space_id,+ NULL::text AS recipient_space_id,+ NULL::bytea AS message_cipher,+ NULL::bytea AS encrypted_message_key,+ NULL::text AS reply_message_id,CASE WHEN m.sender_space_id = $1 THEN m.recipient_liked_at ELSE NULL::bigint END AS notification_created_at,(m.recipient_space_id = $1) AS is_outgoingFROM peer_messages m@@ -150,6 +166,12 @@ conversation_rows AS (latest_activity.message_id,latest_activity.post_id,latest_activity.post_space_id,+ latest_activity.message_kind,+ latest_activity.sender_space_id,+ latest_activity.recipient_space_id,+ latest_activity.message_cipher,+ latest_activity.encrypted_message_key,+ latest_activity.reply_message_id,latest_activity.notification_created_at,latest_activity.is_outgoing,COALESCE(unread_state.unread_count, 0) AS unread_count,@@ -187,6 +209,12 @@ conversation_rows AS (latest_activity.message_id,latest_activity.post_id,latest_activity.post_space_id,+ latest_activity.message_kind,+ latest_activity.sender_space_id,+ latest_activity.recipient_space_id,+ latest_activity.message_cipher,+ latest_activity.encrypted_message_key,+ latest_activity.reply_message_id,latest_activity.notification_created_at,latest_activity.is_outgoing,COALESCE(unread_state.unread_count, 0) AS unread_count,@@ -372,7 +400,13 @@ func (r *MessagesRepository) ListLatestChatSummaries(ctx context.Context, viewerc.notification_unread,c.message_id,c.post_id,- c.post_space_id+ c.post_space_id,+ c.message_kind,+ c.sender_space_id,+ c.recipient_space_id,+ c.message_cipher,+ c.encrypted_message_key,+ c.reply_message_idFROM conversation_rows c`, strings.TrimSpace(viewerSpaceID), pq.Array(cleanFriendSpaceIDs))if err != nil {@@ -427,6 +461,12 @@ func scanConversationChatSummaryRecord(scanner interface{ Scan(dest ...any) erro&rec.LatestActivity.MessageID,&rec.LatestActivity.PostID,&rec.LatestActivity.PostSpaceID,+ &rec.LatestActivity.Kind,+ &rec.LatestActivity.SenderSpaceID,+ &rec.LatestActivity.RecipientSpaceID,+ &rec.LatestActivity.MessageCipher,+ &rec.LatestActivity.EncryptedMessageKey,+ &rec.LatestActivity.ReplyMessageID,}if err := scanner.Scan(dest...); err != nil {return nil, stacktrace.Propagate(err, "")diff --git a/server/space/repo/module.go b/server/space/repo/module.goindex 654fbb9c9b..ec24cd1a7d 100644--- a/server/space/repo/module.go+++ b/server/space/repo/module.go@@ -143,13 +143,19 @@ type SpaceConversationChatSummaryRecord struct {}type SpaceMessageConversationActivityRecord struct {- ID string- Type string- CreatedAt int64- Outgoing bool- MessageID sql.NullString- PostID sql.NullInt64- PostSpaceID sql.NullString+ ID string+ Type string+ Kind sql.NullString+ CreatedAt int64+ Outgoing bool+ MessageID sql.NullString+ SenderSpaceID sql.NullString+ RecipientSpaceID sql.NullString+ MessageCipher []byte+ EncryptedMessageKey []byte+ ReplyMessageID sql.NullString+ PostID sql.NullInt64+ PostSpaceID sql.NullString}type CreateSpaceMessageRecord struct {diff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex 38cb981757..a82ee2fed3 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -182,23 +182,32 @@ const isCurrentProfileActor = (const conversationPreview = (conversation: SpaceMessageConversation) => {const activity = conversation.latestActivity;if (activity.type == "empty") {- return "You are now friends";+ return "You're now friends. Say hello!";}if (activity.type == "friend_request") {return "Friend request";}if (activity.type == "friend_added") {- return "You are now friends";+ return "You're now friends. Say hello!";}if (activity.type == "post_like") {return activity.outgoing ? "You liked a post" : "Liked your post";}+ const text = activity.text ? truncateMessageText(activity.text) : "";if (activity.type == "post_reply") {+ if (text) {+ return activity.outgoing+ ? `You replied: ${text}`+ : `Replied: ${text}`;+ }return "Replied";}if (activity.type == "message_like") {return activity.outgoing ? "You liked a message" : "Liked a message";}+ if (text) {+ return activity.outgoing ? `You: ${text}` : text;+ }return activity.outgoing ? "You sent a message" : "Message";};@@ -1475,6 +1484,10 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({},[activityPostsByKey, onLoadActivityPost],);+ const visibleMessages = React.useMemo(+ () => messages.filter((message) => message.kind != "friend_added"),+ [messages],+ );const messageByID = React.useMemo(() => new Map(messages.map((message) => [message.id, message])),[messages],@@ -1720,10 +1733,10 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({scrollThreadToBottom();}, [isThreadLoading,- messages.length,scheduleThreadBottomScroll,scrollThreadToBottom,selectedFriend,+ visibleMessages.length,]);React.useEffect(@@ -1977,7 +1990,7 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({><SpaceLoadingSpinner ariaLabel="Loading messages" /></Box>- ) : messages.length == 0 ? (+ ) : visibleMessages.length == 0 ? (<Boxsx={{alignItems: "center",@@ -2002,7 +2015,7 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({>{isThreadReadOnly? "No messages"- : "You are now friends"}+ : "Say hello!"}</Box></Box>) : (@@ -2021,12 +2034,16 @@ export const MessagesScreen: React.FC<MessagesScreenProps> = ({| SpaceMessage| undefined;- return messages.map(+ return visibleMessages.map((message, index) => {const previousMessage =- messages[index - 1];+ visibleMessages[+ index - 1+ ];const nextMessage =- messages[index + 1];+ visibleMessages[+ index + 1+ ];const groupsWithPrevious =bodyBubblesCanGroup(previousMessage,diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.tsindex d7443e41ee..eec2b06595 100644--- a/web/apps/space/src/services/space.ts+++ b/web/apps/space/src/services/space.ts@@ -93,6 +93,7 @@ interface SpaceMessageConversationActivity {outgoing?: boolean;postId?: number;postSpaceId?: string;+ text?: string;type: SpaceMessageConversationActivityType;}@@ -256,6 +257,7 @@ export interface SpaceMessageActivity {messageId?: string;outgoing: boolean;post?: SpaceMessageActivityPost;+ text?: string;type: SpaceMessageActivityType;}@@ -744,6 +746,7 @@ const messageActivityFromSpaceActivity = async (messageId: activity.messageId,outgoing: Boolean(activity.outgoing),post,+ text: activity.text?.trim() || undefined,type: activity.type,};};