π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Show post likes in space message threads
Anand Baburajana9b6b8b5faed
diff --git a/rust/bindings/wasm/ente-wasm/src/space.rs b/rust/bindings/wasm/ente-wasm/src/space.rsindex f9fb1baa3f..a2571e8a0f 100644--- a/rust/bindings/wasm/ente-wasm/src/space.rs+++ b/rust/bindings/wasm/ente-wasm/src/space.rs@@ -512,15 +512,81 @@ async fn account_message_to_js(})}+async fn message_response_quote_to_js(+ ctx: &AccountSpaceCtx,+ quote: ente_space::transport::MessageQuoteResponse,+) -> Result<MessageQuoteJs, WasmSpaceError> {+ let caption = if !quote.caption_cipher.trim().is_empty()+ && !quote.encrypted_post_key.trim().is_empty()+ && quote.key_version > 0+ {+ optional_utf8_field(+ ctx.decrypt_post_caption_fields(+ "e.space_id,+ quote.post_id,+ "e.encrypted_post_key,+ quote.key_version,+ "e.caption_cipher,+ )+ .await?,+ "caption",+ )?+ } else {+ None+ };++ Ok(MessageQuoteJs {+ post_id: quote.post_id,+ space_id: quote.space_id,+ encrypted_post_key: (!quote.encrypted_post_key.trim().is_empty())+ .then_some(quote.encrypted_post_key),+ key_version: (quote.key_version > 0).then_some(quote.key_version),+ caption,+ object_key: (!quote.object_key.trim().is_empty()).then_some(quote.object_key),+ width: None,+ height: None,+ media_type: None,+ })+}++async fn account_message_response_to_js(+ ctx: &AccountSpaceCtx,+ message: MessageResponse,+) -> Result<MessageJs, WasmSpaceError> {+ if message.kind != "post_like" {+ let decrypted = ctx.decrypt_message(&message).await?;+ return account_message_to_js(ctx, message, decrypted).await;+ }++ let sender = account_actor_to_js(ctx, message.sender).await?;+ let recipient = account_actor_to_js(ctx, message.recipient).await?;+ let quote = match message.quote {+ Some(quote) => Some(message_response_quote_to_js(ctx, quote).await?),+ None => None,+ };+ Ok(MessageJs {+ message_id: message.message_id,+ kind: message.kind,+ sender,+ recipient,+ text: message.text,+ quote,+ reply_post_id: message.reply_post_id,+ reply_message_id: message.reply_message_id,+ likes: message.likes,+ viewer_liked: message.viewer_liked,+ is_deleted: message.is_deleted,+ created_at: message.created_at,+ updated_at: message.updated_at,+ })+}+async fn message_conversation_activity_to_js(ctx: &AccountSpaceCtx,activity: MessageConversationActivity,) -> Result<MessageConversationActivityJs, WasmSpaceError> {let message = match activity.message {- Some(message) => {- let decrypted = ctx.decrypt_message(&message).await?;- Some(account_message_to_js(ctx, message, decrypted).await?)- }+ Some(message) => Some(account_message_response_to_js(ctx, message).await?),None => None,};Ok(MessageConversationActivityJs {@@ -1098,8 +1164,7 @@ impl SpaceAccountCtxHandle {.await?;let mut items = Vec::with_capacity(page.items.len());for message in page.items {- let decrypted = self.inner.decrypt_message(&message).await?;- items.push(account_message_to_js(&self.inner, message, decrypted).await?);+ items.push(account_message_response_to_js(&self.inner, message).await?);}swb::to_value(&MessagePageJs {items,diff --git a/rust/space/src/client.rs b/rust/space/src/client.rsindex f8608d5b5c..9c94c1b9b5 100644--- a/rust/space/src/client.rs+++ b/rust/space/src/client.rs@@ -905,6 +905,24 @@ impl AccountSpaceCtx {decrypt_secretbox_packed(&space_key, &packed)}+ pub async fn decrypt_post_caption_fields(+ &self,+ space_id: &str,+ post_id: i64,+ encrypted_post_key: &str,+ key_version: i32,+ caption_cipher: &str,+ ) -> Result<Option<Vec<u8>>> {+ if caption_cipher.trim().is_empty() {+ return Ok(None);+ }+ let post_key = self+ .decrypt_post_key_fields(space_id, post_id, encrypted_post_key, key_version)+ .await?;+ let packed = decode_b64(caption_cipher)?;+ Ok(Some(decrypt_secretbox_packed(&post_key, &packed)?))+ }+pub fn decrypt_post(&self, space_key: &[u8], post: &PostResponse) -> Result<DecryptedPost> {let post_key = self.decrypt_post_key(space_key, post)?;let caption_plaintext = if post.caption_cipher.is_empty() {diff --git a/rust/space/src/transport.rs b/rust/space/src/transport.rsindex 6677f41d41..59f43b73e1 100644--- a/rust/space/src/transport.rs+++ b/rust/space/src/transport.rs@@ -164,6 +164,21 @@ pub struct CreateMessageRequest {pub reply_message_id: Option<String>,}+#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct MessageQuoteResponse {+ pub post_id: i64,+ pub space_id: String,+ #[serde(default)]+ pub encrypted_post_key: String,+ #[serde(default)]+ pub caption_cipher: String,+ #[serde(default)]+ pub key_version: i32,+ #[serde(default)]+ pub object_key: String,+}+#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct MessageResponse {@@ -176,6 +191,10 @@ pub struct MessageResponse {#[serde(default)]pub encrypted_message_key: String,#[serde(default)]+ pub text: String,+ #[serde(default)]+ pub quote: Option<MessageQuoteResponse>,+ #[serde(default)]pub reply_post_id: Option<i64>,#[serde(default)]pub reply_message_id: Option<String>,diff --git a/server/space/controller/messages.go b/server/space/controller/messages.goindex de6a042292..0fec3ea4bd 100644--- a/server/space/controller/messages.go+++ b/server/space/controller/messages.go@@ -322,12 +322,25 @@ func toMessageResponse(message repo.SpaceMessageRecord) *models.MessageResponseRecipient: toActorResponse(message.Recipient, true),MessageCipher: message.MessageCipher,EncryptedMessageKey: message.EncryptedMessageKey,+ Text: message.Text,Likes: message.Likes,ViewerLiked: message.ViewerLiked,IsDeleted: message.IsDeleted,CreatedAt: formatMicros(message.CreatedAt),UpdatedAt: formatMicros(message.UpdatedAt),}+ if message.Quote != nil {+ resp.Quote = &models.MessageQuoteResponse{+ PostID: message.Quote.PostID,+ SpaceID: message.Quote.SpaceID,+ EncryptedPostKey: message.Quote.EncryptedPostKey,+ CaptionCipher: message.Quote.CaptionCipher,+ KeyVersion: message.Quote.KeyVersion,+ }+ if message.Quote.ObjectKey.Valid {+ resp.Quote.ObjectKey = message.Quote.ObjectKey.String+ }+ }if message.ReplyPostID.Valid {replyPostID := message.ReplyPostID.Int64resp.ReplyPostID = &replyPostIDdiff --git a/server/space/models/models.go b/server/space/models/models.goindex 272188ac9d..8f4d10646e 100644--- a/server/space/models/models.go+++ b/server/space/models/models.go@@ -325,19 +325,30 @@ type LikeMessageResponse struct {}type MessageResponse struct {- MessageID string `json:"messageId"`- Kind string `json:"kind"`- Sender SpaceActorResponse `json:"sender"`- Recipient SpaceActorResponse `json:"recipient"`- MessageCipher string `json:"messageCipher,omitempty"`- EncryptedMessageKey string `json:"encryptedMessageKey,omitempty"`- ReplyPostID *int64 `json:"replyPostId,omitempty"`- ReplyMessageID *string `json:"replyMessageId,omitempty"`- Likes int64 `json:"likes"`- ViewerLiked bool `json:"viewerLiked"`- IsDeleted bool `json:"isDeleted"`- CreatedAt string `json:"createdAt"`- UpdatedAt string `json:"updatedAt"`+ MessageID string `json:"messageId"`+ Kind string `json:"kind"`+ Sender SpaceActorResponse `json:"sender"`+ Recipient SpaceActorResponse `json:"recipient"`+ MessageCipher string `json:"messageCipher,omitempty"`+ EncryptedMessageKey string `json:"encryptedMessageKey,omitempty"`+ Text string `json:"text,omitempty"`+ Quote *MessageQuoteResponse `json:"quote,omitempty"`+ ReplyPostID *int64 `json:"replyPostId,omitempty"`+ ReplyMessageID *string `json:"replyMessageId,omitempty"`+ Likes int64 `json:"likes"`+ ViewerLiked bool `json:"viewerLiked"`+ IsDeleted bool `json:"isDeleted"`+ CreatedAt string `json:"createdAt"`+ UpdatedAt string `json:"updatedAt"`+}++type MessageQuoteResponse struct {+ PostID int64 `json:"postId"`+ SpaceID string `json:"spaceId"`+ EncryptedPostKey string `json:"encryptedPostKey,omitempty"`+ CaptionCipher string `json:"captionCipher,omitempty"`+ KeyVersion int `json:"keyVersion,omitempty"`+ ObjectKey string `json:"objectKey,omitempty"`}type MessagePage struct {diff --git a/server/space/repo/messages.go b/server/space/repo/messages.goindex db749f32ab..e46ab98b05 100644--- a/server/space/repo/messages.go+++ b/server/space/repo/messages.go@@ -3,6 +3,7 @@ package repoimport ("context""database/sql"+ "sort""strconv""strings"@@ -29,6 +30,13 @@ const spaceMessageSelectColumns = `m.is_deleted,m.created_at,m.updated_at,+ '' AS text,+ NULL::bigint AS quote_post_id,+ '' AS quote_space_id,+ '' AS quote_encrypted_post_key,+ '' AS quote_caption_cipher,+ 0 AS quote_key_version,+ NULL::text AS quote_object_key,sender_space.owner_id,sender_space.space_id,sender_space.space_slug,@@ -143,6 +151,17 @@ func (r *MessagesRepository) ListThread(ctx context.Context, viewerID int64, vieif err := rows.Err(); err != nil {return nil, "", stacktrace.Propagate(err, "")}+ postLikes, err := r.listThreadPostLikes(ctx, viewerID, viewerSpaceID, otherSpaceID, cursor, limit+1)+ if err != nil {+ return nil, "", err+ }+ out = append(out, postLikes...)+ sort.Slice(out, func(i, j int) bool {+ if out[i].CreatedAt != out[j].CreatedAt {+ return out[i].CreatedAt > out[j].CreatedAt+ }+ return out[i].MessageID > out[j].MessageID+ })nextCursor := ""if len(out) > limit {nextCursor = formatMessageCursor(out[limit-1])@@ -151,6 +170,97 @@ func (r *MessagesRepository) ListThread(ctx context.Context, viewerID int64, viereturn out, nextCursor, nil}+func (r *MessagesRepository) listThreadPostLikes(ctx context.Context, viewerID int64, viewerSpaceID string, otherSpaceID string, cursor string, limit int) ([]SpaceMessageRecord, error) {+ args := []any{viewerID, viewerSpaceID, otherSpaceID}+ query := `+ SELECT+ 'post_like:' || p.post_id::text || ':' || pl.actor_space_id AS message_id,+ 'post_like' AS kind,+ pl.user_id AS sender_id,+ pl.actor_space_id AS sender_space_id,+ p.owner_id AS recipient_id,+ p.space_id AS recipient_space_id,+ '' AS message_cipher,+ '' AS encrypted_message_key,+ NULL::bigint AS reply_post_id,+ NULL::text AS reply_message_id,+ 0 AS likes,+ FALSE AS viewer_liked,+ FALSE AS is_deleted,+ pl.created_at,+ pl.created_at AS updated_at,+ CASE WHEN pl.actor_space_id = $2 THEN 'You liked a post' ELSE 'Liked your post' END AS text,+ p.post_id AS quote_post_id,+ p.space_id AS quote_space_id,+ p.encrypted_post_key AS quote_encrypted_post_key,+ p.caption_cipher AS quote_caption_cipher,+ p.key_version AS quote_key_version,+ asset.object_key AS quote_object_key,+ sender_space.owner_id,+ sender_space.space_id,+ sender_space.space_slug,+ sender_space.public_key,+ sender_space.current_version,+ sender_space.encrypted_profile,+ sender_space.avatar_object_key,+ sender_space.avatar_size,+ sender_space.updated_at,+ (SELECT COUNT(*) FROM space_friend_shares fs WHERE fs.space_id = sender_space.space_id) AS sender_friends,+ (SELECT COUNT(*) FROM space_posts sp WHERE sp.space_id = sender_space.space_id AND sp.is_deleted = FALSE) AS sender_posts,+ recipient_space.owner_id,+ recipient_space.space_id,+ recipient_space.space_slug,+ recipient_space.public_key,+ recipient_space.current_version,+ recipient_space.encrypted_profile,+ recipient_space.avatar_object_key,+ recipient_space.avatar_size,+ recipient_space.updated_at,+ (SELECT COUNT(*) FROM space_friend_shares fs WHERE fs.space_id = recipient_space.space_id) AS recipient_friends,+ (SELECT COUNT(*) FROM space_posts rp WHERE rp.space_id = recipient_space.space_id AND rp.is_deleted = FALSE) AS recipient_posts+ FROM space_post_likes pl+ JOIN space_posts p ON p.post_id = pl.post_id+ JOIN spaces sender_space ON sender_space.space_id = pl.actor_space_id+ JOIN spaces recipient_space ON recipient_space.space_id = p.space_id+ LEFT JOIN LATERAL (+ SELECT object_key+ FROM space_post_assets+ WHERE post_id = p.post_id AND p.is_deleted = FALSE+ ORDER BY position ASC, asset_id ASC+ LIMIT 1+ ) asset ON TRUE+ WHERE (+ (pl.actor_space_id = $2 AND p.space_id = $3)+ OR+ (pl.actor_space_id = $3 AND p.space_id = $2)+ )+ AND (pl.user_id = $1 OR p.owner_id = $1)+ AND p.is_deleted = FALSE`+ if cursorCreatedAt, cursorMessageID, ok := parseMessageCursor(cursor); ok {+ args = append(args, cursorCreatedAt, cursorMessageID)+ query += ` AND (pl.created_at, 'post_like:' || p.post_id::text || ':' || pl.actor_space_id) < ($4, $5)`+ }+ args = append(args, limit)+ query += ` ORDER BY pl.created_at DESC, message_id DESC LIMIT $` + strconv.Itoa(len(args))+ rows, err := r.DB.QueryContext(ctx, query, args...)+ if err != nil {+ return nil, stacktrace.Propagate(err, "")+ }+ defer rows.Close()+ out := make([]SpaceMessageRecord, 0, limit)+ for rows.Next() {+ rec, err := scanMessageRecord(rows)+ if err != nil {+ return nil, err+ }+ out = append(out, *rec)+ }+ if err := rows.Err(); err != nil {+ return nil, stacktrace.Propagate(err, "")+ }+ return out, nil+}+func (r *MessagesRepository) SetLike(ctx context.Context, messageID string, userID int64, actorSpaceID string, like bool) error {if like {_, err := r.DB.ExecContext(ctx, `INSERT INTO space_message_likes (message_id, user_id, actor_space_id) VALUES ($1, $2, $3) ON CONFLICT DO NOTHING`, messageID, userID, actorSpaceID)@@ -205,7 +315,7 @@ func (r *MessagesRepository) ListConversations(ctx context.Context, viewerID intm.created_at AS activity_created_at,CASE WHEN m.sender_space_id = $2 THEN m.recipient_space_id ELSE m.sender_space_id END AS friend_space_id,m.message_id,- NULL::bigint AS post_id,+ CASE WHEN m.kind = 'post_reply' THEN m.reply_post_id ELSE NULL::bigint END AS post_id,CASE WHEN m.recipient_space_id = $2 THEN m.created_at ELSE NULL::bigint END AS notification_created_at,FALSE AS is_outgoingFROM space_messages m@@ -232,12 +342,32 @@ func (r *MessagesRepository) ListConversations(ctx context.Context, viewerID intAND m.recipient_space_id = ml.actor_space_idAND ml.actor_space_id <> $2AND m.is_deleted = FALSE++ UNION ALL++ SELECT+ 'message_like' AS activity_type,+ 'message_like:' || ml.message_id || ':' || ml.actor_space_id AS activity_id,+ ml.created_at AS activity_created_at,+ m.sender_space_id AS friend_space_id,+ m.message_id,+ NULL::bigint AS post_id,+ NULL::bigint AS notification_created_at,+ TRUE AS is_outgoing+ FROM space_message_likes ml+ JOIN space_messages m ON m.message_id = ml.message_id+ WHERE ml.actor_space_id = $2+ AND m.recipient_space_id = $2+ AND m.sender_space_id <> $2+ AND m.is_deleted = FALSE),post_like_events AS (SELECTactor_space.space_id AS friend_space_id,p.post_id,- MAX(pl.created_at) AS liked_at+ MAX(pl.created_at) AS liked_at,+ MAX(pl.created_at) AS notification_created_at,+ FALSE AS is_outgoingFROM space_post_likes plJOIN space_posts p ON p.post_id = pl.post_idJOIN spaces actor_space ON actor_space.space_id = pl.actor_space_id@@ -245,6 +375,21 @@ func (r *MessagesRepository) ListConversations(ctx context.Context, viewerID intAND pl.actor_space_id <> $2AND p.is_deleted = FALSEGROUP BY actor_space.space_id, p.post_id++ UNION ALL++ SELECT+ p.space_id AS friend_space_id,+ p.post_id,+ MAX(pl.created_at) AS liked_at,+ NULL::bigint AS notification_created_at,+ TRUE AS is_outgoing+ FROM space_post_likes pl+ JOIN space_posts p ON p.post_id = pl.post_id+ WHERE pl.actor_space_id = $2+ AND p.space_id <> $2+ AND p.is_deleted = FALSE+ GROUP BY p.space_id, p.post_id),post_reply_events AS (SELECT DISTINCT ON (m.sender_space_id, m.reply_post_id)@@ -270,8 +415,8 @@ func (r *MessagesRepository) ListConversations(ctx context.Context, viewerID intl.friend_space_id,NULL::text AS message_id,l.post_id,- l.liked_at AS notification_created_at,- FALSE AS is_outgoing+ l.notification_created_at,+ l.is_outgoingFROM post_like_events l),post_reply_candidates AS (@@ -347,6 +492,22 @@ func (r *MessagesRepository) ListConversations(ctx context.Context, viewerID intWHERE ra.readable_created_at > COALESCE(nrm.read_at, 0)GROUP BY ra.friend_space_id),+ post_like_unread_counts AS (+ SELECT+ actor_space.space_id AS friend_space_id,+ COUNT(*) AS unread_count+ FROM space_post_likes pl+ JOIN space_posts p ON p.post_id = pl.post_id+ JOIN spaces actor_space ON actor_space.space_id = pl.actor_space_id+ LEFT JOIN space_notification_read_markers nrm+ ON nrm.viewer_space_id = $2+ AND nrm.friend_space_id = actor_space.space_id+ WHERE p.space_id = $2+ AND pl.actor_space_id <> $2+ AND p.is_deleted = FALSE+ AND pl.created_at > COALESCE(nrm.read_at, 0)+ GROUP BY actor_space.space_id+ ),latest_activities AS (SELECT DISTINCT ON (friend_space_id)friend_space_id,@@ -360,6 +521,7 @@ func (r *MessagesRepository) ListConversations(ctx context.Context, viewerID intc.*,COALESCE(nrm.read_at, 0) AS read_at,COALESCE(ruc.unread_count, 0) AS unread_count,+ COALESCE(pluc.unread_count, 0) AS post_like_unread_count,la.sort_created_at,la.sort_id,(@@ -373,12 +535,17 @@ func (r *MessagesRepository) ListConversations(ctx context.Context, viewerID intAND nrm.friend_space_id = c.friend_space_idLEFT JOIN readable_unread_counts rucON ruc.friend_space_id = c.friend_space_id+ LEFT JOIN post_like_unread_counts pluc+ ON pluc.friend_space_id = c.friend_space_id),ranked AS (SELECTc.*,(c.unread_count > 0) AS conversation_unread,- c.unread_count AS conversation_unread_count,+ CASE+ WHEN c.unread_count > 0 THEN c.unread_count + c.post_like_unread_count+ ELSE 0+ END AS conversation_unread_count,BOOL_OR(c.notification_unread) OVER (PARTITION BY c.friend_space_id) AS conversation_notification_unread,ROW_NUMBER() OVER (PARTITION BY c.friend_space_id@@ -528,6 +695,19 @@ func (r *MessagesRepository) GetLatestConversationActivityAt(ctx context.ContextUNION ALL+ SELECT+ ml.created_at AS activity_created_at,+ 'message_like:' || ml.message_id || ':' || ml.actor_space_id AS activity_id,+ m.sender_space_id AS friend_space_id+ FROM space_message_likes ml+ JOIN space_messages m ON m.message_id = ml.message_id+ WHERE ml.actor_space_id = $1+ AND m.recipient_space_id = $1+ AND m.sender_space_id <> $1+ AND m.is_deleted = FALSE++ UNION ALL+SELECTpl.created_at AS activity_created_at,'post_like:' || pl.post_id::text || ':' || pl.actor_space_id AS activity_id,@@ -541,6 +721,18 @@ func (r *MessagesRepository) GetLatestConversationActivityAt(ctx context.ContextUNION ALL+ SELECT+ pl.created_at AS activity_created_at,+ 'post_like:' || pl.post_id::text || ':' || p.space_id AS activity_id,+ p.space_id AS friend_space_id+ FROM space_post_likes pl+ JOIN space_posts p ON p.post_id = pl.post_id+ WHERE pl.actor_space_id = $1+ AND p.space_id <> $1+ AND p.is_deleted = FALSE++ UNION ALL+SELECTm.created_at AS activity_created_at,'post_reply:' || m.message_id AS activity_id,@@ -674,12 +866,27 @@ func scanMessageRecord(scanner interface{ Scan(dest ...any) error }) (*SpaceMess&rec.IsDeleted,&rec.CreatedAt,&rec.UpdatedAt,+ &rec.Text,}+ var quote SpaceMessageQuoteRecord+ var quotePostID sql.NullInt64+ dest = append(dest,+ "ePostID,+ "e.SpaceID,+ "e.EncryptedPostKey,+ "e.CaptionCipher,+ "e.KeyVersion,+ "e.ObjectKey,+ )dest = append(dest, spaceActorScanDest(&rec.Sender)...)dest = append(dest, spaceActorScanDest(&rec.Recipient)...)if err := scanner.Scan(dest...); err != nil {return nil, stacktrace.Propagate(err, "")}+ if quotePostID.Valid {+ quote.PostID = quotePostID.Int64+ rec.Quote = "e+ }return &rec, nil}diff --git a/server/space/repo/module.go b/server/space/repo/module.goindex dc094712d9..aa201146f8 100644--- a/server/space/repo/module.go+++ b/server/space/repo/module.go@@ -146,12 +146,23 @@ type SpaceMessageRecord struct {Likes int64ViewerLiked boolIsDeleted bool+ Text string+ Quote *SpaceMessageQuoteRecordCreatedAt int64UpdatedAt int64Sender SpaceActorRecordRecipient SpaceActorRecord}+type SpaceMessageQuoteRecord struct {+ PostID int64+ SpaceID string+ EncryptedPostKey string+ CaptionCipher string+ KeyVersion int+ ObjectKey sql.NullString+}+type SpaceMessageConversationRecord struct {Friend SpaceActorRecordLatestActivity SpaceMessageConversationActivityRecorddiff --git a/server/space/repo/module_test.go b/server/space/repo/module_test.goindex a0a2087f4c..21bf6bdeba 100644--- a/server/space/repo/module_test.go+++ b/server/space/repo/module_test.go@@ -248,7 +248,8 @@ func TestSpaceMessageConversationsUseLatestActivity(t *testing.T) {conversations, _, err = module.Messages.ListConversations(ctx, aliceID, aliceSpace.SpaceID, "", 10)require.NoError(t, err)require.Equal(t, "message_like", conversations[0].LatestActivity.Type)- require.Equal(t, aliceMessage.MessageID, conversations[0].LatestActivity.Message.MessageID)+ require.True(t, conversations[0].LatestActivity.Outgoing)+ require.Equal(t, bobMessage.MessageID, conversations[0].LatestActivity.Message.MessageID)postID, err := module.Posts.CreatePost(ctx, aliceID, aliceSpace.SpaceID, "post-key", nil, aliceSpace.CurrentVersion, nil)require.NoError(t, err)@@ -1612,10 +1613,34 @@ func TestUnreadNotificationsTrackReadableActivityWithoutChangingLatestPreview(trequire.NoError(t, err)require.False(t, notificationsUnread)+ require.NoError(t, module.Messages.SetLike(ctx, incoming.MessageID, aliceID, aliceSpace.SpaceID, true))+ setMessageLikeCreatedAt(t, module, 2500, incoming.MessageID, aliceSpace.SpaceID)++ conversations, _, err = module.Messages.ListConversations(ctx, aliceID, aliceSpace.SpaceID, "", 10)+ require.NoError(t, err)+ require.Equal(t, "message_like", conversations[0].LatestActivity.Type)+ require.True(t, conversations[0].LatestActivity.Outgoing)+ require.Equal(t, incoming.MessageID, conversations[0].LatestActivity.Message.MessageID)+ require.Equal(t, int64(2500), conversations[0].SortCreatedAt)+ require.False(t, conversations[0].Unread)+ require.Equal(t, int64(0), conversations[0].UnreadCount)+ require.False(t, conversations[0].NotificationUnread)+ notificationsUnread, err = module.Messages.HasUnreadNotifications(ctx, aliceID, aliceSpace.SpaceID)+ require.NoError(t, err)+ require.False(t, notificationsUnread)+ latestActivityAt, err = module.Messages.GetLatestConversationActivityAt(ctx, aliceID, aliceSpace.SpaceID, bobSpace.SpaceID)+ require.NoError(t, err)+ require.Equal(t, int64(2500), latestActivityAt)+alicePostID, err := module.Posts.CreatePost(ctx, aliceID, aliceSpace.SpaceID, "alice-post-key", nil, aliceSpace.CurrentVersion, nil)require.NoError(t, err)bobPostID, err := module.Posts.CreatePost(ctx, bobID, bobSpace.SpaceID, "bob-post-key", nil, bobSpace.CurrentVersion, nil)require.NoError(t, err)+ _, err = module.Posts.DB.Exec(`+ INSERT INTO space_post_assets (post_id, object_key, bucket_id, metadata_cipher)+ VALUES ($1, $2, $3, $4)+ `, bobPostID, "bob-post-object", "bucket", "metadata")+ require.NoError(t, err)require.NoError(t, module.Posts.SetLike(ctx, alicePostID, bobID, bobSpace.SpaceID, true))setPostLikeCreatedAt(t, module, 3000, alicePostID, bobSpace.SpaceID)outgoingPostReply, err := module.Messages.CreateMessage(ctx, CreateSpaceMessageRecord{@@ -1636,6 +1661,9 @@ func TestUnreadNotificationsTrackReadableActivityWithoutChangingLatestPreview(trequire.NoError(t, err)require.Equal(t, "message", conversations[0].LatestActivity.Type)require.Equal(t, outgoingPostReply.MessageID, conversations[0].LatestActivity.Message.MessageID)+ require.NotNil(t, conversations[0].LatestActivity.Post)+ require.Equal(t, bobPostID, conversations[0].LatestActivity.Post.PostID)+ require.Equal(t, "bob-post-object", conversations[0].LatestActivity.Post.ObjectKey.String)require.Equal(t, int64(4000), conversations[0].SortCreatedAt)require.False(t, conversations[0].Unread)require.Equal(t, int64(0), conversations[0].UnreadCount)@@ -1644,6 +1672,39 @@ func TestUnreadNotificationsTrackReadableActivityWithoutChangingLatestPreview(trequire.NoError(t, err)require.True(t, notificationsUnread)+ require.NoError(t, module.Posts.SetLike(ctx, bobPostID, aliceID, aliceSpace.SpaceID, true))+ setPostLikeCreatedAt(t, module, 4500, bobPostID, aliceSpace.SpaceID)++ conversations, _, err = module.Messages.ListConversations(ctx, aliceID, aliceSpace.SpaceID, "", 10)+ require.NoError(t, err)+ require.Equal(t, "post_like", conversations[0].LatestActivity.Type)+ require.True(t, conversations[0].LatestActivity.Outgoing)+ require.NotNil(t, conversations[0].LatestActivity.Post)+ require.Equal(t, bobPostID, conversations[0].LatestActivity.Post.PostID)+ require.Equal(t, "bob-post-object", conversations[0].LatestActivity.Post.ObjectKey.String)+ require.Equal(t, int64(4500), conversations[0].SortCreatedAt)+ require.False(t, conversations[0].Unread)+ require.Equal(t, int64(0), conversations[0].UnreadCount)+ require.True(t, conversations[0].NotificationUnread)+ latestActivityAt, err = module.Messages.GetLatestConversationActivityAt(ctx, aliceID, aliceSpace.SpaceID, bobSpace.SpaceID)+ require.NoError(t, err)+ require.Equal(t, int64(4500), latestActivityAt)++ thread, _, err := module.Messages.ListThread(ctx, aliceID, aliceSpace.SpaceID, bobSpace.SpaceID, "", 10)+ require.NoError(t, err)+ require.GreaterOrEqual(t, len(thread), 3)+ require.Equal(t, "post_like", thread[0].Kind)+ require.Equal(t, "You liked a post", thread[0].Text)+ require.NotNil(t, thread[0].Quote)+ require.Equal(t, bobPostID, thread[0].Quote.PostID)+ require.Equal(t, "bob-post-object", thread[0].Quote.ObjectKey.String)+ require.Equal(t, "post_reply", thread[1].Kind)+ require.Equal(t, outgoingPostReply.MessageID, thread[1].MessageID)+ require.Equal(t, "post_like", thread[2].Kind)+ require.Equal(t, "Liked your post", thread[2].Text)+ require.NotNil(t, thread[2].Quote)+ require.Equal(t, alicePostID, thread[2].Quote.PostID)+incomingPostReply, err := module.Messages.CreateMessage(ctx, CreateSpaceMessageRecord{Kind: "post_reply",SenderID: bobID,@@ -1677,7 +1738,7 @@ func TestUnreadNotificationsTrackReadableActivityWithoutChangingLatestPreview(trequire.Equal(t, secondIncomingPostReply.MessageID, conversations[0].LatestActivity.Message.MessageID)require.Equal(t, int64(5001), conversations[0].SortCreatedAt)require.True(t, conversations[0].Unread)- require.Equal(t, int64(2), conversations[0].UnreadCount)+ require.Equal(t, int64(3), conversations[0].UnreadCount)require.True(t, conversations[0].NotificationUnread)notificationsUnread, err = module.Messages.HasUnreadNotifications(ctx, aliceID, aliceSpace.SpaceID)require.NoError(t, err)@@ -1691,7 +1752,7 @@ func TestUnreadNotificationsTrackReadableActivityWithoutChangingLatestPreview(trequire.Equal(t, alicePostID, conversations[0].LatestActivity.Post.PostID)require.Equal(t, int64(6000), conversations[0].SortCreatedAt)require.True(t, conversations[0].Unread)- require.Equal(t, int64(2), conversations[0].UnreadCount)+ require.Equal(t, int64(3), conversations[0].UnreadCount)require.True(t, conversations[0].NotificationUnread)notificationsUnread, err = module.Messages.HasUnreadNotifications(ctx, aliceID, aliceSpace.SpaceID)require.NoError(t, err)diff --git a/web/apps/space/src/screens/MessagesScreen.tsx b/web/apps/space/src/screens/MessagesScreen.tsxindex 070eebe8e7..533cf9ac80 100644--- a/web/apps/space/src/screens/MessagesScreen.tsx+++ b/web/apps/space/src/screens/MessagesScreen.tsx@@ -167,6 +167,9 @@ const Avatar: React.FC<{ avatarUrl?: string | null; size: number }> = ({);const messagePreview = (message: SpaceMessage) => {+ if (message.kind == "post_like") {+ return message.text;+ }if (message.kind == "post_reply") {return message.text || "Replied to a post";}@@ -238,15 +241,19 @@ const conversationPreview = (? "You're no longer friends": "Removed you as a friend";}- if (activity.type == "post_like") return "Liked your post";+ if (activity.type == "post_like") {+ return activity.outgoing ? "You liked a post" : "Liked your post";+ }if (activity.type == "post_reply") {return "Replied";}if (activity.type == "message_like") {const text = activity.message?.text.trim();return text- ? `Liked "${truncateMessageText(text)}"`- : "Liked a message";+ ? `${activity.outgoing ? "You liked" : "Liked"} "${truncateMessageText(text)}"`+ : activity.outgoing+ ? "You liked a message"+ : "Liked a message";}const message = activity.message;@@ -265,10 +272,14 @@ const quotedConversationActivityPreview = (const previewText = truncateMessageText(text);if (activity.type == "message_like") {- return { prefix: 'Liked "', previewText, suffix: '"' };+ return {+ prefix: activity.outgoing ? 'You liked "' : 'Liked "',+ previewText,+ suffix: '"',+ };}if (activity.type == "post_reply") {- return { prefix: 'Replied "', previewText, suffix: '"' };+ return { prefix: "", previewText, suffix: "" };}return undefined;};@@ -727,7 +738,8 @@ const QuotePreview: React.FC<{message: SpaceMessage;onOpenQuotePost: (quote: SpaceMessageQuote) => void;}> = ({ isOwn, message, onOpenQuotePost }) => {- if (message.kind != "post_reply") return null;+ if (message.kind != "post_like" && message.kind != "post_reply")+ return null;const quote = message.quote;const isUnavailable = !quote || quote.isUnavailable || !quote.imageUrl;const canOpen = Boolean(quote && !isUnavailable);@@ -963,8 +975,12 @@ const MessageBubble: React.FC<{: isLastInSequence? "6px 20px 20px 20px": "6px 20px 20px 6px";+ const isSyntheticPostLike = message.kind == "post_like";const hasMessageReply = Boolean(message.replyMessageId);- const hasInlinePreview = message.kind == "post_reply" || hasMessageReply;+ const hasInlinePreview =+ message.kind == "post_like" ||+ message.kind == "post_reply" ||+ hasMessageReply;const [isLikeTooltipOpen, setIsLikeTooltipOpen] = React.useState(false);const likeTooltipTimerRef = React.useRef<number | undefined>(undefined);const longPressTimerRef = React.useRef<number | undefined>(undefined);@@ -1005,21 +1021,27 @@ const MessageBubble: React.FC<{const openActions = React.useCallback((bubbleElement: HTMLElement, source: MessageActionsOpenSource) => {+ if (isSyntheticPostLike) return;clearLongPressTimer();longPressStartRef.current = undefined;window.getSelection()?.removeAllRanges();onOpenActions(message, bubbleElement, source);},- [clearLongPressTimer, message, onOpenActions],+ [clearLongPressTimer, isSyntheticPostLike, message, onOpenActions],);const handleContextMenu = (event: React.MouseEvent<HTMLElement>) => {+ if (isSyntheticPostLike) return;event.preventDefault();event.stopPropagation();openActions(event.currentTarget, "contextmenu");};const handleTouchStart = (event: React.TouchEvent<HTMLElement>) => {+ if (isSyntheticPostLike) {+ cancelLongPress();+ return;+ }if (event.touches.length != 1 ||isMessageLongPressIgnoredTarget(event.target)@@ -1113,7 +1135,7 @@ const MessageBubble: React.FC<{color: isOwn? outgoingMessageText: incomingMessageText,- cursor: "context-menu",+ cursor: isSyntheticPostLike ? "default" : "context-menu",display: "block",maxWidth: "100%",minWidth: 0,diff --git a/web/apps/space/src/services/space.ts b/web/apps/space/src/services/space.tsindex 5226ab269a..df2689f49a 100644--- a/web/apps/space/src/services/space.ts+++ b/web/apps/space/src/services/space.ts@@ -118,7 +118,7 @@ interface SpaceFriend {shareKeyVersion: number;}-type SpaceMessageKindResponse = "post_reply" | "regular";+type SpaceMessageKindResponse = "post_like" | "post_reply" | "regular";interface SpaceMessageQuoteResponse {caption?: string;