Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Hydrate wall social actors

Anand Baburajan5fd4dcf0c592
diff --git a/rust/e2e/tests/wall_e2e.rs b/rust/e2e/tests/wall_e2e.rs
index 096a6685d8..54fa26f5fa 100644
--- a/rust/e2e/tests/wall_e2e.rs
+++ b/rust/e2e/tests/wall_e2e.rs
@@ -1,6 +1,6 @@
mod support;
-use ente_wall::{OpenWallLinkCtxInput, WallLinkCtx};
+use ente_wall::{OpenWallLinkCtxInput, WallLinkCtx, WallNotificationType};
use support::{auth, wall};
@@ -182,6 +182,16 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {
.expect("feed should load after friend approval");
assert_eq!(feed.items.len(), 1);
assert_eq!(feed.items[0].post_id, post_id);
+ assert_eq!(feed.items[0].author.wall_id, owner_wall.wall_id);
+ assert_eq!(feed.items[0].author.wall_slug, updated_slug);
+ let feed_author_profile = friend_ctx
+ .decrypt_actor_profile(&feed.items[0].author)
+ .await
+ .expect("friend should decrypt feed author profile");
+ assert_eq!(
+ feed_author_profile.as_deref(),
+ Some(updated_profile.as_slice())
+ );
let feed_post = friend_ctx
.decrypt_feed_item(&feed.items[0])
.await
@@ -196,6 +206,21 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {
.await
.expect("liking post should succeed");
assert!(liked.liked);
+ let likers = owner_ctx
+ .list_post_likers(post_id, None, Some(10))
+ .await
+ .expect("post likers should load");
+ assert_eq!(likers.likers.len(), 1);
+ assert_eq!(likers.likers[0].actor.wall_id, friend_wall.wall_id);
+ assert_eq!(likers.likers[0].actor.wall_slug, friend_slug);
+ let liker_profile = owner_ctx
+ .decrypt_actor_profile(&likers.likers[0].actor)
+ .await
+ .expect("owner should decrypt liker profile");
+ assert_eq!(
+ liker_profile.as_deref(),
+ Some(friend_profile_payload.as_slice())
+ );
let top_level = friend_ctx
.create_comment(post_id, &post_key, b"looks great", None)
.await
@@ -210,6 +235,8 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {
.await
.expect("comments should load");
assert_eq!(comments.comments.len(), 2);
+ assert_eq!(comments.comments[1].author.wall_id, friend_wall.wall_id);
+ assert_eq!(comments.comments[0].author.wall_id, owner_wall.wall_id);
let parent = friend_ctx
.decrypt_comment(&post_key, &comments.comments[1])
.expect("parent comment should decrypt");
@@ -219,6 +246,26 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {
assert_eq!(parent.plaintext, b"looks great");
assert_eq!(reply.plaintext, b"thanks");
+ let notifications = owner_ctx
+ .list_notifications(None, Some(10))
+ .await
+ .expect("owner notifications should load");
+ let liked_notification = notifications
+ .items
+ .iter()
+ .find(|item| item.notification_type == WallNotificationType::LikedPost)
+ .expect("liked post notification should exist");
+ assert_eq!(liked_notification.actor.wall_id, friend_wall.wall_id);
+ assert_eq!(
+ liked_notification
+ .post
+ .as_ref()
+ .expect("liked post notification should include post")
+ .author
+ .wall_id,
+ owner_wall.wall_id
+ );
+
wall::assert_http_status(outsider_ctx.fetch_post_decrypted(post_id).await, 403);
let link_profile = link_ctx
@@ -231,6 +278,15 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {
.await
.expect("link session should list posts");
assert_eq!(link_posts.items.len(), 1);
+ assert_eq!(link_posts.items[0].author.wall_id, owner_wall.wall_id);
+ let link_author_profile = link_ctx
+ .decrypt_actor_profile(&link_posts.items[0].author)
+ .await
+ .expect("link should decrypt owner actor profile");
+ assert_eq!(
+ link_author_profile.as_deref(),
+ Some(updated_profile.as_slice())
+ );
assert!(link_posts.next_cursor.is_empty());
let link_post = link_ctx
.decrypt_post(&link_posts.items[0])
@@ -245,6 +301,9 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {
.await
.expect("link session should list comments");
assert_eq!(link_comments.comments.len(), 2);
+ assert_eq!(link_comments.comments[0].author.wall_id, owner_wall.wall_id);
+ assert!(link_comments.comments[1].author.wall_id.is_empty());
+ assert_eq!(link_comments.comments[1].author.wall_slug, friend_slug);
let link_parent = link_ctx
.decrypt_comment(&link_post.post_key, &link_comments.comments[1])
.expect("link session should decrypt parent comment");
diff --git a/rust/wall/src/client.rs b/rust/wall/src/client.rs
index 5b560ab31a..7d8773efed 100644
--- a/rust/wall/src/client.rs
+++ b/rust/wall/src/client.rs
@@ -21,9 +21,9 @@ use crate::transport::{
PostObjectPayload, PostPage, PostResponse, PresignUploadRequest, PresignUploadResponse,
ProfileAvatarPayload, RefreshFriendSharesRequest, RotateWallKeyRequest, ShareUpdatePayload,
UpdatePostCaptionRequest, UpdateWallProfileRequest, UpdateWallProfileResponse,
- UpdateWallSlugRequest, WallFriendResponse, WallKeyResponse, WallKeyVersionResponse,
- WallLinkCreateRequest, WallLinkLoginRequest, WallLinkLoginResponse, WallLinkStatusResponse,
- WallLookupResponse, WallNotificationPage, WallProfileResponse,
+ UpdateWallSlugRequest, WallActorResponse, WallFriendResponse, WallKeyResponse,
+ WallKeyVersionResponse, WallLinkCreateRequest, WallLinkLoginRequest, WallLinkLoginResponse,
+ WallLinkStatusResponse, WallLookupResponse, WallNotificationPage, WallProfileResponse,
};
use ente_core::crypto::{sealed, secretbox};
use ente_core::http::{Error as HttpError, HttpClient, HttpConfig};
@@ -711,6 +711,28 @@ impl AccountWallCtx {
self.decrypt_post(&wall_key, post)
}
+ pub async fn decrypt_actor_profile(
+ &self,
+ actor: &WallActorResponse,
+ ) -> Result<Option<Vec<u8>>> {
+ if actor.encrypted_profile.trim().is_empty()
+ || actor.wall_id.trim().is_empty()
+ || actor.key_version <= 0
+ {
+ return Ok(None);
+ }
+ let Some(wall_key) = self
+ .resolve_wall_key_for_version(&actor.wall_id, Some(actor.key_version))
+ .await?
+ else {
+ return Ok(None);
+ };
+ Ok(Some(decrypt_secretbox_packed(
+ &wall_key,
+ &decode_b64(&actor.encrypted_profile)?,
+ )?))
+ }
+
pub async fn decrypt_feed_item(&self, item: &FeedItem) -> Result<DecryptedPost> {
let post = post_response_from_feed_item(item);
self.decrypt_post_for_wall(&item.wall_id, &post).await
@@ -918,13 +940,13 @@ impl AccountWallCtx {
let friends = self.list_wall_friends(wall_id).await?;
let mut updates = Vec::new();
for friend in friends {
- if friend.key_version == access.key_version {
+ if friend.share_key_version == access.key_version {
continue;
}
- let public_key = decode_b64(&friend.public_key)?;
+ let public_key = decode_b64(&friend.friend.public_key)?;
let sealed_share = sealed::seal(&access.wall_key, &public_key)?;
updates.push(ShareUpdatePayload {
- friend_id: friend.friend_id,
+ friend_id: friend.friend.user_id,
encrypted_wall_key: encode_b64(&pack_payload(&sealed_share, &[])),
});
}
@@ -1043,7 +1065,7 @@ fn post_response_from_feed_item(item: &FeedItem) -> PostResponse {
wall_id: item.wall_id.clone(),
wall_slug: item.wall_slug.clone(),
owner_user_id: item.owner_user_id,
- author: item.wall_slug.clone(),
+ author: item.author.clone(),
encrypted_post_key: item.encrypted_post_key.clone(),
caption_cipher: item.caption_cipher.clone(),
key_version: item.key_version,
@@ -1203,6 +1225,28 @@ impl WallLinkCtx {
})
}
+ pub async fn decrypt_actor_profile(
+ &self,
+ actor: &WallActorResponse,
+ ) -> Result<Option<Vec<u8>>> {
+ if actor.encrypted_profile.trim().is_empty()
+ || actor.wall_id != self.wall_id
+ || actor.key_version <= 0
+ {
+ return Ok(None);
+ }
+ let Some(wall_key) = self
+ .resolve_wall_key_for_version(Some(actor.key_version))
+ .await?
+ else {
+ return Ok(None);
+ };
+ Ok(Some(decrypt_secretbox_packed(
+ &wall_key,
+ &decode_b64(&actor.encrypted_profile)?,
+ )?))
+ }
+
pub async fn download_post_asset(&self, post_id: i64, object_key: &str) -> Result<Vec<u8>> {
let post = self.get_post(post_id).await?;
let decrypted = self.decrypt_post(&post).await?;
@@ -1682,7 +1726,13 @@ mod tests {
wall_id: "wall_owner_gallery".to_owned(),
wall_slug: "owner-gallery".to_owned(),
owner_user_id: 7,
- author: "owner-gallery".to_owned(),
+ author: WallActorResponse {
+ user_id: 7,
+ wall_id: "wall_owner_gallery".to_owned(),
+ wall_slug: "owner-gallery".to_owned(),
+ key_version: 2,
+ ..Default::default()
+ },
encrypted_post_key: encode_b64(
&encrypt_secretbox_packed(&previous_wall_key, &post_key)
.expect("encrypted post key"),
@@ -1993,9 +2043,11 @@ mod tests {
.with_body(
json!({
"likers": [{
- "userId": 8,
- "wallId": "wall_liker",
- "wallSlug": "liker",
+ "actor": {
+ "userId": 8,
+ "wallId": "wall_liker",
+ "wallSlug": "liker"
+ },
"createdAt": "2026-04-16T00:00:00Z"
}],
"nextCursor": "2000:8"
@@ -2010,7 +2062,7 @@ mod tests {
.await
.expect("likers should load");
- assert_eq!(response.likers[0].wall_id, "wall_liker");
+ assert_eq!(response.likers[0].actor.wall_id, "wall_liker");
assert_eq!(response.next_cursor, "2000:8");
likers.assert_async().await;
}
@@ -2131,10 +2183,14 @@ mod tests {
.with_status(200)
.with_body(
json!([{
- "friendId": 7,
- "username": "viewer",
- "publicKey": encode_b64(&friend_public_key),
- "keyVersion": 2,
+ "friend": {
+ "userId": 7,
+ "wallId": "wall_viewer",
+ "wallSlug": "viewer",
+ "publicKey": encode_b64(&friend_public_key),
+ "keyVersion": 2
+ },
+ "shareKeyVersion": 2,
"createdAt": "2026-04-16T00:00:00Z"
}])
.to_string(),
@@ -2183,6 +2239,11 @@ mod tests {
"wallId": "wall_owner_gallery",
"wallSlug": "owner-gallery",
"ownerUserId": 7,
+ "author": {
+ "userId": 7,
+ "wallId": "wall_owner_gallery",
+ "wallSlug": "owner-gallery"
+ },
"encryptedPostKey": "cGFja2Vk",
"captionCipher": "",
"keyVersion": 3,
@@ -2239,7 +2300,11 @@ mod tests {
"wallId": "wall_owner_gallery",
"wallSlug": "owner-gallery",
"ownerUserId": 7,
- "author": "owner-gallery"
+ "author": {
+ "userId": 7,
+ "wallId": "wall_owner_gallery",
+ "wallSlug": "owner-gallery"
+ }
}
}],
"nextCursor": "cursor-2"
@@ -2259,7 +2324,7 @@ mod tests {
page.items[0].notification_type,
crate::transport::WallNotificationType::LikedPost
);
- assert_eq!(page.items[0].actor.username, "mira");
+ assert_eq!(page.items[0].actor.wall_slug, "mira");
assert_eq!(page.next_cursor, "cursor-2");
notifications.assert_async().await;
}
@@ -2284,7 +2349,11 @@ mod tests {
"wallId": "wall_owner_gallery",
"wallSlug": "owner-gallery",
"ownerUserId": 7,
- "author": "owner-gallery",
+ "author": {
+ "userId": 7,
+ "wallId": "wall_owner_gallery",
+ "wallSlug": "owner-gallery"
+ },
"encryptedPostKey": "cGFja2Vk",
"captionCipher": "",
"keyVersion": 3,
@@ -2366,7 +2435,11 @@ mod tests {
"postId": 42,
"wallId": "wall_owner_gallery",
"wallSlug": "owner-gallery",
- "author": "owner-gallery",
+ "author": {
+ "userId": 7,
+ "wallId": "wall_owner_gallery",
+ "wallSlug": "owner-gallery"
+ },
"encryptedPostKey": encode_b64(&encrypt_secretbox_packed(&wall_key, &post_key).expect("post key wrap")),
"captionCipher": encode_b64(&encrypt_secretbox_packed(&post_key, caption).expect("caption wrap")),
"keyVersion": 3,
diff --git a/rust/wall/src/lib.rs b/rust/wall/src/lib.rs
index dd6d5352c5..0c4fca03b2 100644
--- a/rust/wall/src/lib.rs
+++ b/rust/wall/src/lib.rs
@@ -15,8 +15,8 @@ pub use transport::{
CommentResponse, EntityKeyPayload, FriendRelationshipResponse, FriendShareResponse,
FriendStatusResponse, LikeCommentResponse, LikePostResponse, ListPostLikersResponse,
PostLikerResponse, PostObjectPayload, PostPage, PostResponse, PresignUploadResponse,
- ProfileAvatarPayload, ProfileAvatarResponse, WallFriendResponse, WallKeyResponse,
- WallKeyVersionResponse, WallLinkLoginResponse, WallLinkStatusResponse, WallLookupResponse,
- WallNotification, WallNotificationActor, WallNotificationComment, WallNotificationPage,
+ ProfileAvatarPayload, ProfileAvatarResponse, WallActorResponse, WallFriendResponse,
+ WallKeyResponse, WallKeyVersionResponse, WallLinkLoginResponse, WallLinkStatusResponse,
+ WallLookupResponse, WallNotification, WallNotificationComment, WallNotificationPage,
WallNotificationPost, WallNotificationType, WallProfileResponse,
};
diff --git a/rust/wall/src/models.rs b/rust/wall/src/models.rs
index 0badd9b945..c16e1c6e2a 100644
--- a/rust/wall/src/models.rs
+++ b/rust/wall/src/models.rs
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
-use crate::transport::{PostObjectPayload, ProfileAvatarResponse};
+use crate::transport::{PostObjectPayload, ProfileAvatarResponse, WallActorResponse};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
@@ -100,6 +100,7 @@ pub struct FeedItem {
pub wall_id: String,
pub wall_slug: String,
pub owner_user_id: i64,
+ pub author: WallActorResponse,
pub encrypted_post_key: String,
#[serde(default)]
pub caption_cipher: String,
diff --git a/rust/wall/src/transport.rs b/rust/wall/src/transport.rs
index 40f46ca9e3..f2ab27ddba 100644
--- a/rust/wall/src/transport.rs
+++ b/rust/wall/src/transport.rs
@@ -154,7 +154,7 @@ pub struct PostResponse {
pub wall_slug: String,
#[serde(default)]
pub owner_user_id: i64,
- pub author: String,
+ pub author: WallActorResponse,
pub encrypted_post_key: String,
#[serde(default)]
pub caption_cipher: String,
@@ -187,11 +187,7 @@ pub struct CreateCommentRequest {
#[serde(rename_all = "camelCase")]
pub struct CommentResponse {
pub comment_id: i64,
- #[serde(default)]
- pub author_id: i64,
- #[serde(default)]
- pub author_wall_id: String,
- pub author: String,
+ pub author: WallActorResponse,
pub comment_cipher: String,
pub created_at: String,
#[serde(default)]
@@ -221,13 +217,26 @@ pub enum WallNotificationType {
AddedYouAsFriend,
}
-#[derive(Debug, Clone, Serialize, Deserialize)]
+#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
-pub struct WallNotificationActor {
+pub struct WallActorResponse {
+ #[serde(default)]
pub user_id: i64,
- pub username: String,
+ #[serde(default)]
pub wall_id: String,
pub wall_slug: String,
+ #[serde(default)]
+ pub public_key: String,
+ #[serde(default)]
+ pub key_version: i32,
+ #[serde(default)]
+ pub encrypted_profile: String,
+ #[serde(default)]
+ pub avatar: Option<ProfileAvatarResponse>,
+ #[serde(default)]
+ pub friends: Option<i64>,
+ #[serde(default)]
+ pub posts: Option<i64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -237,7 +246,7 @@ pub struct WallNotificationPost {
pub wall_id: String,
pub wall_slug: String,
pub owner_user_id: i64,
- pub author: String,
+ pub author: WallActorResponse,
#[serde(default)]
pub objects: Vec<PostObjectPayload>,
}
@@ -246,12 +255,7 @@ pub struct WallNotificationPost {
#[serde(rename_all = "camelCase")]
pub struct WallNotificationComment {
pub comment_id: i64,
- #[serde(default)]
- pub author_id: i64,
- #[serde(default)]
- pub author_wall_id: String,
- #[serde(default)]
- pub author: String,
+ pub author: WallActorResponse,
#[serde(default)]
pub comment_cipher: String,
#[serde(default)]
@@ -267,7 +271,7 @@ pub struct WallNotification {
#[serde(rename = "type")]
pub notification_type: WallNotificationType,
pub created_at: String,
- pub actor: WallNotificationActor,
+ pub actor: WallActorResponse,
#[serde(default)]
pub post: Option<WallNotificationPost>,
#[serde(default)]
@@ -402,20 +406,9 @@ pub struct FriendTargetPayload {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WallFriendResponse {
- pub friend_id: i64,
- #[serde(default)]
- pub wall_id: String,
- pub username: String,
- pub public_key: String,
- pub key_version: i32,
+ pub friend: WallActorResponse,
#[serde(default)]
- pub encrypted_profile: String,
- #[serde(default)]
- pub avatar: Option<ProfileAvatarResponse>,
- #[serde(default)]
- pub friends: i64,
- #[serde(default)]
- pub posts: i64,
+ pub share_key_version: i32,
pub created_at: String,
}
@@ -447,9 +440,7 @@ pub struct FriendShareResponse {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PostLikerResponse {
- pub user_id: i64,
- pub wall_id: String,
- pub wall_slug: String,
+ pub actor: WallActorResponse,
pub created_at: String,
}
diff --git a/server/migrations/122_wall_social_indexes.down.sql b/server/migrations/122_wall_social_indexes.down.sql
new file mode 100644
index 0000000000..ebbef7a459
--- /dev/null
+++ b/server/migrations/122_wall_social_indexes.down.sql
@@ -0,0 +1,2 @@
+DROP INDEX IF EXISTS idx_wall_post_comments_post_comment_desc;
+DROP INDEX IF EXISTS idx_wall_post_likes_post_created_user;
diff --git a/server/migrations/122_wall_social_indexes.up.sql b/server/migrations/122_wall_social_indexes.up.sql
new file mode 100644
index 0000000000..c4a0c1a461
--- /dev/null
+++ b/server/migrations/122_wall_social_indexes.up.sql
@@ -0,0 +1,6 @@
+CREATE INDEX IF NOT EXISTS idx_wall_post_likes_post_created_user
+ ON wall_post_likes (post_id, created_at DESC, user_id DESC);
+
+CREATE INDEX IF NOT EXISTS idx_wall_post_comments_post_comment_desc
+ ON wall_post_comments (post_id, comment_id DESC)
+ WHERE is_deleted = FALSE;
diff --git a/server/wall/controller/friends.go b/server/wall/controller/friends.go
index 5a4cbb4d14..f0f85f6479 100644
--- a/server/wall/controller/friends.go
+++ b/server/wall/controller/friends.go
@@ -101,26 +101,10 @@ func (c *FriendsController) ListFriends(ctx *gin.Context, req models.ListWallFri
}
resp := make([]models.WallFriendResponse, 0, len(friends))
for _, friend := range friends {
- var avatar *models.ProfileAvatarResponse
- if friend.AvatarObjectKey.Valid {
- avatar = &models.ProfileAvatarResponse{
- ObjectKey: friend.AvatarObjectKey.String,
- }
- if friend.AvatarSize.Valid {
- avatar.Size = friend.AvatarSize.Int64
- }
- }
resp = append(resp, models.WallFriendResponse{
- FriendID: friend.FriendID,
- WallID: friend.WallID,
- Username: friend.Username,
- PublicKey: friend.PublicKey,
- KeyVersion: friend.KeyVersion,
- EncryptedProfile: friend.EncryptedProfile,
- Avatar: avatar,
- Friends: friend.Friends,
- Posts: friend.Posts,
- CreatedAt: formatMicros(friend.CreatedAt),
+ Friend: toActorResponse(friend.Friend, true),
+ ShareKeyVersion: friend.ShareKeyVersion,
+ CreatedAt: formatMicros(friend.CreatedAt),
})
}
return resp, nil
diff --git a/server/wall/controller/helpers.go b/server/wall/controller/helpers.go
index 7a05ec4562..df5645f471 100644
--- a/server/wall/controller/helpers.go
+++ b/server/wall/controller/helpers.go
@@ -1,6 +1,7 @@
package controller
import (
+ "context"
"time"
"github.com/ente-io/museum/wall/models"
@@ -28,6 +29,76 @@ func toAvatarResponse(wall *wallrepo.WallRecord) *models.ProfileAvatarResponse {
return resp
}
+func toActorAvatarResponse(actor wallrepo.WallActorRecord) *models.ProfileAvatarResponse {
+ if !actor.AvatarObjectKey.Valid {
+ return nil
+ }
+ resp := &models.ProfileAvatarResponse{
+ ObjectKey: actor.AvatarObjectKey.String,
+ UpdatedAt: formatMicros(actor.UpdatedAt),
+ }
+ if actor.AvatarSize.Valid {
+ resp.Size = actor.AvatarSize.Int64
+ }
+ return resp
+}
+
+func toActorResponse(actor wallrepo.WallActorRecord, includePrivate bool) models.WallActorResponse {
+ resp := models.WallActorResponse{
+ WallSlug: actor.WallSlug,
+ }
+ if !includePrivate {
+ return resp
+ }
+ resp.UserID = actor.UserID
+ resp.WallID = actor.WallID
+ resp.PublicKey = actor.PublicKey
+ resp.KeyVersion = actor.KeyVersion
+ resp.EncryptedProfile = actor.EncryptedProfile
+ resp.Avatar = toActorAvatarResponse(actor)
+ if actor.Friends.Valid {
+ friends := actor.Friends.Int64
+ resp.Friends = &friends
+ }
+ if actor.Posts.Valid {
+ posts := actor.Posts.Int64
+ resp.Posts = &posts
+ }
+ return resp
+}
+
+func actorVisibility(ctx context.Context, auth authDeps, viewer *viewerAuth, actors ...wallrepo.WallActorRecord) (map[string]bool, error) {
+ visible := make(map[string]bool)
+ if len(actors) == 0 || viewer == nil {
+ return visible, nil
+ }
+ wallIDSet := make(map[string]struct{}, len(actors))
+ for _, actor := range actors {
+ if actor.WallID != "" {
+ wallIDSet[actor.WallID] = struct{}{}
+ }
+ }
+ if len(wallIDSet) == 0 {
+ return visible, nil
+ }
+ if viewer.Link != nil {
+ visible[viewer.Link.WallID] = true
+ return visible, nil
+ }
+ if viewer.UserID <= 0 || auth.FriendsRepo == nil {
+ return visible, nil
+ }
+ wallIDs := make([]string, 0, len(wallIDSet))
+ for wallID := range wallIDSet {
+ wallIDs = append(wallIDs, wallID)
+ }
+ return auth.FriendsRepo.ListAccessibleWallIDs(ctx, viewer.UserID, wallIDs)
+}
+
+func visibleActor(visible map[string]bool, actor wallrepo.WallActorRecord) bool {
+ return visible[actor.WallID]
+}
+
func toWallKeyResponse(wall *wallrepo.WallRecord) *models.WallKeyResponse {
return &models.WallKeyResponse{
WallID: wall.WallID,
@@ -64,13 +135,13 @@ func toPostObjectPayload(asset wallrepo.WallPostAssetRecord) models.PostObjectPa
return resp
}
-func toPostResponse(post *wallrepo.WallPostRecord, assets []wallrepo.WallPostAssetRecord) *models.PostResponse {
+func toPostResponse(post *wallrepo.WallPostRecord, assets []wallrepo.WallPostAssetRecord, includeAuthorPrivate bool) *models.PostResponse {
resp := &models.PostResponse{
PostID: post.PostID,
WallID: post.WallID,
WallSlug: post.WallSlug,
OwnerUserID: post.OwnerID,
- Author: post.Author,
+ Author: toActorResponse(post.Author, includeAuthorPrivate),
EncryptedPostKey: post.EncryptedPostKey,
CaptionCipher: post.CaptionCipher,
KeyVersion: post.KeyVersion,
@@ -88,12 +159,10 @@ func toPostResponse(post *wallrepo.WallPostRecord, assets []wallrepo.WallPostAss
return resp
}
-func toCommentResponse(comment wallrepo.WallCommentRecord) models.CommentResponse {
+func toCommentResponse(comment wallrepo.WallCommentRecord, includeAuthorPrivate bool) models.CommentResponse {
resp := models.CommentResponse{
CommentID: comment.CommentID,
- AuthorID: comment.AuthorID,
- AuthorWallID: comment.AuthorWallID,
- Author: comment.Author,
+ Author: toActorResponse(comment.Author, includeAuthorPrivate),
CommentCipher: comment.CommentCipher,
CreatedAt: formatMicros(comment.CreatedAt),
Likes: comment.Likes,
diff --git a/server/wall/controller/notifications.go b/server/wall/controller/notifications.go
index be8f3fc81f..e25ceaaffd 100644
--- a/server/wall/controller/notifications.go
+++ b/server/wall/controller/notifications.go
@@ -20,24 +20,33 @@ func (c *NotificationsController) List(ctx *gin.Context, req models.ListNotifica
if err != nil {
return nil, err
}
+ actors := make([]repo.WallActorRecord, 0, len(notifications)*3)
+ for _, notification := range notifications {
+ actors = append(actors, notification.Actor)
+ if notification.PostID.Valid {
+ actors = append(actors, notification.PostAuthor)
+ }
+ if notification.CommentID.Valid {
+ actors = append(actors, notification.CommentAuthor)
+ }
+ }
+ visible, err := actorVisibility(ctx.Request.Context(), c.auth, &viewerAuth{UserID: userID}, actors...)
+ if err != nil {
+ return nil, err
+ }
items := make([]models.NotificationResponse, 0, len(notifications))
for _, notification := range notifications {
- items = append(items, toNotificationResponse(notification))
+ items = append(items, toNotificationResponse(notification, visible))
}
return &models.NotificationPage{Items: items, NextCursor: nextCursor}, nil
}
-func toNotificationResponse(notification repo.WallNotificationRecord) models.NotificationResponse {
+func toNotificationResponse(notification repo.WallNotificationRecord, visible map[string]bool) models.NotificationResponse {
resp := models.NotificationResponse{
ID: notification.ID,
Type: notification.Type,
CreatedAt: formatMicros(notification.CreatedAt),
- Actor: models.NotificationActorResponse{
- UserID: notification.ActorID,
- Username: notification.ActorUsername,
- WallID: notification.ActorWallID,
- WallSlug: notification.ActorWallSlug,
- },
+ Actor: toActorResponse(notification.Actor, visibleActor(visible, notification.Actor)),
}
if notification.PostID.Valid {
post := &models.NotificationPostResponse{
@@ -45,7 +54,7 @@ func toNotificationResponse(notification repo.WallNotificationRecord) models.Not
WallID: notification.PostWallID.String,
WallSlug: notification.PostWallSlug.String,
OwnerUserID: notification.PostOwnerID.Int64,
- Author: notification.PostAuthor.String,
+ Author: toActorResponse(notification.PostAuthor, visibleActor(visible, notification.PostAuthor)),
}
if notification.PostObjectKey.Valid {
object := models.PostObjectPayload{
@@ -79,15 +88,7 @@ func toNotificationResponse(notification repo.WallNotificationRecord) models.Not
if notification.CommentID.Valid {
comment := &models.NotificationCommentResponse{
CommentID: notification.CommentID.Int64,
- }
- if notification.CommentAuthorID.Valid {
- comment.AuthorID = notification.CommentAuthorID.Int64
- }
- if notification.CommentAuthorWallID.Valid {
- comment.AuthorWallID = notification.CommentAuthorWallID.String
- }
- if notification.CommentAuthor.Valid {
- comment.Author = notification.CommentAuthor.String
+ Author: toActorResponse(notification.CommentAuthor, visibleActor(visible, notification.CommentAuthor)),
}
if notification.CommentCipher.Valid {
comment.CommentCipher = notification.CommentCipher.String
diff --git a/server/wall/controller/posts.go b/server/wall/controller/posts.go
index 186584dd18..3f217d3b4a 100644
--- a/server/wall/controller/posts.go
+++ b/server/wall/controller/posts.go
@@ -96,7 +96,7 @@ func (c *PostsController) List(ctx *gin.Context, req models.ListPostsRequest) (*
}
resp := make([]models.PostResponse, 0, len(posts))
for _, post := range posts {
- resp = append(resp, *toPostResponse(&post, assetsByPost[post.PostID]))
+ resp = append(resp, *toPostResponse(&post, assetsByPost[post.PostID], true))
}
return &models.PostPage{
Items: resp,
@@ -123,7 +123,7 @@ func (c *PostsController) ListFeed(ctx *gin.Context, req models.ListFeedRequest)
}
items := make([]models.PostResponse, 0, len(posts))
for _, post := range posts {
- items = append(items, *toPostResponse(&post, assetsByPost[post.PostID]))
+ items = append(items, *toPostResponse(&post, assetsByPost[post.PostID], true))
}
return &models.FeedPage{
Items: items,
@@ -159,7 +159,7 @@ func (c *PostsController) Get(ctx *gin.Context, postID string) (*models.PostResp
if err != nil {
return nil, err
}
- return toPostResponse(post, assetsByPost[id]), nil
+ return toPostResponse(post, assetsByPost[id], true), nil
}
func (c *PostsController) UpdateCaption(ctx *gin.Context, postID string, req models.UpdatePostCaptionRequest) (*models.PostResponse, error) {
@@ -182,7 +182,7 @@ func (c *PostsController) UpdateCaption(ctx *gin.Context, postID string, req mod
if err != nil {
return nil, err
}
- return toPostResponse(post, assetsByPost[id]), nil
+ return toPostResponse(post, assetsByPost[id], true), nil
}
func (c *PostsController) ToggleLike(ctx *gin.Context, postID string, req models.LikePostRequest) (*models.LikePostResponse, error) {
@@ -241,11 +241,17 @@ func (c *PostsController) ListLikers(ctx *gin.Context, postID string) (*models.L
return nil, err
}
resp := make([]models.PostLikerResponse, 0, len(likers))
+ actors := make([]repo.WallActorRecord, 0, len(likers))
+ for _, liker := range likers {
+ actors = append(actors, liker.Actor)
+ }
+ visible, err := actorVisibility(ctx.Request.Context(), c.auth, viewer, actors...)
+ if err != nil {
+ return nil, err
+ }
for _, liker := range likers {
resp = append(resp, models.PostLikerResponse{
- UserID: liker.UserID,
- WallID: liker.WallID,
- WallSlug: liker.WallSlug,
+ Actor: toActorResponse(liker.Actor, visibleActor(visible, liker.Actor)),
CreatedAt: formatMicros(liker.CreatedAt),
})
}
@@ -295,8 +301,16 @@ func (c *PostsController) ListComments(ctx *gin.Context, postID string) (*models
return nil, err
}
resp := make([]models.CommentResponse, 0, len(comments))
+ actors := make([]repo.WallActorRecord, 0, len(comments))
+ for _, comment := range comments {
+ actors = append(actors, comment.Author)
+ }
+ visible, err := actorVisibility(ctx.Request.Context(), c.auth, viewer, actors...)
+ if err != nil {
+ return nil, err
+ }
for _, comment := range comments {
- resp = append(resp, toCommentResponse(comment))
+ resp = append(resp, toCommentResponse(comment, visibleActor(visible, comment.Author)))
}
return &models.ListCommentsResponse{Comments: resp, NextCursor: nextCursor}, nil
}
@@ -343,7 +357,7 @@ func (c *PostsController) CreateComment(ctx *gin.Context, postID string, req mod
if err != nil {
return nil, err
}
- resp := toCommentResponse(*comment)
+ resp := toCommentResponse(*comment, true)
return &resp, nil
}
diff --git a/server/wall/models/models.go b/server/wall/models/models.go
index 3c768da8e7..1935d3ac22 100644
--- a/server/wall/models/models.go
+++ b/server/wall/models/models.go
@@ -77,6 +77,18 @@ type ProfileAvatarResponse struct {
UpdatedAt string `json:"updatedAt,omitempty"`
}
+type WallActorResponse struct {
+ UserID int64 `json:"userId,omitempty"`
+ WallID string `json:"wallId,omitempty"`
+ WallSlug string `json:"wallSlug"`
+ PublicKey string `json:"publicKey,omitempty"`
+ KeyVersion int `json:"keyVersion,omitempty"`
+ EncryptedProfile string `json:"encryptedProfile,omitempty"`
+ Avatar *ProfileAvatarResponse `json:"avatar,omitempty"`
+ Friends *int64 `json:"friends,omitempty"`
+ Posts *int64 `json:"posts,omitempty"`
+}
+
type WallLinkCreateRequest struct {
WallID string `json:"wallId"`
AuthKey string `json:"authKey"`
@@ -191,16 +203,9 @@ type WallKeyVersionResponse struct {
}
type WallFriendResponse struct {
- FriendID int64 `json:"friendId"`
- WallID string `json:"wallId"`
- Username string `json:"username"`
- PublicKey string `json:"publicKey"`
- KeyVersion int `json:"keyVersion"`
- EncryptedProfile string `json:"encryptedProfile,omitempty"`
- Avatar *ProfileAvatarResponse `json:"avatar,omitempty"`
- Friends int64 `json:"friends"`
- Posts int64 `json:"posts"`
- CreatedAt string `json:"createdAt"`
+ Friend WallActorResponse `json:"friend"`
+ ShareKeyVersion int `json:"shareKeyVersion"`
+ CreatedAt string `json:"createdAt"`
}
type RefreshFriendSharesRequest struct {
@@ -240,10 +245,8 @@ type ListPostLikersResponse struct {
}
type PostLikerResponse struct {
- UserID int64 `json:"userId"`
- WallID string `json:"wallId"`
- WallSlug string `json:"wallSlug"`
- CreatedAt string `json:"createdAt"`
+ Actor WallActorResponse `json:"actor"`
+ CreatedAt string `json:"createdAt"`
}
type LikeCommentRequest struct {
@@ -274,7 +277,7 @@ type PostResponse struct {
WallID string `json:"wallId"`
WallSlug string `json:"wallSlug"`
OwnerUserID int64 `json:"ownerUserId"`
- Author string `json:"author"`
+ Author WallActorResponse `json:"author"`
EncryptedPostKey string `json:"encryptedPostKey"`
CaptionCipher string `json:"captionCipher,omitempty"`
KeyVersion int `json:"keyVersion"`
@@ -296,16 +299,14 @@ type FeedPage struct {
}
type CommentResponse struct {
- CommentID int64 `json:"commentId"`
- AuthorID int64 `json:"authorId"`
- AuthorWallID string `json:"authorWallId"`
- Author string `json:"author"`
- CommentCipher string `json:"commentCipher"`
- CreatedAt string `json:"createdAt"`
- Likes int64 `json:"likes"`
- ViewerLiked bool `json:"viewerLiked"`
- ViewerCanDelete bool `json:"viewerCanDelete"`
- ParentCommentID *int64 `json:"parentCommentId,omitempty"`
+ CommentID int64 `json:"commentId"`
+ Author WallActorResponse `json:"author"`
+ CommentCipher string `json:"commentCipher"`
+ CreatedAt string `json:"createdAt"`
+ Likes int64 `json:"likes"`
+ ViewerLiked bool `json:"viewerLiked"`
+ ViewerCanDelete bool `json:"viewerCanDelete"`
+ ParentCommentID *int64 `json:"parentCommentId,omitempty"`
}
type ListCommentsResponse struct {
@@ -318,37 +319,28 @@ type CreateCommentRequest struct {
ParentCommentID *int64 `json:"parentCommentId,omitempty"`
}
-type NotificationActorResponse struct {
- UserID int64 `json:"userId"`
- Username string `json:"username"`
- WallID string `json:"wallId"`
- WallSlug string `json:"wallSlug"`
-}
-
type NotificationPostResponse struct {
PostID int64 `json:"postId"`
WallID string `json:"wallId"`
WallSlug string `json:"wallSlug"`
OwnerUserID int64 `json:"ownerUserId"`
- Author string `json:"author"`
+ Author WallActorResponse `json:"author"`
Objects []PostObjectPayload `json:"objects,omitempty"`
}
type NotificationCommentResponse struct {
- CommentID int64 `json:"commentId"`
- AuthorID int64 `json:"authorId,omitempty"`
- AuthorWallID string `json:"authorWallId,omitempty"`
- Author string `json:"author,omitempty"`
- CommentCipher string `json:"commentCipher,omitempty"`
- CreatedAt string `json:"createdAt,omitempty"`
- ParentCommentID *int64 `json:"parentCommentId,omitempty"`
+ CommentID int64 `json:"commentId"`
+ Author WallActorResponse `json:"author"`
+ CommentCipher string `json:"commentCipher,omitempty"`
+ CreatedAt string `json:"createdAt,omitempty"`
+ ParentCommentID *int64 `json:"parentCommentId,omitempty"`
}
type NotificationResponse struct {
ID string `json:"id"`
Type string `json:"type"`
CreatedAt string `json:"createdAt"`
- Actor NotificationActorResponse `json:"actor"`
+ Actor WallActorResponse `json:"actor"`
Post *NotificationPostResponse `json:"post,omitempty"`
Comment *NotificationCommentResponse `json:"comment,omitempty"`
}
diff --git a/server/wall/repo/common.go b/server/wall/repo/common.go
index 5f97735c4e..02624bae67 100644
--- a/server/wall/repo/common.go
+++ b/server/wall/repo/common.go
@@ -34,6 +34,22 @@ func optionalInt(limit int, fallback int) int {
return limit
}
+func wallActorScanDest(actor *WallActorRecord) []any {
+ return []any{
+ &actor.UserID,
+ &actor.WallID,
+ &actor.WallSlug,
+ &actor.PublicKey,
+ &actor.KeyVersion,
+ &actor.EncryptedProfile,
+ &actor.AvatarObjectKey,
+ &actor.AvatarSize,
+ &actor.UpdatedAt,
+ &actor.Friends,
+ &actor.Posts,
+ }
+}
+
func wrapUnique(err error, message string) error {
if err == nil {
return nil
diff --git a/server/wall/repo/friends.go b/server/wall/repo/friends.go
index 5430b73348..aad724c402 100644
--- a/server/wall/repo/friends.go
+++ b/server/wall/repo/friends.go
@@ -6,6 +6,7 @@ import (
"errors"
"github.com/ente-io/stacktrace"
+ "github.com/lib/pq"
)
var ErrAlreadyFriends = errors.New("wall users are already friends")
@@ -228,20 +229,22 @@ func (r *FriendsRepository) ListSharesForFriend(ctx context.Context, friendID in
func (r *FriendsRepository) ListFriendsForWall(ctx context.Context, wallID string) ([]WallFriendRecord, error) {
rows, err := r.DB.QueryContext(ctx, `
- SELECT s.friend_id,
+ SELECT friend_wall.owner_id,
friend_wall.wall_id,
friend_wall.wall_slug,
- ka.public_key,
- s.key_version,
+ friend_ka.public_key,
+ friend_wall.current_version,
friend_wall.encrypted_profile,
friend_wall.avatar_object_key,
friend_wall.avatar_size,
+ friend_wall.updated_at,
(SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = friend_wall.wall_id) AS friends,
(SELECT COUNT(*) FROM wall_posts p WHERE p.wall_id = friend_wall.wall_id AND p.is_deleted = FALSE) AS posts,
+ s.key_version,
s.created_at
FROM wall_friend_shares s
JOIN walls friend_wall ON friend_wall.owner_id = s.friend_id
- JOIN key_attributes ka ON ka.user_id = s.friend_id
+ JOIN key_attributes friend_ka ON friend_ka.user_id = s.friend_id
WHERE s.wall_id = $1
ORDER BY lower(friend_wall.wall_slug) ASC
`, wallID)
@@ -252,19 +255,9 @@ func (r *FriendsRepository) ListFriendsForWall(ctx context.Context, wallID strin
var out []WallFriendRecord
for rows.Next() {
var rec WallFriendRecord
- if err := rows.Scan(
- &rec.FriendID,
- &rec.WallID,
- &rec.Username,
- &rec.PublicKey,
- &rec.KeyVersion,
- &rec.EncryptedProfile,
- &rec.AvatarObjectKey,
- &rec.AvatarSize,
- &rec.Friends,
- &rec.Posts,
- &rec.CreatedAt,
- ); err != nil {
+ dest := wallActorScanDest(&rec.Friend)
+ dest = append(dest, &rec.ShareKeyVersion, &rec.CreatedAt)
+ if err := rows.Scan(dest...); err != nil {
return nil, stacktrace.Propagate(err, "")
}
out = append(out, rec)
@@ -272,6 +265,34 @@ func (r *FriendsRepository) ListFriendsForWall(ctx context.Context, wallID strin
return out, stacktrace.Propagate(rows.Err(), "")
}
+func (r *FriendsRepository) ListAccessibleWallIDs(ctx context.Context, viewerID int64, wallIDs []string) (map[string]bool, error) {
+ out := make(map[string]bool, len(wallIDs))
+ if viewerID <= 0 || len(wallIDs) == 0 {
+ return out, nil
+ }
+ rows, err := r.DB.QueryContext(ctx, `
+ SELECT wall_id
+ FROM walls
+ WHERE owner_id = $1 AND wall_id = ANY($2)
+ UNION
+ SELECT wall_id
+ FROM wall_friend_shares
+ WHERE friend_id = $1 AND wall_id = ANY($2)
+ `, viewerID, pq.Array(wallIDs))
+ if err != nil {
+ return nil, stacktrace.Propagate(err, "")
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var wallID string
+ if err := rows.Scan(&wallID); err != nil {
+ return nil, stacktrace.Propagate(err, "")
+ }
+ out[wallID] = true
+ }
+ return out, stacktrace.Propagate(rows.Err(), "")
+}
+
func (r *FriendsRepository) GetRelationship(ctx context.Context, viewerID, targetOwnerID int64, targetWallID string) (string, error) {
if viewerID == targetOwnerID {
return "self", nil
diff --git a/server/wall/repo/module.go b/server/wall/repo/module.go
index c6dd453270..7470266896 100644
--- a/server/wall/repo/module.go
+++ b/server/wall/repo/module.go
@@ -68,7 +68,7 @@ type WallPostRecord struct {
WallID string
WallSlug string
OwnerID int64
- Author string
+ Author WallActorRecord
EncryptedPostKey string
CaptionCipher string
KeyVersion int
@@ -107,9 +107,7 @@ type WallTempObjectRecord struct {
type WallCommentRecord struct {
CommentID int64
PostID int64
- AuthorID int64
- AuthorWallID string
- Author string
+ Author WallActorRecord
CommentCipher string
ParentCommentID sql.NullInt64
CreatedAt int64
@@ -119,12 +117,24 @@ type WallCommentRecord struct {
}
type WallPostLikerRecord struct {
- UserID int64
- WallID string
- WallSlug string
+ Actor WallActorRecord
CreatedAt int64
}
+type WallActorRecord struct {
+ UserID int64
+ WallID string
+ WallSlug string
+ PublicKey string
+ KeyVersion int
+ EncryptedProfile string
+ AvatarObjectKey sql.NullString
+ AvatarSize sql.NullInt64
+ UpdatedAt int64
+ Friends sql.NullInt64
+ Posts sql.NullInt64
+}
+
type WallShareRecord struct {
WallID string
FriendID int64
@@ -142,17 +152,9 @@ type WallShareUpdateRecord struct {
}
type WallFriendRecord struct {
- FriendID int64
- WallID string
- Username string
- PublicKey string
- KeyVersion int
- EncryptedProfile string
- AvatarObjectKey sql.NullString
- AvatarSize sql.NullInt64
- Friends int64
- Posts int64
- CreatedAt int64
+ Friend WallActorRecord
+ ShareKeyVersion int
+ CreatedAt int64
}
type WallLinkRecord struct {
@@ -185,15 +187,12 @@ type WallNotificationRecord struct {
ID string
Type string
CreatedAt int64
- ActorID int64
- ActorUsername string
- ActorWallID string
- ActorWallSlug string
+ Actor WallActorRecord
PostID sql.NullInt64
PostWallID sql.NullString
PostWallSlug sql.NullString
PostOwnerID sql.NullInt64
- PostAuthor sql.NullString
+ PostAuthor WallActorRecord
PostObjectKey sql.NullString
PostObjectSize sql.NullInt64
PostObjectPosition sql.NullInt64
@@ -204,9 +203,7 @@ type WallNotificationRecord struct {
PostObjectMediaType sql.NullString
CommentID sql.NullInt64
ParentCommentID sql.NullInt64
- CommentAuthorID sql.NullInt64
- CommentAuthorWallID sql.NullString
- CommentAuthor sql.NullString
+ CommentAuthor WallActorRecord
CommentCipher sql.NullString
CommentCreatedAt sql.NullInt64
}
diff --git a/server/wall/repo/module_test.go b/server/wall/repo/module_test.go
index 938f225fb0..5d97a46a67 100644
--- a/server/wall/repo/module_test.go
+++ b/server/wall/repo/module_test.go
@@ -104,12 +104,12 @@ func TestWallModuleLifecycle(t *testing.T) {
friends, err := module.Friends.ListFriendsForWall(ctx, aliceWall.WallID)
require.NoError(t, err)
require.Len(t, friends, 1)
- require.Equal(t, "bob", friends[0].Username)
+ require.Equal(t, "bob", friends[0].Friend.WallSlug)
bobFriends, err := module.Friends.ListFriendsForWall(ctx, bobWall.WallID)
require.NoError(t, err)
require.Len(t, bobFriends, 1)
- require.Equal(t, "alice", bobFriends[0].Username)
+ require.Equal(t, "alice", bobFriends[0].Friend.WallSlug)
for _, tempObject := range []WallTempObjectRecord{
{
@@ -169,7 +169,7 @@ func TestWallModuleLifecycle(t *testing.T) {
require.Len(t, comments, 2)
require.Empty(t, nextCommentsCursor)
require.Equal(t, comment.CommentID, comments[1].CommentID)
- require.Equal(t, bobWall.WallID, comments[1].AuthorWallID)
+ require.Equal(t, bobWall.WallID, comments[1].Author.WallID)
require.Equal(t, comment.CommentID, comments[0].ParentCommentID.Int64)
assets, err := module.Posts.ListAssetsByPostIDs(ctx, []int64{postID})
@@ -719,9 +719,9 @@ func TestNotificationsIncludeWallSocialEvents(t *testing.T) {
require.Len(t, page, 3)
require.Equal(t, "addedYouAsFriend", page[0].Type)
require.Equal(t, "likedComment", page[1].Type)
- require.Equal(t, aliceWall.WallID, page[1].CommentAuthorWallID.String)
+ require.Equal(t, aliceWall.WallID, page[1].CommentAuthor.WallID)
require.Equal(t, "repliedToComment", page[2].Type)
- require.Equal(t, bobWall.WallID, page[2].CommentAuthorWallID.String)
+ require.Equal(t, bobWall.WallID, page[2].CommentAuthor.WallID)
require.NotEmpty(t, nextCursor)
page, nextCursor, err = module.Notifications.List(ctx, aliceID, nextCursor, 3)
@@ -786,15 +786,15 @@ func TestListPostLikersPaginates(t *testing.T) {
page, nextCursor, err := module.Posts.ListPostLikers(ctx, postID, "", 1)
require.NoError(t, err)
require.Len(t, page, 1)
- require.Equal(t, bobID, page[0].UserID)
- require.Equal(t, bobWall.WallID, page[0].WallID)
+ require.Equal(t, bobID, page[0].Actor.UserID)
+ require.Equal(t, bobWall.WallID, page[0].Actor.WallID)
require.Equal(t, "3000:"+strconv.FormatInt(bobID, 10), nextCursor)
page, nextCursor, err = module.Posts.ListPostLikers(ctx, postID, nextCursor, 1)
require.NoError(t, err)
require.Len(t, page, 1)
- require.Equal(t, devID, page[0].UserID)
- require.Equal(t, devWall.WallID, page[0].WallID)
+ require.Equal(t, devID, page[0].Actor.UserID)
+ require.Equal(t, devWall.WallID, page[0].Actor.WallID)
require.Empty(t, nextCursor)
}
diff --git a/server/wall/repo/notifications.go b/server/wall/repo/notifications.go
index d0724542d9..870a49aaab 100644
--- a/server/wall/repo/notifications.go
+++ b/server/wall/repo/notifications.go
@@ -13,15 +13,20 @@ const wallNotificationRows = `
'post_like:' || pl.post_id::text || ':' || pl.user_id::text AS notification_id,
'likedPost' AS notification_type,
pl.created_at,
- pl.user_id AS actor_id,
- actor_wall.wall_slug AS actor_username,
- actor_wall.wall_id AS actor_wall_id,
- actor_wall.wall_slug AS actor_wall_slug,
+ actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,
+ actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,
+ actor_wall.avatar_size, actor_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = actor_wall.wall_id) AS actor_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = actor_wall.wall_id AND ap.is_deleted = FALSE) AS actor_posts,
p.post_id,
p.wall_id AS post_wall_id,
post_wall.wall_slug AS post_wall_slug,
p.owner_id AS post_owner_id,
- owner_wall.wall_slug AS post_author,
+ owner_wall.owner_id, owner_wall.wall_id, owner_wall.wall_slug, owner_ka.public_key,
+ owner_wall.current_version, owner_wall.encrypted_profile, owner_wall.avatar_object_key,
+ owner_wall.avatar_size, owner_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = owner_wall.wall_id) AS post_author_friends,
+ (SELECT COUNT(*) FROM wall_posts op WHERE op.wall_id = owner_wall.wall_id AND op.is_deleted = FALSE) AS post_author_posts,
asset.object_key AS post_object_key,
asset.size AS post_object_size,
asset.position AS post_object_position,
@@ -32,16 +37,16 @@ const wallNotificationRows = `
asset.media_type AS post_object_media_type,
NULL::bigint AS comment_id,
NULL::bigint AS parent_comment_id,
- NULL::bigint AS comment_author_id,
- NULL::text AS comment_author_wall_id,
- NULL::text AS comment_author,
+ 0::bigint, ''::text, ''::text, ''::text, 0::integer, ''::text, NULL::text, NULL::bigint, 0::bigint, NULL::bigint, NULL::bigint,
NULL::text AS comment_cipher,
NULL::bigint AS comment_created_at
FROM wall_post_likes pl
JOIN wall_posts p ON p.post_id = pl.post_id
JOIN walls actor_wall ON actor_wall.owner_id = pl.user_id
+ JOIN key_attributes actor_ka ON actor_ka.user_id = pl.user_id
JOIN walls post_wall ON post_wall.wall_id = p.wall_id
JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
+ JOIN key_attributes owner_ka ON owner_ka.user_id = p.owner_id
LEFT JOIN LATERAL (
SELECT object_key, size, position, variant, blur_hash_cipher, width, height, media_type
FROM wall_post_assets
@@ -59,15 +64,20 @@ const wallNotificationRows = `
'comment:' || c.comment_id::text AS notification_id,
'commentedOnPost' AS notification_type,
c.created_at,
- c.author_id AS actor_id,
- actor_wall.wall_slug AS actor_username,
- actor_wall.wall_id AS actor_wall_id,
- actor_wall.wall_slug AS actor_wall_slug,
+ actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,
+ actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,
+ actor_wall.avatar_size, actor_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = actor_wall.wall_id) AS actor_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = actor_wall.wall_id AND ap.is_deleted = FALSE) AS actor_posts,
p.post_id,
p.wall_id AS post_wall_id,
post_wall.wall_slug AS post_wall_slug,
p.owner_id AS post_owner_id,
- owner_wall.wall_slug AS post_author,
+ owner_wall.owner_id, owner_wall.wall_id, owner_wall.wall_slug, owner_ka.public_key,
+ owner_wall.current_version, owner_wall.encrypted_profile, owner_wall.avatar_object_key,
+ owner_wall.avatar_size, owner_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = owner_wall.wall_id) AS post_author_friends,
+ (SELECT COUNT(*) FROM wall_posts op WHERE op.wall_id = owner_wall.wall_id AND op.is_deleted = FALSE) AS post_author_posts,
asset.object_key AS post_object_key,
asset.size AS post_object_size,
asset.position AS post_object_position,
@@ -78,16 +88,20 @@ const wallNotificationRows = `
asset.media_type AS post_object_media_type,
c.comment_id,
NULL::bigint AS parent_comment_id,
- c.author_id AS comment_author_id,
- actor_wall.wall_id AS comment_author_wall_id,
- actor_wall.wall_slug AS comment_author,
+ actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,
+ actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,
+ actor_wall.avatar_size, actor_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = actor_wall.wall_id) AS comment_author_friends,
+ (SELECT COUNT(*) FROM wall_posts cp WHERE cp.wall_id = actor_wall.wall_id AND cp.is_deleted = FALSE) AS comment_author_posts,
c.comment_cipher,
c.created_at AS comment_created_at
FROM wall_post_comments c
JOIN wall_posts p ON p.post_id = c.post_id
JOIN walls actor_wall ON actor_wall.owner_id = c.author_id
+ JOIN key_attributes actor_ka ON actor_ka.user_id = c.author_id
JOIN walls post_wall ON post_wall.wall_id = p.wall_id
JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
+ JOIN key_attributes owner_ka ON owner_ka.user_id = p.owner_id
LEFT JOIN LATERAL (
SELECT object_key, size, position, variant, blur_hash_cipher, width, height, media_type
FROM wall_post_assets
@@ -107,15 +121,20 @@ const wallNotificationRows = `
'reply:' || c.comment_id::text AS notification_id,
'repliedToComment' AS notification_type,
c.created_at,
- c.author_id AS actor_id,
- actor_wall.wall_slug AS actor_username,
- actor_wall.wall_id AS actor_wall_id,
- actor_wall.wall_slug AS actor_wall_slug,
+ actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,
+ actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,
+ actor_wall.avatar_size, actor_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = actor_wall.wall_id) AS actor_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = actor_wall.wall_id AND ap.is_deleted = FALSE) AS actor_posts,
p.post_id,
p.wall_id AS post_wall_id,
post_wall.wall_slug AS post_wall_slug,
p.owner_id AS post_owner_id,
- owner_wall.wall_slug AS post_author,
+ owner_wall.owner_id, owner_wall.wall_id, owner_wall.wall_slug, owner_ka.public_key,
+ owner_wall.current_version, owner_wall.encrypted_profile, owner_wall.avatar_object_key,
+ owner_wall.avatar_size, owner_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = owner_wall.wall_id) AS post_author_friends,
+ (SELECT COUNT(*) FROM wall_posts op WHERE op.wall_id = owner_wall.wall_id AND op.is_deleted = FALSE) AS post_author_posts,
asset.object_key AS post_object_key,
asset.size AS post_object_size,
asset.position AS post_object_position,
@@ -126,17 +145,21 @@ const wallNotificationRows = `
asset.media_type AS post_object_media_type,
c.comment_id,
c.parent_comment_id,
- c.author_id AS comment_author_id,
- actor_wall.wall_id AS comment_author_wall_id,
- actor_wall.wall_slug AS comment_author,
+ actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,
+ actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,
+ actor_wall.avatar_size, actor_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = actor_wall.wall_id) AS comment_author_friends,
+ (SELECT COUNT(*) FROM wall_posts cp WHERE cp.wall_id = actor_wall.wall_id AND cp.is_deleted = FALSE) AS comment_author_posts,
c.comment_cipher,
c.created_at AS comment_created_at
FROM wall_post_comments c
JOIN wall_post_comments parent ON parent.comment_id = c.parent_comment_id
JOIN wall_posts p ON p.post_id = c.post_id
JOIN walls actor_wall ON actor_wall.owner_id = c.author_id
+ JOIN key_attributes actor_ka ON actor_ka.user_id = c.author_id
JOIN walls post_wall ON post_wall.wall_id = p.wall_id
JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
+ JOIN key_attributes owner_ka ON owner_ka.user_id = p.owner_id
LEFT JOIN LATERAL (
SELECT object_key, size, position, variant, blur_hash_cipher, width, height, media_type
FROM wall_post_assets
@@ -156,15 +179,20 @@ const wallNotificationRows = `
'comment_like:' || cl.comment_id::text || ':' || cl.user_id::text AS notification_id,
'likedComment' AS notification_type,
cl.created_at,
- cl.user_id AS actor_id,
- actor_wall.wall_slug AS actor_username,
- actor_wall.wall_id AS actor_wall_id,
- actor_wall.wall_slug AS actor_wall_slug,
+ actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,
+ actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,
+ actor_wall.avatar_size, actor_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = actor_wall.wall_id) AS actor_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = actor_wall.wall_id AND ap.is_deleted = FALSE) AS actor_posts,
p.post_id,
p.wall_id AS post_wall_id,
post_wall.wall_slug AS post_wall_slug,
p.owner_id AS post_owner_id,
- owner_wall.wall_slug AS post_author,
+ owner_wall.owner_id, owner_wall.wall_id, owner_wall.wall_slug, owner_ka.public_key,
+ owner_wall.current_version, owner_wall.encrypted_profile, owner_wall.avatar_object_key,
+ owner_wall.avatar_size, owner_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = owner_wall.wall_id) AS post_author_friends,
+ (SELECT COUNT(*) FROM wall_posts op WHERE op.wall_id = owner_wall.wall_id AND op.is_deleted = FALSE) AS post_author_posts,
asset.object_key AS post_object_key,
asset.size AS post_object_size,
asset.position AS post_object_position,
@@ -175,18 +203,23 @@ const wallNotificationRows = `
asset.media_type AS post_object_media_type,
c.comment_id,
c.parent_comment_id,
- c.author_id AS comment_author_id,
- comment_author_wall.wall_id AS comment_author_wall_id,
- comment_author_wall.wall_slug AS comment_author,
+ comment_author_wall.owner_id, comment_author_wall.wall_id, comment_author_wall.wall_slug, comment_author_ka.public_key,
+ comment_author_wall.current_version, comment_author_wall.encrypted_profile, comment_author_wall.avatar_object_key,
+ comment_author_wall.avatar_size, comment_author_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = comment_author_wall.wall_id) AS comment_author_friends,
+ (SELECT COUNT(*) FROM wall_posts cp WHERE cp.wall_id = comment_author_wall.wall_id AND cp.is_deleted = FALSE) AS comment_author_posts,
c.comment_cipher,
c.created_at AS comment_created_at
FROM wall_comment_likes cl
JOIN wall_post_comments c ON c.comment_id = cl.comment_id
JOIN wall_posts p ON p.post_id = c.post_id
JOIN walls actor_wall ON actor_wall.owner_id = cl.user_id
+ JOIN key_attributes actor_ka ON actor_ka.user_id = cl.user_id
JOIN walls comment_author_wall ON comment_author_wall.owner_id = c.author_id
+ JOIN key_attributes comment_author_ka ON comment_author_ka.user_id = c.author_id
JOIN walls post_wall ON post_wall.wall_id = p.wall_id
JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
+ JOIN key_attributes owner_ka ON owner_ka.user_id = p.owner_id
LEFT JOIN LATERAL (
SELECT object_key, size, position, variant, blur_hash_cipher, width, height, media_type
FROM wall_post_assets
@@ -205,15 +238,16 @@ const wallNotificationRows = `
'friend_add:' || fe.event_id::text AS notification_id,
'addedYouAsFriend' AS notification_type,
fe.created_at,
- fe.actor_id,
- actor_wall.wall_slug AS actor_username,
- actor_wall.wall_id AS actor_wall_id,
- actor_wall.wall_slug AS actor_wall_slug,
+ actor_wall.owner_id, actor_wall.wall_id, actor_wall.wall_slug, actor_ka.public_key,
+ actor_wall.current_version, actor_wall.encrypted_profile, actor_wall.avatar_object_key,
+ actor_wall.avatar_size, actor_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = actor_wall.wall_id) AS actor_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = actor_wall.wall_id AND ap.is_deleted = FALSE) AS actor_posts,
NULL::bigint AS post_id,
NULL::text AS post_wall_id,
NULL::text AS post_wall_slug,
NULL::bigint AS post_owner_id,
- NULL::text AS post_author,
+ 0::bigint, ''::text, ''::text, ''::text, 0::integer, ''::text, NULL::text, NULL::bigint, 0::bigint, NULL::bigint, NULL::bigint,
NULL::text AS post_object_key,
NULL::bigint AS post_object_size,
NULL::integer AS post_object_position,
@@ -224,13 +258,12 @@ const wallNotificationRows = `
NULL::text AS post_object_media_type,
NULL::bigint AS comment_id,
NULL::bigint AS parent_comment_id,
- NULL::bigint AS comment_author_id,
- NULL::text AS comment_author_wall_id,
- NULL::text AS comment_author,
+ 0::bigint, ''::text, ''::text, ''::text, 0::integer, ''::text, NULL::text, NULL::bigint, 0::bigint, NULL::bigint, NULL::bigint,
NULL::text AS comment_cipher,
NULL::bigint AS comment_created_at
FROM wall_friend_events fe
JOIN walls actor_wall ON actor_wall.wall_id = fe.actor_wall_id
+ JOIN key_attributes actor_ka ON actor_ka.user_id = actor_wall.owner_id
WHERE fe.target_id = $1
AND fe.actor_id <> $1
`
@@ -248,12 +281,7 @@ func (r *NotificationsRepository) List(ctx context.Context, userID int64, cursor
}
rows, err := r.DB.QueryContext(ctx, `
WITH notifications AS (`+wallNotificationRows+`)
- SELECT n.notification_id, n.notification_type, n.created_at,
- n.actor_id, n.actor_username, n.actor_wall_id, n.actor_wall_slug,
- n.post_id, n.post_wall_id, n.post_wall_slug, n.post_owner_id, n.post_author,
- n.post_object_key, n.post_object_size, n.post_object_position, n.post_object_variant,
- n.post_object_blur_hash_cipher, n.post_object_width, n.post_object_height, n.post_object_media_type,
- n.comment_id, n.parent_comment_id, n.comment_author_id, n.comment_author_wall_id, n.comment_author, n.comment_cipher, n.comment_created_at
+ SELECT n.*
FROM notifications n
WHERE ($2::bigint IS NULL OR (n.created_at, n.notification_id) < ($2::bigint, $3::text))
ORDER BY n.created_at DESC, n.notification_id DESC
@@ -285,35 +313,14 @@ func (r *NotificationsRepository) List(ctx context.Context, userID int64, cursor
func scanNotificationRecord(scanner interface{ Scan(dest ...any) error }) (*WallNotificationRecord, error) {
var rec WallNotificationRecord
- if err := scanner.Scan(
- &rec.ID,
- &rec.Type,
- &rec.CreatedAt,
- &rec.ActorID,
- &rec.ActorUsername,
- &rec.ActorWallID,
- &rec.ActorWallSlug,
- &rec.PostID,
- &rec.PostWallID,
- &rec.PostWallSlug,
- &rec.PostOwnerID,
- &rec.PostAuthor,
- &rec.PostObjectKey,
- &rec.PostObjectSize,
- &rec.PostObjectPosition,
- &rec.PostObjectVariant,
- &rec.PostObjectBlurHashCipher,
- &rec.PostObjectWidth,
- &rec.PostObjectHeight,
- &rec.PostObjectMediaType,
- &rec.CommentID,
- &rec.ParentCommentID,
- &rec.CommentAuthorID,
- &rec.CommentAuthorWallID,
- &rec.CommentAuthor,
- &rec.CommentCipher,
- &rec.CommentCreatedAt,
- ); err != nil {
+ dest := []any{&rec.ID, &rec.Type, &rec.CreatedAt}
+ dest = append(dest, wallActorScanDest(&rec.Actor)...)
+ dest = append(dest, &rec.PostID, &rec.PostWallID, &rec.PostWallSlug, &rec.PostOwnerID)
+ dest = append(dest, wallActorScanDest(&rec.PostAuthor)...)
+ dest = append(dest, &rec.PostObjectKey, &rec.PostObjectSize, &rec.PostObjectPosition, &rec.PostObjectVariant, &rec.PostObjectBlurHashCipher, &rec.PostObjectWidth, &rec.PostObjectHeight, &rec.PostObjectMediaType, &rec.CommentID, &rec.ParentCommentID)
+ dest = append(dest, wallActorScanDest(&rec.CommentAuthor)...)
+ dest = append(dest, &rec.CommentCipher, &rec.CommentCreatedAt)
+ if err := scanner.Scan(dest...); err != nil {
return nil, stacktrace.Propagate(err, "")
}
return &rec, nil
diff --git a/server/wall/repo/posts.go b/server/wall/repo/posts.go
index 606088b8cf..f4f2dbcc14 100644
--- a/server/wall/repo/posts.go
+++ b/server/wall/repo/posts.go
@@ -58,16 +58,23 @@ func (r *PostsRepository) CreatePost(ctx context.Context, ownerID int64, wallID,
func (r *PostsRepository) GetPost(ctx context.Context, postID int64, viewerID int64) (*WallPostRecord, error) {
return scanPostRecord(r.DB.QueryRowContext(ctx, `
- SELECT p.post_id, p.wall_id, w.wall_slug, p.owner_id, owner_wall.wall_slug, p.encrypted_post_key, p.caption_cipher,
+ SELECT p.post_id, p.wall_id, w.wall_slug, p.owner_id,
+ owner_wall.owner_id, owner_wall.wall_id, owner_wall.wall_slug, owner_ka.public_key,
+ owner_wall.current_version, owner_wall.encrypted_profile, owner_wall.avatar_object_key,
+ owner_wall.avatar_size, owner_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = owner_wall.wall_id) AS author_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = owner_wall.wall_id AND ap.is_deleted = FALSE) AS author_posts,
+ p.encrypted_post_key, p.caption_cipher,
p.key_version, p.created_at,
(SELECT COUNT(*) FROM wall_post_likes pl WHERE pl.post_id = p.post_id) AS likes,
EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $2) AS viewer_liked,
(SELECT COUNT(*) FROM wall_post_comments pc WHERE pc.post_id = p.post_id AND pc.is_deleted = FALSE) AS comments
- FROM wall_posts p
- JOIN walls w ON w.wall_id = p.wall_id
- JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
- WHERE p.post_id = $1 AND p.is_deleted = FALSE
- `, postID, viewerID))
+ FROM wall_posts p
+ JOIN walls w ON w.wall_id = p.wall_id
+ JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
+ JOIN key_attributes owner_ka ON owner_ka.user_id = p.owner_id
+ WHERE p.post_id = $1 AND p.is_deleted = FALSE
+ `, postID, viewerID))
}
func (r *PostsRepository) ListPostsByWall(ctx context.Context, wallID string, viewerID int64, cursor string, limit int) ([]WallPostRecord, string, error) {
@@ -77,15 +84,22 @@ func (r *PostsRepository) ListPostsByWall(ctx context.Context, wallID string, vi
}
args := []any{wallID, viewerID}
query := `
- SELECT p.post_id, p.wall_id, w.wall_slug, p.owner_id, owner_wall.wall_slug, p.encrypted_post_key, p.caption_cipher,
- p.key_version, p.created_at,
- (SELECT COUNT(*) FROM wall_post_likes pl WHERE pl.post_id = p.post_id) AS likes,
- EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $2) AS viewer_liked,
- (SELECT COUNT(*) FROM wall_post_comments pc WHERE pc.post_id = p.post_id AND pc.is_deleted = FALSE) AS comments
- FROM wall_posts p
- JOIN walls w ON w.wall_id = p.wall_id
- JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
- WHERE p.wall_id = $1 AND p.is_deleted = FALSE`
+ SELECT p.post_id, p.wall_id, w.wall_slug, p.owner_id,
+ owner_wall.owner_id, owner_wall.wall_id, owner_wall.wall_slug, owner_ka.public_key,
+ owner_wall.current_version, owner_wall.encrypted_profile, owner_wall.avatar_object_key,
+ owner_wall.avatar_size, owner_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = owner_wall.wall_id) AS author_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = owner_wall.wall_id AND ap.is_deleted = FALSE) AS author_posts,
+ p.encrypted_post_key, p.caption_cipher,
+ p.key_version, p.created_at,
+ (SELECT COUNT(*) FROM wall_post_likes pl WHERE pl.post_id = p.post_id) AS likes,
+ EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $2) AS viewer_liked,
+ (SELECT COUNT(*) FROM wall_post_comments pc WHERE pc.post_id = p.post_id AND pc.is_deleted = FALSE) AS comments
+ FROM wall_posts p
+ JOIN walls w ON w.wall_id = p.wall_id
+ JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
+ JOIN key_attributes owner_ka ON owner_ka.user_id = p.owner_id
+ WHERE p.wall_id = $1 AND p.is_deleted = FALSE`
if cursorCreatedAt, cursorPostID, ok := parsePostCursor(cursor); ok {
args = append(args, cursorCreatedAt, cursorPostID)
query += ` AND (p.created_at, p.post_id) < ($3, $4)`
@@ -123,15 +137,22 @@ func (r *PostsRepository) ListFeed(ctx context.Context, viewerID int64, cursor s
}
args := []any{viewerID}
query := `
- SELECT p.post_id, p.wall_id, w.wall_slug, p.owner_id, owner_wall.wall_slug, p.encrypted_post_key, p.caption_cipher,
- p.key_version, p.created_at,
- (SELECT COUNT(*) FROM wall_post_likes pl WHERE pl.post_id = p.post_id) AS likes,
- EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $1) AS viewer_liked,
- (SELECT COUNT(*) FROM wall_post_comments pc WHERE pc.post_id = p.post_id AND pc.is_deleted = FALSE) AS comments
- FROM wall_posts p
- JOIN walls w ON w.wall_id = p.wall_id
- JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
- WHERE p.is_deleted = FALSE
+ SELECT p.post_id, p.wall_id, w.wall_slug, p.owner_id,
+ owner_wall.owner_id, owner_wall.wall_id, owner_wall.wall_slug, owner_ka.public_key,
+ owner_wall.current_version, owner_wall.encrypted_profile, owner_wall.avatar_object_key,
+ owner_wall.avatar_size, owner_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = owner_wall.wall_id) AS author_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = owner_wall.wall_id AND ap.is_deleted = FALSE) AS author_posts,
+ p.encrypted_post_key, p.caption_cipher,
+ p.key_version, p.created_at,
+ (SELECT COUNT(*) FROM wall_post_likes pl WHERE pl.post_id = p.post_id) AS likes,
+ EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $1) AS viewer_liked,
+ (SELECT COUNT(*) FROM wall_post_comments pc WHERE pc.post_id = p.post_id AND pc.is_deleted = FALSE) AS comments
+ FROM wall_posts p
+ JOIN walls w ON w.wall_id = p.wall_id
+ JOIN walls owner_wall ON owner_wall.owner_id = p.owner_id
+ JOIN key_attributes owner_ka ON owner_ka.user_id = p.owner_id
+ WHERE p.is_deleted = FALSE
AND (
p.owner_id = $1 OR
EXISTS (
@@ -268,9 +289,15 @@ func (r *PostsRepository) ListPostLikers(ctx context.Context, postID int64, curs
}
args := []any{postID}
query := `
- SELECT pl.user_id, liker_wall.wall_id, liker_wall.wall_slug, pl.created_at
+ SELECT liker_wall.owner_id, liker_wall.wall_id, liker_wall.wall_slug, liker_ka.public_key,
+ liker_wall.current_version, liker_wall.encrypted_profile, liker_wall.avatar_object_key,
+ liker_wall.avatar_size, liker_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = liker_wall.wall_id) AS liker_friends,
+ (SELECT COUNT(*) FROM wall_posts lp WHERE lp.wall_id = liker_wall.wall_id AND lp.is_deleted = FALSE) AS liker_posts,
+ pl.created_at
FROM wall_post_likes pl
JOIN walls liker_wall ON liker_wall.owner_id = pl.user_id
+ JOIN key_attributes liker_ka ON liker_ka.user_id = pl.user_id
WHERE pl.post_id = $1`
if cursorCreatedAt, cursorUserID, ok := parsePostLikerCursor(cursor); ok {
args = append(args, cursorCreatedAt, cursorUserID)
@@ -286,7 +313,9 @@ func (r *PostsRepository) ListPostLikers(ctx context.Context, postID int64, curs
out := make([]WallPostLikerRecord, 0, limit+1)
for rows.Next() {
var rec WallPostLikerRecord
- if err := rows.Scan(&rec.UserID, &rec.WallID, &rec.WallSlug, &rec.CreatedAt); err != nil {
+ dest := wallActorScanDest(&rec.Actor)
+ dest = append(dest, &rec.CreatedAt)
+ if err := rows.Scan(dest...); err != nil {
return nil, "", stacktrace.Propagate(err, "")
}
out = append(out, rec)
@@ -335,12 +364,19 @@ func (r *PostsRepository) CreateComment(ctx context.Context, postID, authorID in
func (r *PostsRepository) GetComment(ctx context.Context, commentID, viewerID int64) (*WallCommentRecord, error) {
return scanCommentRecord(r.DB.QueryRowContext(ctx, `
- SELECT c.comment_id, c.post_id, c.author_id, author_wall.wall_id, author_wall.wall_slug, c.comment_cipher, c.parent_comment_id, c.created_at,
+ SELECT c.comment_id, c.post_id,
+ author_wall.owner_id, author_wall.wall_id, author_wall.wall_slug, author_ka.public_key,
+ author_wall.current_version, author_wall.encrypted_profile, author_wall.avatar_object_key,
+ author_wall.avatar_size, author_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = author_wall.wall_id) AS author_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = author_wall.wall_id AND ap.is_deleted = FALSE) AS author_posts,
+ c.comment_cipher, c.parent_comment_id, c.created_at,
(SELECT COUNT(*) FROM wall_comment_likes cl WHERE cl.comment_id = c.comment_id) AS likes,
EXISTS (SELECT 1 FROM wall_comment_likes cl WHERE cl.comment_id = c.comment_id AND cl.user_id = $2) AS viewer_liked,
(c.author_id = $2) AS viewer_can_delete
FROM wall_post_comments c
JOIN walls author_wall ON author_wall.owner_id = c.author_id
+ JOIN key_attributes author_ka ON author_ka.user_id = c.author_id
WHERE c.comment_id = $1 AND c.is_deleted = FALSE
`, commentID, viewerID))
}
@@ -352,12 +388,19 @@ func (r *PostsRepository) ListComments(ctx context.Context, postID, viewerID int
}
args := []any{postID, viewerID}
query := `
- SELECT c.comment_id, c.post_id, c.author_id, author_wall.wall_id, author_wall.wall_slug, c.comment_cipher, c.parent_comment_id, c.created_at,
+ SELECT c.comment_id, c.post_id,
+ author_wall.owner_id, author_wall.wall_id, author_wall.wall_slug, author_ka.public_key,
+ author_wall.current_version, author_wall.encrypted_profile, author_wall.avatar_object_key,
+ author_wall.avatar_size, author_wall.updated_at,
+ (SELECT COUNT(*) FROM wall_friend_shares fs WHERE fs.wall_id = author_wall.wall_id) AS author_friends,
+ (SELECT COUNT(*) FROM wall_posts ap WHERE ap.wall_id = author_wall.wall_id AND ap.is_deleted = FALSE) AS author_posts,
+ c.comment_cipher, c.parent_comment_id, c.created_at,
(SELECT COUNT(*) FROM wall_comment_likes cl WHERE cl.comment_id = c.comment_id) AS likes,
EXISTS (SELECT 1 FROM wall_comment_likes cl WHERE cl.comment_id = c.comment_id AND cl.user_id = $2) AS viewer_liked,
(c.author_id = $2) AS viewer_can_delete
FROM wall_post_comments c
JOIN walls author_wall ON author_wall.owner_id = c.author_id
+ JOIN key_attributes author_ka ON author_ka.user_id = c.author_id
WHERE c.post_id = $1 AND c.is_deleted = FALSE`
if trimmed := strings.TrimSpace(cursor); trimmed != "" {
if cursorID, err := strconv.ParseInt(trimmed, 10, 64); err == nil && cursorID > 0 {
@@ -430,7 +473,10 @@ func (r *PostsRepository) DeleteComment(ctx context.Context, postID, commentID,
func scanPostRecord(scanner interface{ Scan(dest ...any) error }) (*WallPostRecord, error) {
var rec WallPostRecord
- if err := scanner.Scan(&rec.PostID, &rec.WallID, &rec.WallSlug, &rec.OwnerID, &rec.Author, &rec.EncryptedPostKey, &rec.CaptionCipher, &rec.KeyVersion, &rec.CreatedAt, &rec.Likes, &rec.ViewerLiked, &rec.Comments); err != nil {
+ dest := []any{&rec.PostID, &rec.WallID, &rec.WallSlug, &rec.OwnerID}
+ dest = append(dest, wallActorScanDest(&rec.Author)...)
+ dest = append(dest, &rec.EncryptedPostKey, &rec.CaptionCipher, &rec.KeyVersion, &rec.CreatedAt, &rec.Likes, &rec.ViewerLiked, &rec.Comments)
+ if err := scanner.Scan(dest...); err != nil {
return nil, stacktrace.Propagate(err, "")
}
return &rec, nil
@@ -473,12 +519,15 @@ func parsePostLikerCursor(cursor string) (int64, int64, bool) {
}
func formatPostLikerCursor(liker WallPostLikerRecord) string {
- return strconv.FormatInt(liker.CreatedAt, 10) + ":" + strconv.FormatInt(liker.UserID, 10)
+ return strconv.FormatInt(liker.CreatedAt, 10) + ":" + strconv.FormatInt(liker.Actor.UserID, 10)
}
func scanCommentRecord(scanner interface{ Scan(dest ...any) error }) (*WallCommentRecord, error) {
var rec WallCommentRecord
- if err := scanner.Scan(&rec.CommentID, &rec.PostID, &rec.AuthorID, &rec.AuthorWallID, &rec.Author, &rec.CommentCipher, &rec.ParentCommentID, &rec.CreatedAt, &rec.Likes, &rec.ViewerLiked, &rec.ViewerCanDelete); err != nil {
+ dest := []any{&rec.CommentID, &rec.PostID}
+ dest = append(dest, wallActorScanDest(&rec.Author)...)
+ dest = append(dest, &rec.CommentCipher, &rec.ParentCommentID, &rec.CreatedAt, &rec.Likes, &rec.ViewerLiked, &rec.ViewerCanDelete)
+ if err := scanner.Scan(dest...); err != nil {
return nil, stacktrace.Propagate(err, "")
}
return &rec, nil
diff --git a/web/packages/wasm/src/wall.rs b/web/packages/wasm/src/wall.rs
index 066524d370..ebc6f8f7be 100644
--- a/web/packages/wasm/src/wall.rs
+++ b/web/packages/wasm/src/wall.rs
@@ -4,8 +4,9 @@ use ente_core::http::Error as HttpError;
use ente_wall::{
AccountWallCtx, AuthKeyAttributes, CommentResponse, CreatedWall, CreatedWallLink,
DecryptedPost, DecryptedWallProfile, OpenAccountWallCtxInput, OpenWallLinkCtxInput,
- PostResponse, PrivateKeySource, ProfileAvatarResponse, WallError as CoreWallError, WallLinkCtx,
- WallNotification, WallNotificationComment, WallNotificationPost,
+ PostResponse, PrivateKeySource, ProfileAvatarResponse, WallActorResponse,
+ WallError as CoreWallError, WallLinkCtx, WallNotification, WallNotificationComment,
+ WallNotificationPost,
crypto::{decode_b64, encode_b64},
};
use serde::{Deserialize, Serialize};
@@ -133,6 +134,20 @@ struct WallProfileJs {
updated_at: Option<String>,
}
+#[derive(Serialize)]
+#[serde(rename_all = "camelCase")]
+struct ActorJs {
+ user_id: i64,
+ wall_id: String,
+ wall_slug: String,
+ public_key: String,
+ key_version: i32,
+ profile: Option<String>,
+ avatar: Option<ProfileAvatarResponse>,
+ friends: Option<i64>,
+ posts: Option<i64>,
+}
+
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct PostJs {
@@ -140,7 +155,7 @@ struct PostJs {
wall_id: String,
wall_slug: String,
owner_user_id: i64,
- author: String,
+ author: ActorJs,
caption: Option<String>,
key_version: i32,
objects: Vec<ente_wall::PostObjectPayload>,
@@ -161,9 +176,7 @@ struct PostPageJs {
#[serde(rename_all = "camelCase")]
struct CommentJs {
comment_id: i64,
- author_id: i64,
- author_wall_id: String,
- author: String,
+ author: ActorJs,
comment: String,
created_at: String,
likes: i64,
@@ -183,14 +196,23 @@ struct CommentPageJs {
#[serde(rename_all = "camelCase")]
struct NotificationCommentJs {
comment_id: i64,
- author_id: i64,
- author_wall_id: String,
- author: String,
+ author: ActorJs,
comment: Option<String>,
created_at: String,
parent_comment_id: Option<i64>,
}
+#[derive(Serialize)]
+#[serde(rename_all = "camelCase")]
+struct NotificationPostJs {
+ post_id: i64,
+ wall_id: String,
+ wall_slug: String,
+ owner_user_id: i64,
+ author: ActorJs,
+ objects: Vec<ente_wall::PostObjectPayload>,
+}
+
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct NotificationJs {
@@ -198,8 +220,8 @@ struct NotificationJs {
#[serde(rename = "type")]
notification_type: ente_wall::WallNotificationType,
created_at: String,
- actor: ente_wall::WallNotificationActor,
- post: Option<WallNotificationPost>,
+ actor: ActorJs,
+ post: Option<NotificationPostJs>,
comment: Option<NotificationCommentJs>,
}
@@ -210,6 +232,28 @@ struct NotificationPageJs {
next_cursor: String,
}
+#[derive(Serialize)]
+#[serde(rename_all = "camelCase")]
+struct PostLikerJs {
+ actor: ActorJs,
+ created_at: String,
+}
+
+#[derive(Serialize)]
+#[serde(rename_all = "camelCase")]
+struct PostLikerPageJs {
+ likers: Vec<PostLikerJs>,
+ next_cursor: String,
+}
+
+#[derive(Serialize)]
+#[serde(rename_all = "camelCase")]
+struct FriendJs {
+ friend: ActorJs,
+ share_key_version: i32,
+ created_at: String,
+}
+
fn decode_b64_field(value: &str) -> Result<Vec<u8>, WasmWallError> {
decode_b64(value)
.map_err(CoreWallError::from)
@@ -260,13 +304,73 @@ fn profile_to_js(value: DecryptedWallProfile) -> Result<WallProfileJs, WasmWallE
})
}
-fn post_to_js(post: PostResponse, decrypted: DecryptedPost) -> Result<PostJs, WasmWallError> {
+fn actor_to_js(
+ actor: WallActorResponse,
+ profile: Option<Vec<u8>>,
+) -> Result<ActorJs, WasmWallError> {
+ Ok(ActorJs {
+ user_id: actor.user_id,
+ wall_id: actor.wall_id,
+ wall_slug: actor.wall_slug,
+ public_key: actor.public_key,
+ key_version: actor.key_version,
+ profile: optional_utf8_field(profile, "actor profile")?,
+ avatar: actor.avatar,
+ friends: actor.friends,
+ posts: actor.posts,
+ })
+}
+
+async fn account_actor_to_js(
+ ctx: &AccountWallCtx,
+ actor: WallActorResponse,
+) -> Result<ActorJs, WasmWallError> {
+ let profile = ctx.decrypt_actor_profile(&actor).await?;
+ actor_to_js(actor, profile)
+}
+
+async fn link_actor_to_js(
+ ctx: &WallLinkCtx,
+ actor: WallActorResponse,
+) -> Result<ActorJs, WasmWallError> {
+ let profile = ctx.decrypt_actor_profile(&actor).await?;
+ actor_to_js(actor, profile)
+}
+
+async fn account_post_to_js(
+ ctx: &AccountWallCtx,
+ post: PostResponse,
+ decrypted: DecryptedPost,
+) -> Result<PostJs, WasmWallError> {
+ let author = account_actor_to_js(ctx, post.author).await?;
+ Ok(PostJs {
+ post_id: post.post_id,
+ wall_id: post.wall_id,
+ wall_slug: post.wall_slug,
+ owner_user_id: post.owner_user_id,
+ author,
+ caption: optional_utf8_field(decrypted.caption_plaintext, "caption")?,
+ key_version: post.key_version,
+ objects: post.objects,
+ created_at: post.created_at,
+ likes: post.likes,
+ viewer_liked: post.viewer_liked,
+ comments: post.comments,
+ })
+}
+
+async fn link_post_to_js(
+ ctx: &WallLinkCtx,
+ post: PostResponse,
+ decrypted: DecryptedPost,
+) -> Result<PostJs, WasmWallError> {
+ let author = link_actor_to_js(ctx, post.author).await?;
Ok(PostJs {
post_id: post.post_id,
wall_id: post.wall_id,
wall_slug: post.wall_slug,
owner_user_id: post.owner_user_id,
- author: post.author,
+ author,
caption: optional_utf8_field(decrypted.caption_plaintext, "caption")?,
key_version: post.key_version,
objects: post.objects,
@@ -277,15 +381,33 @@ fn post_to_js(post: PostResponse, decrypted: DecryptedPost) -> Result<PostJs, Wa
})
}
-fn comment_to_js(
+async fn account_comment_to_js(
+ ctx: &AccountWallCtx,
+ comment: CommentResponse,
+ decrypted: ente_wall::DecryptedComment,
+) -> Result<CommentJs, WasmWallError> {
+ let author = account_actor_to_js(ctx, comment.author).await?;
+ Ok(CommentJs {
+ comment_id: comment.comment_id,
+ author,
+ comment: utf8_field(decrypted.plaintext, "comment")?,
+ created_at: comment.created_at,
+ likes: comment.likes,
+ viewer_liked: comment.viewer_liked,
+ viewer_can_delete: comment.viewer_can_delete,
+ parent_comment_id: comment.parent_comment_id,
+ })
+}
+
+async fn link_comment_to_js(
+ ctx: &WallLinkCtx,
comment: CommentResponse,
decrypted: ente_wall::DecryptedComment,
) -> Result<CommentJs, WasmWallError> {
+ let author = link_actor_to_js(ctx, comment.author).await?;
Ok(CommentJs {
comment_id: comment.comment_id,
- author_id: comment.author_id,
- author_wall_id: comment.author_wall_id,
- author: comment.author,
+ author,
comment: utf8_field(decrypted.plaintext, "comment")?,
created_at: comment.created_at,
likes: comment.likes,
@@ -302,7 +424,7 @@ async fn account_post_page_to_js(
let mut items = Vec::with_capacity(page.items.len());
for post in page.items {
let decrypted = ctx.decrypt_post_for_wall(&post.wall_id, &post).await?;
- items.push(post_to_js(post, decrypted)?);
+ items.push(account_post_to_js(ctx, post, decrypted).await?);
}
Ok(PostPageJs {
items,
@@ -317,7 +439,7 @@ async fn link_post_page_to_js(
let mut items = Vec::with_capacity(page.items.len());
for post in page.items {
let decrypted = ctx.decrypt_post(&post).await?;
- items.push(post_to_js(post, decrypted)?);
+ items.push(link_post_to_js(ctx, post, decrypted).await?);
}
Ok(PostPageJs {
items,
@@ -337,7 +459,7 @@ async fn account_comment_page_to_js(
let mut comments = Vec::with_capacity(page.comments.len());
for comment in page.comments {
let decrypted = ctx.decrypt_comment(&decrypted_post.post_key, &comment)?;
- comments.push(comment_to_js(comment, decrypted)?);
+ comments.push(account_comment_to_js(ctx, comment, decrypted).await?);
}
Ok(CommentPageJs {
comments,
@@ -357,7 +479,7 @@ async fn link_comment_page_to_js(
let mut comments = Vec::with_capacity(page.comments.len());
for comment in page.comments {
let decrypted = ctx.decrypt_comment(&decrypted_post.post_key, &comment)?;
- comments.push(comment_to_js(comment, decrypted)?);
+ comments.push(link_comment_to_js(ctx, comment, decrypted).await?);
}
Ok(CommentPageJs {
comments,
@@ -369,25 +491,43 @@ async fn notification_to_js(
ctx: &AccountWallCtx,
notification: WallNotification,
) -> Result<NotificationJs, WasmWallError> {
+ let post = match notification.post {
+ Some(post) => Some(notification_post_to_js(ctx, post).await?),
+ None => None,
+ };
let comment = match notification.comment {
- Some(comment) => {
- Some(notification_comment_to_js(ctx, notification.post.as_ref(), comment).await?)
- }
+ Some(comment) => Some(notification_comment_to_js(ctx, post.as_ref(), comment).await?),
None => None,
};
+ let actor = account_actor_to_js(ctx, notification.actor).await?;
Ok(NotificationJs {
id: notification.id,
notification_type: notification.notification_type,
created_at: notification.created_at,
- actor: notification.actor,
- post: notification.post,
+ actor,
+ post,
comment,
})
}
+async fn notification_post_to_js(
+ ctx: &AccountWallCtx,
+ post: WallNotificationPost,
+) -> Result<NotificationPostJs, WasmWallError> {
+ let author = account_actor_to_js(ctx, post.author).await?;
+ Ok(NotificationPostJs {
+ post_id: post.post_id,
+ wall_id: post.wall_id,
+ wall_slug: post.wall_slug,
+ owner_user_id: post.owner_user_id,
+ author,
+ objects: post.objects,
+ })
+}
+
async fn notification_comment_to_js(
ctx: &AccountWallCtx,
- post: Option<&WallNotificationPost>,
+ post: Option<&NotificationPostJs>,
comment: WallNotificationComment,
) -> Result<NotificationCommentJs, WasmWallError> {
let plaintext = if comment.comment_cipher.trim().is_empty() {
@@ -397,8 +537,6 @@ async fn notification_comment_to_js(
let decrypted_post = ctx.decrypt_post_for_wall(&post.wall_id, &post).await?;
let comment_response = CommentResponse {
comment_id: comment.comment_id,
- author_id: comment.author_id,
- author_wall_id: comment.author_wall_id.clone(),
author: comment.author.clone(),
comment_cipher: comment.comment_cipher.clone(),
created_at: comment.created_at.clone(),
@@ -415,11 +553,10 @@ async fn notification_comment_to_js(
} else {
None
};
+ let author = account_actor_to_js(ctx, comment.author).await?;
Ok(NotificationCommentJs {
comment_id: comment.comment_id,
- author_id: comment.author_id,
- author_wall_id: comment.author_wall_id,
- author: comment.author,
+ author,
comment: plaintext,
created_at: comment.created_at,
parent_comment_id: comment.parent_comment_id,
@@ -635,7 +772,7 @@ impl WallAccountCtxHandle {
wall_id: item.wall_id,
wall_slug: item.wall_slug.clone(),
owner_user_id: item.owner_user_id,
- author: item.wall_slug,
+ author: item.author,
encrypted_post_key: item.encrypted_post_key,
caption_cipher: item.caption_cipher,
key_version: item.key_version,
@@ -700,7 +837,7 @@ impl WallAccountCtxHandle {
.inner
.decrypt_post_for_wall(&post.wall_id, &post)
.await?;
- swb::to_value(&post_to_js(post, decrypted)?).map_err(Into::into)
+ swb::to_value(&account_post_to_js(&self.inner, post, decrypted).await?).map_err(Into::into)
}
/// Download and decrypt one object from a wall post.
@@ -746,8 +883,19 @@ impl WallAccountCtxHandle {
cursor: Option<String>,
limit: Option<i32>,
) -> Result<JsValue, WasmWallError> {
- swb::to_value(&self.inner.list_post_likers(post_id, cursor, limit).await?)
- .map_err(Into::into)
+ let page = self.inner.list_post_likers(post_id, cursor, limit).await?;
+ let mut likers = Vec::with_capacity(page.likers.len());
+ for liker in page.likers {
+ likers.push(PostLikerJs {
+ actor: account_actor_to_js(&self.inner, liker.actor).await?,
+ created_at: liker.created_at,
+ });
+ }
+ swb::to_value(&PostLikerPageJs {
+ likers,
+ next_cursor: page.next_cursor,
+ })
+ .map_err(Into::into)
}
/// List comments with plaintext decrypted.
@@ -785,7 +933,8 @@ impl WallAccountCtxHandle {
let decrypted = self
.inner
.decrypt_comment(&decrypted_post.post_key, &response)?;
- swb::to_value(&comment_to_js(response, decrypted)?).map_err(Into::into)
+ swb::to_value(&account_comment_to_js(&self.inner, response, decrypted).await?)
+ .map_err(Into::into)
}
/// Like or unlike a comment.
@@ -835,7 +984,16 @@ impl WallAccountCtxHandle {
/// List friends for a wall.
pub async fn list_wall_friends(&self, wall_id: String) -> Result<JsValue, WasmWallError> {
- swb::to_value(&self.inner.list_wall_friends(&wall_id).await?).map_err(Into::into)
+ let friends = self.inner.list_wall_friends(&wall_id).await?;
+ let mut items = Vec::with_capacity(friends.len());
+ for friend in friends {
+ items.push(FriendJs {
+ friend: account_actor_to_js(&self.inner, friend.friend).await?,
+ share_key_version: friend.share_key_version,
+ created_at: friend.created_at,
+ });
+ }
+ swb::to_value(&items).map_err(Into::into)
}
/// Remove a friend by their wall ID.
@@ -944,7 +1102,18 @@ impl WallLinkCtxHandle {
cursor: Option<String>,
limit: Option<i32>,
) -> Result<JsValue, WasmWallError> {
- swb::to_value(&self.inner.list_post_likers(post_id, cursor, limit).await?)
- .map_err(Into::into)
+ let page = self.inner.list_post_likers(post_id, cursor, limit).await?;
+ let mut likers = Vec::with_capacity(page.likers.len());
+ for liker in page.likers {
+ likers.push(PostLikerJs {
+ actor: link_actor_to_js(&self.inner, liker.actor).await?,
+ created_at: liker.created_at,
+ });
+ }
+ swb::to_value(&PostLikerPageJs {
+ likers,
+ next_cursor: page.next_cursor,
+ })
+ .map_err(Into::into)
}
}