π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove wall comments code
Anand Baburajanc8dbc5d1dc73
diff --git a/rust/e2e/tests/wall_e2e.rs b/rust/e2e/tests/wall_e2e.rsindex 54fa26f5fa..f2699c8540 100644--- a/rust/e2e/tests/wall_e2e.rs+++ b/rust/e2e/tests/wall_e2e.rs@@ -100,7 +100,7 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {.upload_post_asset(&post_key, b"wall e2e encrypted post asset", Some(0)).await.expect("post asset upload should succeed");- let (post_id, post_key) = owner_ctx+ let (post_id, _post_key) = owner_ctx.create_post(&owner_wall.wall_id,&[object],@@ -221,30 +221,6 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {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- .expect("comment creation should succeed");- owner_ctx- .create_comment(post_id, &post_key, b"thanks", Some(top_level.comment_id))- .await- .expect("reply creation should succeed");-- let comments = friend_ctx- .list_comments(post_id, None, None)- .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");- let reply = friend_ctx- .decrypt_comment(&post_key, &comments.comments[0])- .expect("reply comment should decrypt");- assert_eq!(parent.plaintext, b"looks great");- assert_eq!(reply.plaintext, b"thanks");let notifications = owner_ctx.list_notifications(None, Some(10))@@ -296,22 +272,6 @@ async fn wall_bootstrap_posts_friend_share_and_link_suite() {link_post.caption_plaintext.as_deref(),Some(br#"{"caption":"hello world"}"#.as_slice()));- let link_comments = link_ctx- .list_comments(post_id, None, None)- .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");- let link_reply = link_ctx- .decrypt_comment(&link_post.post_key, &link_comments.comments[0])- .expect("link session should decrypt reply comment");- assert_eq!(link_parent.plaintext, b"looks great");- assert_eq!(link_reply.plaintext, b"thanks");owner_ctx.delete_wall_link(&owner_wall.wall_id)diff --git a/rust/wall/src/client.rs b/rust/wall/src/client.rsindex 3b33d0cf62..d971162f77 100644--- a/rust/wall/src/client.rs+++ b/rust/wall/src/client.rs@@ -8,22 +8,21 @@ use crate::crypto::{};use crate::error::{Result, WallError};use crate::models::{- CreatedWall, CreatedWallLink, DecryptedComment, DecryptedFriendShare, DecryptedPost,- DecryptedWallProfile, FeedItem, FeedPage, HydratedKeys, OpenAccountWallCtxInput,- OpenWallLinkCtxInput, PrivateKeySource,+ CreatedWall, CreatedWallLink, DecryptedFriendShare, DecryptedPost, DecryptedWallProfile,+ FeedItem, FeedPage, HydratedKeys, OpenAccountWallCtxInput, OpenWallLinkCtxInput,+ PrivateKeySource,};use crate::transport::{- AddFriendPayload, AssetDownloadResponse, CommentResponse, CreateCommentRequest,- CreateEntityKeyRequest, CreatePostRequest, CreatePostResponse, CreateWallRequest,- EntityKeyPayload, EntityKeyResponse, FriendRelationshipResponse, FriendShareResponse,- FriendStatusResponse, FriendTargetPayload, LikeCommentRequest, LikeCommentResponse,- LikePostRequest, LikePostResponse, ListCommentsResponse, ListPostLikersResponse,- PostObjectPayload, PostPage, PostResponse, PresignUploadRequest, PresignUploadResponse,- ProfileAvatarPayload, RefreshFriendSharesRequest, RotateWallKeyRequest, ShareUpdatePayload,- UpdatePostCaptionRequest, UpdateWallProfileRequest, UpdateWallProfileResponse,- UpdateWallSlugRequest, WallActorResponse, WallFriendResponse, WallKeyResponse,- WallKeyVersionResponse, WallLinkCreateRequest, WallLinkLoginRequest, WallLinkLoginResponse,- WallLinkStatusResponse, WallLookupResponse, WallNotificationPage, WallProfileResponse,+ AddFriendPayload, AssetDownloadResponse, CreateEntityKeyRequest, CreatePostRequest,+ CreatePostResponse, CreateWallRequest, EntityKeyPayload, EntityKeyResponse,+ FriendRelationshipResponse, FriendShareResponse, FriendStatusResponse, FriendTargetPayload,+ LikePostRequest, LikePostResponse, ListPostLikersResponse, PostObjectPayload, PostPage,+ PostResponse, PresignUploadRequest, PresignUploadResponse, ProfileAvatarPayload,+ RefreshFriendSharesRequest, RotateWallKeyRequest, ShareUpdatePayload, UpdatePostCaptionRequest,+ UpdateWallProfileRequest, UpdateWallProfileResponse, 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};@@ -794,77 +793,6 @@ impl AccountWallCtx {.map_err(Into::into)}- pub async fn like_comment(- &self,- post_id: i64,- comment_id: i64,- like: bool,- ) -> Result<LikeCommentResponse> {- let path = format!("/wall/posts/{post_id}/comments/{comment_id}/like");- let request = LikeCommentRequest { like };- self.client- .post_json(&path, &request)- .await- .map_err(Into::into)- }-- pub async fn list_comments(- &self,- post_id: i64,- limit: Option<i32>,- cursor: Option<i64>,- ) -> Result<ListCommentsResponse> {- let mut query = Vec::new();- if let Some(value) = limit {- query.push(("limit", value.to_string()));- }- if let Some(value) = cursor {- query.push(("cursor", value.to_string()));- }- let path = format!("/wall/posts/{post_id}/comments");- self.client- .get_json(&path, &query)- .await- .map_err(Into::into)- }-- pub async fn create_comment(- &self,- post_id: i64,- post_key: &[u8],- plaintext: &[u8],- parent_comment_id: Option<i64>,- ) -> Result<CommentResponse> {- let request = CreateCommentRequest {- comment_cipher: encode_b64(&encrypt_secretbox_packed(post_key, plaintext)?),- parent_comment_id,- };- let path = format!("/wall/posts/{post_id}/comments");- self.client- .post_json(&path, &request)- .await- .map_err(Into::into)- }-- pub fn decrypt_comment(- &self,- post_key: &[u8],- comment: &CommentResponse,- ) -> Result<DecryptedComment> {- let packed = decode_b64(&comment.comment_cipher)?;- Ok(DecryptedComment {- plaintext: decrypt_secretbox_packed(post_key, &packed)?,- })- }-- pub async fn delete_comment(&self, post_id: i64, comment_id: i64) -> Result<()> {- let path = format!("/wall/posts/{post_id}/comments/{comment_id}");- self.client- .delete_empty(&path, &[])- .await- .map_err(Into::into)- }-pub async fn add_friend_from_link(&self, link: &WallLinkCtx) -> Result<FriendStatusResponse> {if link.owner_public_key().is_empty() {return Err(WallError::InvalidInput(@@ -1073,7 +1001,6 @@ fn post_response_from_feed_item(item: &FeedItem) -> PostResponse {created_at: item.created_at.clone(),likes: item.likes,viewer_liked: item.viewer_liked,- comments: item.comments,}}@@ -1254,37 +1181,6 @@ impl WallLinkCtx {.await}- pub async fn list_comments(- &self,- post_id: i64,- limit: Option<i32>,- cursor: Option<i64>,- ) -> Result<ListCommentsResponse> {- let mut query = Vec::new();- if let Some(value) = limit {- query.push(("limit", value.to_string()));- }- if let Some(value) = cursor {- query.push(("cursor", value.to_string()));- }- let path = format!("/wall/posts/{post_id}/comments");- self.client- .get_json(&path, &query)- .await- .map_err(Into::into)- }-- pub fn decrypt_comment(- &self,- post_key: &[u8],- comment: &CommentResponse,- ) -> Result<DecryptedComment> {- let packed = decode_b64(&comment.comment_cipher)?;- Ok(DecryptedComment {- plaintext: decrypt_secretbox_packed(post_key, &packed)?,- })- }-pub async fn list_post_likers(&self,post_id: i64,@@ -1772,7 +1668,6 @@ mod tests {created_at: "2026-04-16T00:00:00Z".to_owned(),likes: 0,viewer_liked: false,- comments: 0,};let decrypted = ctx@@ -2301,12 +2196,6 @@ mod tests {.with_status(200).create_async().await;- let delete_comment = server- .mock("DELETE", "/wall/posts/42/comments/7")- .match_header("x-auth-token", "token")- .with_status(200)- .create_async()- .await;let unfriend_wall = server.mock("POST", "/wall/friends/unfriend").match_header("x-auth-token", "token")@@ -2329,9 +2218,6 @@ mod tests {ctx.delete_post(42).await.expect("delete post should accept empty response");- ctx.delete_comment(42, 7)- .await- .expect("delete comment should accept empty response");ctx.unfriend_by_wall("wall_owner_main").await.expect("unfriend by wall should accept empty response");@@ -2340,7 +2226,6 @@ mod tests {.expect("unfriend by username should accept empty response");delete_post.assert_async().await;- delete_comment.assert_async().await;unfriend_wall.assert_async().await;unfriend_username.assert_async().await;}@@ -2386,28 +2271,6 @@ mod tests {like.assert_async().await;}- #[tokio::test]- async fn like_comment_uses_comment_like_endpoint() {- let mut server = Server::new_async().await;- let ctx = test_account_ctx(&server.url());- let like = server- .mock("POST", "/wall/posts/42/comments/7/like")- .match_header("x-auth-token", "token")- .match_body(Matcher::JsonString(json!({"like": true}).to_string()))- .with_status(200)- .with_body(json!({"liked": true}).to_string())- .create_async()- .await;-- let response = ctx- .like_comment(42, 7, true)- .await- .expect("comment like should succeed");-- assert!(response.liked);- like.assert_async().await;- }-#[tokio::test]async fn list_post_likers_uses_post_likes_endpoint() {let mut server = Server::new_async().await;@@ -2447,52 +2310,6 @@ mod tests {likers.assert_async().await;}- #[tokio::test]- async fn list_comments_uses_post_comments_endpoint() {- let mut server = Server::new_async().await;- let ctx = test_account_ctx(&server.url());- let comments = server- .mock("GET", "/wall/posts/42/comments")- .match_header("x-auth-token", "token")- .match_query(Matcher::AllOf(vec![- Matcher::UrlEncoded("cursor".into(), "7".into()),- Matcher::UrlEncoded("limit".into(), "5".into()),- ]))- .with_status(200)- .with_body(- json!({- "comments": [{- "commentId": 7,- "author": {- "userId": 8,- "wallId": "wall_commenter",- "wallSlug": "commenter"- },- "commentCipher": "cGFja2Vk",- "createdAt": "2026-04-16T00:00:00Z",- "likes": 2,- "viewerLiked": true,- "viewerCanDelete": false,- "parentCommentId": 3- }],- "nextCursor": "6"- })- .to_string(),- )- .create_async()- .await;-- let response = ctx- .list_comments(42, Some(5), Some(7))- .await- .expect("comments should load");-- assert_eq!(response.comments[0].comment_id, 7);- assert_eq!(response.comments[0].parent_comment_id, Some(3));- assert_eq!(response.next_cursor, "6");- comments.assert_async().await;- }-#[tokio::test]async fn list_wall_friends_uses_wall_friends_endpoint() {let mut server = Server::new_async().await;@@ -2818,8 +2635,7 @@ mod tests {"objects": [],"createdAt": "2026-04-16T00:00:00Z","likes": 2,- "viewerLiked": true,- "comments": 1+ "viewerLiked": true}],"nextCursor": "cursor-2"})@@ -2928,8 +2744,7 @@ mod tests {"objects": [],"createdAt": "2026-04-16T00:00:00Z","likes": 2,- "viewerLiked": true,- "comments": 1+ "viewerLiked": true}],"nextCursor": "41"})@@ -3014,8 +2829,7 @@ mod tests {"objects": [],"createdAt": "2026-04-16T00:00:00Z","likes": 0,- "viewerLiked": false,- "comments": 0+ "viewerLiked": false}).to_string(),)diff --git a/rust/wall/src/lib.rs b/rust/wall/src/lib.rsindex 0c4fca03b2..4809583aa6 100644--- a/rust/wall/src/lib.rs+++ b/rust/wall/src/lib.rs@@ -7,16 +7,15 @@ pub mod transport;pub use client::{AccountWallCtx, WallLinkCtx};pub use error::{Result, WallError};pub use models::{- AuthKeyAttributes, CreatedWall, CreatedWallLink, DecryptedComment, DecryptedFriendShare,- DecryptedPost, DecryptedWallProfile, FeedItem, FeedPage, HydratedKeys, OpenAccountWallCtxInput,+ AuthKeyAttributes, CreatedWall, CreatedWallLink, DecryptedFriendShare, DecryptedPost,+ DecryptedWallProfile, FeedItem, FeedPage, HydratedKeys, OpenAccountWallCtxInput,OpenWallLinkCtxInput, PrivateKeySource,};pub use transport::{- CommentResponse, EntityKeyPayload, FriendRelationshipResponse, FriendShareResponse,- FriendStatusResponse, LikeCommentResponse, LikePostResponse, ListPostLikersResponse,- PostLikerResponse, PostObjectPayload, PostPage, PostResponse, PresignUploadResponse,- ProfileAvatarPayload, ProfileAvatarResponse, WallActorResponse, WallFriendResponse,- WallKeyResponse, WallKeyVersionResponse, WallLinkLoginResponse, WallLinkStatusResponse,- WallLookupResponse, WallNotification, WallNotificationComment, WallNotificationPage,- WallNotificationPost, WallNotificationType, WallProfileResponse,+ EntityKeyPayload, FriendRelationshipResponse, FriendShareResponse, FriendStatusResponse,+ LikePostResponse, ListPostLikersResponse, PostLikerResponse, PostObjectPayload, PostPage,+ PostResponse, PresignUploadResponse, ProfileAvatarPayload, ProfileAvatarResponse,+ WallActorResponse, WallFriendResponse, WallKeyResponse, WallKeyVersionResponse,+ WallLinkLoginResponse, WallLinkStatusResponse, WallLookupResponse, WallNotification,+ WallNotificationPage, WallNotificationPost, WallNotificationType, WallProfileResponse,};diff --git a/rust/wall/src/models.rs b/rust/wall/src/models.rsindex c16e1c6e2a..38099ea9c1 100644--- a/rust/wall/src/models.rs+++ b/rust/wall/src/models.rs@@ -79,11 +79,6 @@ pub struct DecryptedPost {pub caption_plaintext: Option<Vec<u8>>,}-#[derive(Debug, Clone)]-pub struct DecryptedComment {- pub plaintext: Vec<u8>,-}-#[derive(Debug, Clone)]pub struct DecryptedFriendShare {pub friend: String,@@ -110,7 +105,6 @@ pub struct FeedItem {pub created_at: String,pub likes: i64,pub viewer_liked: bool,- pub comments: i64,}#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]diff --git a/rust/wall/src/transport.rs b/rust/wall/src/transport.rsindex f2ab27ddba..9b1a66da4b 100644--- a/rust/wall/src/transport.rs+++ b/rust/wall/src/transport.rs@@ -128,17 +128,6 @@ pub struct LikePostResponse {pub liked: bool,}-#[derive(Debug, Clone, Serialize)]-#[serde(rename_all = "camelCase")]-pub struct LikeCommentRequest {- pub like: bool,-}--#[derive(Debug, Clone, Serialize, Deserialize)]-pub struct LikeCommentResponse {- pub liked: bool,-}-#[derive(Debug, Clone, Serialize)]#[serde(rename_all = "camelCase")]pub struct UpdatePostCaptionRequest {@@ -164,7 +153,6 @@ pub struct PostResponse {pub created_at: String,pub likes: i64,pub viewer_liked: bool,- pub comments: i64,}#[derive(Debug, Clone, Serialize, Deserialize)]@@ -175,45 +163,10 @@ pub struct PostPage {pub next_cursor: String,}-#[derive(Debug, Clone, Serialize)]-#[serde(rename_all = "camelCase")]-pub struct CreateCommentRequest {- pub comment_cipher: String,- #[serde(skip_serializing_if = "Option::is_none")]- pub parent_comment_id: Option<i64>,-}--#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct CommentResponse {- pub comment_id: i64,- pub author: WallActorResponse,- pub comment_cipher: String,- pub created_at: String,- #[serde(default)]- pub likes: i64,- #[serde(default)]- pub viewer_liked: bool,- pub viewer_can_delete: bool,- #[serde(default)]- pub parent_comment_id: Option<i64>,-}--#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct ListCommentsResponse {- pub comments: Vec<CommentResponse>,- #[serde(default)]- pub next_cursor: String,-}-#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]#[serde(rename_all = "camelCase")]pub enum WallNotificationType {LikedPost,- CommentedOnPost,- LikedComment,- RepliedToComment,AddedYouAsFriend,}@@ -251,19 +204,6 @@ pub struct WallNotificationPost {pub objects: Vec<PostObjectPayload>,}-#[derive(Debug, Clone, Serialize, Deserialize)]-#[serde(rename_all = "camelCase")]-pub struct WallNotificationComment {- pub comment_id: i64,- pub author: WallActorResponse,- #[serde(default)]- pub comment_cipher: String,- #[serde(default)]- pub created_at: String,- #[serde(default)]- pub parent_comment_id: Option<i64>,-}-#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct WallNotification {@@ -274,8 +214,6 @@ pub struct WallNotification {pub actor: WallActorResponse,#[serde(default)]pub post: Option<WallNotificationPost>,- #[serde(default)]- pub comment: Option<WallNotificationComment>,}#[derive(Debug, Clone, Serialize, Deserialize)]diff --git a/server/migrations/121_wall.down.sql b/server/migrations/121_wall.down.sqlindex be317fd327..5e66733d7a 100644--- a/server/migrations/121_wall.down.sql+++ b/server/migrations/121_wall.down.sql@@ -8,11 +8,6 @@ DROP TABLE IF EXISTS wall_friend_events;DROP TRIGGER IF EXISTS update_wall_friend_shares_updated_at ON wall_friend_shares;DROP TABLE IF EXISTS wall_friend_shares;-DROP TABLE IF EXISTS wall_comment_likes;--DROP TRIGGER IF EXISTS update_wall_post_comments_updated_at ON wall_post_comments;-DROP TABLE IF EXISTS wall_post_comments;-DROP TABLE IF EXISTS wall_post_likes;DROP TABLE IF EXISTS wall_temp_objects;DROP TABLE IF EXISTS wall_post_assets;diff --git a/server/migrations/121_wall.up.sql b/server/migrations/121_wall.up.sqlindex 58b0319bc7..96976b5346 100644--- a/server/migrations/121_wall.up.sql+++ b/server/migrations/121_wall.up.sql@@ -109,42 +109,8 @@ CREATE TABLE IF NOT EXISTS wall_post_likes (CREATE INDEX IF NOT EXISTS idx_wall_post_likes_post_idON wall_post_likes (post_id);-CREATE TABLE IF NOT EXISTS wall_post_comments (- comment_id BIGSERIAL PRIMARY KEY,- post_id BIGINT NOT NULL REFERENCES wall_posts (post_id) ON DELETE CASCADE,- parent_comment_id BIGINT REFERENCES wall_post_comments (comment_id) ON DELETE CASCADE,- author_id BIGINT NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,- comment_cipher TEXT NOT NULL,- is_deleted BOOLEAN NOT NULL DEFAULT FALSE,- created_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(),- updated_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds()-);--CREATE INDEX IF NOT EXISTS idx_wall_post_comments_post_created- ON wall_post_comments (post_id, created_at DESC)- WHERE is_deleted = FALSE;--CREATE INDEX IF NOT EXISTS idx_wall_post_comments_parent- ON wall_post_comments (parent_comment_id, created_at ASC)- WHERE is_deleted = FALSE;--CREATE TRIGGER update_wall_post_comments_updated_at- BEFORE UPDATE ON wall_post_comments- FOR EACH ROW-EXECUTE PROCEDURE trigger_updated_at_microseconds_column();--CREATE TABLE IF NOT EXISTS wall_comment_likes (- comment_id BIGINT NOT NULL REFERENCES wall_post_comments (comment_id) ON DELETE CASCADE,- user_id BIGINT NOT NULL REFERENCES users (user_id) ON DELETE CASCADE,- created_at BIGINT NOT NULL DEFAULT now_utc_micro_seconds(),- PRIMARY KEY (comment_id, user_id)-);--CREATE INDEX IF NOT EXISTS idx_wall_comment_likes_comment_id- ON wall_comment_likes (comment_id);--CREATE INDEX IF NOT EXISTS idx_wall_comment_likes_user_id- ON wall_comment_likes (user_id, created_at DESC);+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 TABLE IF NOT EXISTS wall_friend_shares (wall_id TEXT NOT NULL REFERENCES walls (wall_id) ON DELETE CASCADE,diff --git a/server/migrations/122_wall_social_indexes.down.sql b/server/migrations/122_wall_social_indexes.down.sqldeleted file mode 100644index ebbef7a459..0000000000--- a/server/migrations/122_wall_social_indexes.down.sql+++ /dev/null@@ -1,2 +0,0 @@-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.sqldeleted file mode 100644index c4a0c1a461..0000000000--- a/server/migrations/122_wall_social_indexes.up.sql+++ /dev/null@@ -1,6 +0,0 @@-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/api/posts.go b/server/wall/api/posts.goindex dadf1be8a5..67a55b1c4b 100644--- a/server/wall/api/posts.go+++ b/server/wall/api/posts.go@@ -69,32 +69,3 @@ func (h *Handlers) ListPostLikers(c *gin.Context) {func (h *Handlers) DeletePost(c *gin.Context) {respondStatus(c, h.Module.Posts.Delete(c, c.Param("postID")))}--func (h *Handlers) ListComments(c *gin.Context) {- resp, err := h.Module.Posts.ListComments(c, c.Param("postID"))- respondJSON(c, resp, err)-}--func (h *Handlers) CreateComment(c *gin.Context) {- var req models.CreateCommentRequest- if err := c.ShouldBindJSON(&req); err != nil {- respondJSON(c, nil, ente.ErrBadRequest)- return- }- resp, err := h.Module.Posts.CreateComment(c, c.Param("postID"), req)- respondJSON(c, resp, err)-}--func (h *Handlers) ToggleCommentLike(c *gin.Context) {- var req models.LikeCommentRequest- if err := c.ShouldBindJSON(&req); err != nil {- respondJSON(c, nil, ente.ErrBadRequest)- return- }- resp, err := h.Module.Posts.ToggleCommentLike(c, c.Param("postID"), c.Param("commentID"), req)- respondJSON(c, resp, err)-}--func (h *Handlers) DeleteComment(c *gin.Context) {- respondStatus(c, h.Module.Posts.DeleteComment(c, c.Param("postID"), c.Param("commentID")))-}diff --git a/server/wall/api/register.go b/server/wall/api/register.goindex ff1944d448..c614d3740c 100644--- a/server/wall/api/register.go+++ b/server/wall/api/register.go@@ -15,9 +15,6 @@ func Register(privateAPI, publicAPI gin.IRoutes, handlers *Handlers) {privateAPI.PATCH("/wall/posts/:postID/caption", handlers.UpdatePostCaption)privateAPI.POST("/wall/posts/:postID/like", handlers.TogglePostLike)privateAPI.DELETE("/wall/posts/:postID", handlers.DeletePost)- privateAPI.POST("/wall/posts/:postID/comments", handlers.CreateComment)- privateAPI.POST("/wall/posts/:postID/comments/:commentID/like", handlers.ToggleCommentLike)- privateAPI.DELETE("/wall/posts/:postID/comments/:commentID", handlers.DeleteComment)privateAPI.GET("/wall/notifications", handlers.ListNotifications)privateAPI.POST("/wall/friends/add", handlers.AddFriend)privateAPI.POST("/wall/friends/unfriend", handlers.Unfriend)@@ -35,7 +32,6 @@ func Register(privateAPI, publicAPI gin.IRoutes, handlers *Handlers) {publicAPI.GET("/wall/posts", handlers.ListPosts)publicAPI.GET("/wall/posts/:postID", handlers.GetPost)publicAPI.GET("/wall/posts/:postID/likes", handlers.ListPostLikers)- publicAPI.GET("/wall/posts/:postID/comments", handlers.ListComments)publicAPI.GET("/wall/versions", handlers.ListWallKeyVersions)publicAPI.GET("/wall/public/by-slug/:wallSlug", handlers.LookupWallBySlug)publicAPI.POST("/wall/links/session", handlers.WallLinkLogin)diff --git a/server/wall/controller/helpers.go b/server/wall/controller/helpers.goindex df5645f471..4de5fbadf5 100644--- a/server/wall/controller/helpers.go+++ b/server/wall/controller/helpers.go@@ -148,7 +148,6 @@ func toPostResponse(post *wallrepo.WallPostRecord, assets []wallrepo.WallPostAssCreatedAt: formatMicros(post.CreatedAt),Likes: post.Likes,ViewerLiked: post.ViewerLiked,- Comments: post.Comments,}if len(assets) > 0 {resp.Objects = make([]models.PostObjectPayload, 0, len(assets))@@ -158,20 +157,3 @@ func toPostResponse(post *wallrepo.WallPostRecord, assets []wallrepo.WallPostAss}return resp}--func toCommentResponse(comment wallrepo.WallCommentRecord, includeAuthorPrivate bool) models.CommentResponse {- resp := models.CommentResponse{- CommentID: comment.CommentID,- Author: toActorResponse(comment.Author, includeAuthorPrivate),- CommentCipher: comment.CommentCipher,- CreatedAt: formatMicros(comment.CreatedAt),- Likes: comment.Likes,- ViewerLiked: comment.ViewerLiked,- ViewerCanDelete: comment.ViewerCanDelete,- }- if comment.ParentCommentID.Valid {- parentID := comment.ParentCommentID.Int64- resp.ParentCommentID = &parentID- }- return resp-}diff --git a/server/wall/controller/notifications.go b/server/wall/controller/notifications.goindex e25ceaaffd..a0bc123033 100644--- a/server/wall/controller/notifications.go+++ b/server/wall/controller/notifications.go@@ -26,9 +26,6 @@ func (c *NotificationsController) List(ctx *gin.Context, req models.ListNotificaif 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 {@@ -85,22 +82,5 @@ func toNotificationResponse(notification repo.WallNotificationRecord, visible ma}resp.Post = post}- if notification.CommentID.Valid {- comment := &models.NotificationCommentResponse{- CommentID: notification.CommentID.Int64,- Author: toActorResponse(notification.CommentAuthor, visibleActor(visible, notification.CommentAuthor)),- }- if notification.CommentCipher.Valid {- comment.CommentCipher = notification.CommentCipher.String- }- if notification.CommentCreatedAt.Valid {- comment.CreatedAt = formatMicros(notification.CommentCreatedAt.Int64)- }- if notification.ParentCommentID.Valid {- parentID := notification.ParentCommentID.Int64- comment.ParentCommentID = &parentID- }- resp.Comment = comment- }return resp}diff --git a/server/wall/controller/posts.go b/server/wall/controller/posts.goindex 3f217d3b4a..83f8365a64 100644--- a/server/wall/controller/posts.go+++ b/server/wall/controller/posts.go@@ -270,157 +270,3 @@ func (c *PostsController) Delete(ctx *gin.Context, postID string) error {_, err = c.PostsRepo.DeletePost(ctx.Request.Context(), id, userID)return err}--func (c *PostsController) ListComments(ctx *gin.Context, postID string) (*models.ListCommentsResponse, error) {- id, err := strconv.ParseInt(strings.TrimSpace(postID), 10, 64)- if err != nil || id <= 0 {- return nil, ente.NewBadRequestWithMessage("invalid postID")- }- viewer, err := c.auth.resolveViewer(ctx)- if err != nil {- return nil, err- }- viewerID := int64(0)- if viewer != nil {- viewerID = viewer.UserID- }- post, err := c.PostsRepo.GetPost(ctx.Request.Context(), id, viewerID)- if err != nil {- return nil, err- }- wall, err := c.WallsRepo.GetWallByID(ctx.Request.Context(), post.WallID)- if err != nil {- return nil, err- }- if err := c.auth.canViewWall(ctx.Request.Context(), viewer, wall); err != nil {- return nil, err- }- limit, _ := strconv.Atoi(strings.TrimSpace(ctx.Query("limit")))- comments, nextCursor, err := c.PostsRepo.ListComments(ctx.Request.Context(), id, viewerID, ctx.Query("cursor"), limit)- if err != nil {- 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, visibleActor(visible, comment.Author)))- }- return &models.ListCommentsResponse{Comments: resp, NextCursor: nextCursor}, nil-}--func (c *PostsController) CreateComment(ctx *gin.Context, postID string, req models.CreateCommentRequest) (*models.CommentResponse, error) {- userID, err := c.auth.requireUser(ctx)- if err != nil {- return nil, err- }- if strings.TrimSpace(req.CommentCipher) == "" {- return nil, ente.NewBadRequestWithMessage("commentCipher is required")- }- id, err := strconv.ParseInt(strings.TrimSpace(postID), 10, 64)- if err != nil || id <= 0 {- return nil, ente.NewBadRequestWithMessage("invalid postID")- }- post, err := c.PostsRepo.GetPost(ctx.Request.Context(), id, userID)- if err != nil {- return nil, err- }- wall, err := c.WallsRepo.GetWallByID(ctx.Request.Context(), post.WallID)- if err != nil {- return nil, err- }- if err := c.auth.canViewWall(ctx.Request.Context(), &viewerAuth{UserID: userID}, wall); err != nil {- return nil, err- }- if req.ParentCommentID != nil {- if *req.ParentCommentID <= 0 {- return nil, ente.NewBadRequestWithMessage("invalid parentCommentId")- }- parent, err := c.PostsRepo.GetComment(ctx.Request.Context(), *req.ParentCommentID, userID)- if err != nil {- if errors.Is(stacktrace.RootCause(err), sql.ErrNoRows) {- return nil, ente.NewBadRequestWithMessage("invalid parentCommentId")- }- return nil, err- }- if parent.PostID != id {- return nil, ente.NewBadRequestWithMessage("invalid parentCommentId")- }- }- comment, err := c.PostsRepo.CreateComment(ctx.Request.Context(), id, userID, req.CommentCipher, req.ParentCommentID)- if err != nil {- return nil, err- }- resp := toCommentResponse(*comment, true)- return &resp, nil-}--func (c *PostsController) ToggleCommentLike(ctx *gin.Context, postID, commentID string, req models.LikeCommentRequest) (*models.LikeCommentResponse, error) {- userID, err := c.auth.requireUser(ctx)- if err != nil {- return nil, err- }- postIDInt, err := strconv.ParseInt(strings.TrimSpace(postID), 10, 64)- if err != nil || postIDInt <= 0 {- return nil, ente.NewBadRequestWithMessage("invalid postID")- }- commentIDInt, err := strconv.ParseInt(strings.TrimSpace(commentID), 10, 64)- if err != nil || commentIDInt <= 0 {- return nil, ente.NewBadRequestWithMessage("invalid commentID")- }- post, err := c.PostsRepo.GetPost(ctx.Request.Context(), postIDInt, userID)- if err != nil {- return nil, err- }- wall, err := c.WallsRepo.GetWallByID(ctx.Request.Context(), post.WallID)- if err != nil {- return nil, err- }- if err := c.auth.canViewWall(ctx.Request.Context(), &viewerAuth{UserID: userID}, wall); err != nil {- return nil, err- }- comment, err := c.PostsRepo.GetComment(ctx.Request.Context(), commentIDInt, userID)- if err != nil {- return nil, err- }- if comment.PostID != postIDInt {- return nil, ente.NewBadRequestWithMessage("invalid commentID")- }- if err := c.PostsRepo.SetCommentLike(ctx.Request.Context(), postIDInt, commentIDInt, userID, req.Like); err != nil {- return nil, err- }- return &models.LikeCommentResponse{Liked: req.Like}, nil-}--func (c *PostsController) DeleteComment(ctx *gin.Context, postID, commentID string) error {- userID, err := c.auth.requireUser(ctx)- if err != nil {- return err- }- postIDInt, err := strconv.ParseInt(strings.TrimSpace(postID), 10, 64)- if err != nil || postIDInt <= 0 {- return ente.NewBadRequestWithMessage("invalid postID")- }- commentIDInt, err := strconv.ParseInt(strings.TrimSpace(commentID), 10, 64)- if err != nil || commentIDInt <= 0 {- return ente.NewBadRequestWithMessage("invalid commentID")- }- post, err := c.PostsRepo.GetPost(ctx.Request.Context(), postIDInt, userID)- if err != nil {- return err- }- wall, err := c.WallsRepo.GetWallByID(ctx.Request.Context(), post.WallID)- if err != nil {- return err- }- if err := c.auth.canViewWall(ctx.Request.Context(), &viewerAuth{UserID: userID}, wall); err != nil {- return err- }- return c.PostsRepo.DeleteComment(ctx.Request.Context(), postIDInt, commentIDInt, userID)-}diff --git a/server/wall/controller/posts_test.go b/server/wall/controller/posts_test.godeleted file mode 100644index b35195f09d..0000000000--- a/server/wall/controller/posts_test.go+++ /dev/null@@ -1,169 +0,0 @@-package controller--import (- "context"- "database/sql"- "net/http/httptest"- "strconv"- "testing"-- "github.com/ente-io/museum/internal/testutil"- timeutil "github.com/ente-io/museum/pkg/utils/time"- "github.com/ente-io/museum/wall/models"- wallrepo "github.com/ente-io/museum/wall/repo"- "github.com/gin-gonic/gin"- "github.com/stretchr/testify/require"-)--func setupPostsControllerTest(t *testing.T) (*PostsController, *wallrepo.Module, context.Context) {- t.Helper()- testutil.WithServerRoot(t)- db := testutil.RequireTestDB(t)- testutil.ResetTables(t, db)- t.Cleanup(func() {- testutil.ResetTables(t, db)- })- gin.SetMode(gin.TestMode)- repos := wallrepo.NewModule(db, nil)- return NewModule(repos, nil).Posts, repos, context.Background()-}--func insertWallControllerUser(t *testing.T, module *wallrepo.Module, email string, publicKey string) int64 {- t.Helper()- userID := testutil.InsertUser(t, module.Walls.DB, testutil.UserFixture{- Email: email,- CreationTime: timeutil.Microseconds(),- })- _, err := module.Walls.DB.Exec(`- INSERT INTO key_attributes (- user_id, kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce,- public_key, encrypted_secret_key, secret_key_decryption_nonce- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)- `, userID, "salt", []byte{1, 2, 3}, "encrypted-key", "nonce", publicKey, "encrypted-secret-key", "secret-nonce")- require.NoError(t, err)- return userID-}--func newWallControllerContext(userID int64) *gin.Context {- recorder := httptest.NewRecorder()- ctx, _ := gin.CreateTestContext(recorder)- ctx.Request = httptest.NewRequest("POST", "/", nil)- ctx.Request.Header.Set("X-Auth-User-ID", strconv.FormatInt(userID, 10))- return ctx-}--func countWallComments(t *testing.T, db *sql.DB, postID int64) int {- t.Helper()- var count int- err := db.QueryRow(`SELECT COUNT(*) FROM wall_post_comments WHERE post_id = $1`, postID).Scan(&count)- require.NoError(t, err)- return count-}--func countActiveWallComments(t *testing.T, db *sql.DB, postID int64) int {- t.Helper()- var count int- err := db.QueryRow(`SELECT COUNT(*) FROM wall_post_comments WHERE post_id = $1 AND is_deleted = FALSE`, postID).Scan(&count)- require.NoError(t, err)- return count-}--func TestCreateCommentRejectsParentFromAnotherPost(t *testing.T) {- posts, repos, ctx := setupPostsControllerTest(t)- aliceID := insertWallControllerUser(t, repos, "[email protected]", "alice-public")- wall, err := repos.Walls.CreateWall(ctx, aliceID, "alice", "alice-wall-key", "alice-profile")- require.NoError(t, err)- firstPostID, err := repos.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key-1", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- secondPostID, err := repos.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key-2", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- parent, err := repos.Posts.CreateComment(ctx, firstPostID, aliceID, "parent-comment", nil)- require.NoError(t, err)-- resp, err := posts.CreateComment(newWallControllerContext(aliceID), strconv.FormatInt(secondPostID, 10), models.CreateCommentRequest{- CommentCipher: "cross-post-reply",- ParentCommentID: &parent.CommentID,- })-- require.Nil(t, resp)- require.Error(t, err)- require.Equal(t, 0, countWallComments(t, repos.Posts.DB, secondPostID))-}--func TestCreateCommentAcceptsReplyAsParent(t *testing.T) {- posts, repos, ctx := setupPostsControllerTest(t)- aliceID := insertWallControllerUser(t, repos, "[email protected]", "alice-public")- wall, err := repos.Walls.CreateWall(ctx, aliceID, "alice", "alice-wall-key", "alice-profile")- require.NoError(t, err)- postID, err := repos.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- parent, err := repos.Posts.CreateComment(ctx, postID, aliceID, "parent-comment", nil)- require.NoError(t, err)- reply, err := repos.Posts.CreateComment(ctx, postID, aliceID, "reply-comment", &parent.CommentID)- require.NoError(t, err)-- resp, err := posts.CreateComment(newWallControllerContext(aliceID), strconv.FormatInt(postID, 10), models.CreateCommentRequest{- CommentCipher: "nested-reply",- ParentCommentID: &reply.CommentID,- })-- require.NoError(t, err)- require.NotNil(t, resp)- require.Equal(t, reply.CommentID, *resp.ParentCommentID)- require.Equal(t, 3, countWallComments(t, repos.Posts.DB, postID))-}--func TestCreateCommentAcceptsTopLevelParentOnSamePost(t *testing.T) {- posts, repos, ctx := setupPostsControllerTest(t)- aliceID := insertWallControllerUser(t, repos, "[email protected]", "alice-public")- wall, err := repos.Walls.CreateWall(ctx, aliceID, "alice", "alice-wall-key", "alice-profile")- require.NoError(t, err)- postID, err := repos.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- parent, err := repos.Posts.CreateComment(ctx, postID, aliceID, "parent-comment", nil)- require.NoError(t, err)-- resp, err := posts.CreateComment(newWallControllerContext(aliceID), strconv.FormatInt(postID, 10), models.CreateCommentRequest{- CommentCipher: "reply-comment",- ParentCommentID: &parent.CommentID,- })-- require.NoError(t, err)- require.NotNil(t, resp)- require.Equal(t, parent.CommentID, *resp.ParentCommentID)- require.Equal(t, 2, countWallComments(t, repos.Posts.DB, postID))-}--func TestDeleteCommentRejectsRoutePostMismatch(t *testing.T) {- posts, repos, ctx := setupPostsControllerTest(t)- aliceID := insertWallControllerUser(t, repos, "[email protected]", "alice-public")- wall, err := repos.Walls.CreateWall(ctx, aliceID, "alice", "alice-wall-key", "alice-profile")- require.NoError(t, err)- firstPostID, err := repos.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key-1", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- secondPostID, err := repos.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key-2", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- comment, err := repos.Posts.CreateComment(ctx, firstPostID, aliceID, "comment", nil)- require.NoError(t, err)-- err = posts.DeleteComment(newWallControllerContext(aliceID), strconv.FormatInt(secondPostID, 10), strconv.FormatInt(comment.CommentID, 10))-- require.ErrorIs(t, err, sql.ErrNoRows)- require.Equal(t, 1, countActiveWallComments(t, repos.Posts.DB, firstPostID))-}--func TestDeleteCommentDeletesOwnCommentOnRoutePost(t *testing.T) {- posts, repos, ctx := setupPostsControllerTest(t)- aliceID := insertWallControllerUser(t, repos, "[email protected]", "alice-public")- wall, err := repos.Walls.CreateWall(ctx, aliceID, "alice", "alice-wall-key", "alice-profile")- require.NoError(t, err)- postID, err := repos.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- comment, err := repos.Posts.CreateComment(ctx, postID, aliceID, "comment", nil)- require.NoError(t, err)-- err = posts.DeleteComment(newWallControllerContext(aliceID), strconv.FormatInt(postID, 10), strconv.FormatInt(comment.CommentID, 10))-- require.NoError(t, err)- require.Equal(t, 0, countActiveWallComments(t, repos.Posts.DB, postID))-}diff --git a/server/wall/controller/test_helpers_test.go b/server/wall/controller/test_helpers_test.gonew file mode 100644index 0000000000..2897f5640e--- /dev/null+++ b/server/wall/controller/test_helpers_test.go@@ -0,0 +1,51 @@+package controller++import (+ "context"+ "net/http/httptest"+ "strconv"+ "testing"++ "github.com/ente-io/museum/internal/testutil"+ timeutil "github.com/ente-io/museum/pkg/utils/time"+ wallrepo "github.com/ente-io/museum/wall/repo"+ "github.com/gin-gonic/gin"+ "github.com/stretchr/testify/require"+)++func setupPostsControllerTest(t *testing.T) (*PostsController, *wallrepo.Module, context.Context) {+ t.Helper()+ testutil.WithServerRoot(t)+ db := testutil.RequireTestDB(t)+ testutil.ResetTables(t, db)+ t.Cleanup(func() {+ testutil.ResetTables(t, db)+ })+ gin.SetMode(gin.TestMode)+ repos := wallrepo.NewModule(db, nil)+ return NewModule(repos, nil).Posts, repos, context.Background()+}++func insertWallControllerUser(t *testing.T, module *wallrepo.Module, email string, publicKey string) int64 {+ t.Helper()+ userID := testutil.InsertUser(t, module.Walls.DB, testutil.UserFixture{+ Email: email,+ CreationTime: timeutil.Microseconds(),+ })+ _, err := module.Walls.DB.Exec(`+ INSERT INTO key_attributes (+ user_id, kek_salt, kek_hash_bytes, encrypted_key, key_decryption_nonce,+ public_key, encrypted_secret_key, secret_key_decryption_nonce+ ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)+ `, userID, "salt", []byte{1, 2, 3}, "encrypted-key", "nonce", publicKey, "encrypted-secret-key", "secret-nonce")+ require.NoError(t, err)+ return userID+}++func newWallControllerContext(userID int64) *gin.Context {+ recorder := httptest.NewRecorder()+ ctx, _ := gin.CreateTestContext(recorder)+ ctx.Request = httptest.NewRequest("POST", "/", nil)+ ctx.Request.Header.Set("X-Auth-User-ID", strconv.FormatInt(userID, 10))+ return ctx+}diff --git a/server/wall/models/models.go b/server/wall/models/models.goindex 1935d3ac22..ce68fbd97c 100644--- a/server/wall/models/models.go+++ b/server/wall/models/models.go@@ -249,14 +249,6 @@ type PostLikerResponse struct {CreatedAt string `json:"createdAt"`}-type LikeCommentRequest struct {- Like bool `json:"like"`-}--type LikeCommentResponse struct {- Liked bool `json:"liked"`-}-type UpdatePostCaptionRequest struct {CaptionCipher *string `json:"captionCipher,omitempty"`}@@ -285,7 +277,6 @@ type PostResponse struct {CreatedAt string `json:"createdAt"`Likes int64 `json:"likes"`ViewerLiked bool `json:"viewerLiked"`- Comments int64 `json:"comments"`}type PostPage struct {@@ -298,27 +289,6 @@ type FeedPage struct {NextCursor string `json:"nextCursor,omitempty"`}-type CommentResponse struct {- 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 {- Comments []CommentResponse `json:"comments"`- NextCursor string `json:"nextCursor,omitempty"`-}--type CreateCommentRequest struct {- CommentCipher string `json:"commentCipher"`- ParentCommentID *int64 `json:"parentCommentId,omitempty"`-}-type NotificationPostResponse struct {PostID int64 `json:"postId"`WallID string `json:"wallId"`@@ -328,21 +298,12 @@ type NotificationPostResponse struct {Objects []PostObjectPayload `json:"objects,omitempty"`}-type NotificationCommentResponse struct {- 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 WallActorResponse `json:"actor"`- Post *NotificationPostResponse `json:"post,omitempty"`- Comment *NotificationCommentResponse `json:"comment,omitempty"`+ ID string `json:"id"`+ Type string `json:"type"`+ CreatedAt string `json:"createdAt"`+ Actor WallActorResponse `json:"actor"`+ Post *NotificationPostResponse `json:"post,omitempty"`}type NotificationPage struct {diff --git a/server/wall/repo/module.go b/server/wall/repo/module.goindex 7470266896..18c68c6e5a 100644--- a/server/wall/repo/module.go+++ b/server/wall/repo/module.go@@ -75,7 +75,6 @@ type WallPostRecord struct {CreatedAt int64Likes int64ViewerLiked bool- Comments int64}type WallPostAssetRecord struct {@@ -104,18 +103,6 @@ type WallTempObjectRecord struct {CreatedAt int64}-type WallCommentRecord struct {- CommentID int64- PostID int64- Author WallActorRecord- CommentCipher string- ParentCommentID sql.NullInt64- CreatedAt int64- Likes int64- ViewerLiked bool- ViewerCanDelete bool-}-type WallPostLikerRecord struct {Actor WallActorRecordCreatedAt int64@@ -201,11 +188,6 @@ type WallNotificationRecord struct {PostObjectWidth sql.NullInt64PostObjectHeight sql.NullInt64PostObjectMediaType sql.NullString- CommentID sql.NullInt64- ParentCommentID sql.NullInt64- CommentAuthor WallActorRecord- CommentCipher sql.NullString- CommentCreatedAt sql.NullInt64}func NewModule(db *sql.DB, s3Config *s3config.S3Config) *Module {diff --git a/server/wall/repo/module_test.go b/server/wall/repo/module_test.goindex d29cabb786..dab1a660ef 100644--- a/server/wall/repo/module_test.go+++ b/server/wall/repo/module_test.go@@ -159,19 +159,6 @@ func TestWallModuleLifecycle(t *testing.T) {err = module.Posts.SetLike(ctx, postID, bobID, true)require.NoError(t, err)- comment, err := module.Posts.CreateComment(ctx, postID, bobID, "comment-1", nil)- require.NoError(t, err)- _, err = module.Posts.CreateComment(ctx, postID, aliceID, "reply-1", &comment.CommentID)- require.NoError(t, err)-- comments, nextCommentsCursor, err := module.Posts.ListComments(ctx, postID, bobID, "", 20)- require.NoError(t, err)- require.Len(t, comments, 2)- require.Empty(t, nextCommentsCursor)- require.Equal(t, comment.CommentID, comments[1].CommentID)- 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})require.NoError(t, err)require.Len(t, assets[postID], 2)@@ -737,73 +724,18 @@ func TestNotificationsIncludeWallSocialEvents(t *testing.T) {require.NoError(t, err)setPostLikeCreatedAt(t, module, 2000, postID, bobID)- bobComment, err := module.Posts.CreateComment(ctx, postID, bobID, "bob-comment", nil)- require.NoError(t, err)- setCommentCreatedAt(t, module, 3000, bobComment.CommentID)-- aliceComment, err := module.Posts.CreateComment(ctx, postID, aliceID, "alice-comment", nil)- require.NoError(t, err)- bobReply, err := module.Posts.CreateComment(ctx, postID, bobID, "bob-reply", &aliceComment.CommentID)- require.NoError(t, err)- setCommentCreatedAt(t, module, 4000, bobReply.CommentID)-- err = module.Posts.SetCommentLike(ctx, postID, aliceComment.CommentID, bobID, true)- require.NoError(t, err)- setCommentLikeCreatedAt(t, module, 5000, aliceComment.CommentID, bobID)-err = module.Friends.AddFriend(ctx, bobID, bobWall.WallID, aliceWall.WallID, "alice-share-key", aliceWall.CurrentVersion, "bob-share-key", bobWall.CurrentVersion)require.NoError(t, err)- setFriendEventCreatedAt(t, module, 6000, bobID, aliceID)+ setFriendEventCreatedAt(t, module, 3000, bobID, aliceID)page, nextCursor, err := module.Notifications.List(ctx, aliceID, "", 3)require.NoError(t, err)- 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].CommentAuthor.WallID)- require.Equal(t, "repliedToComment", page[2].Type)- require.Equal(t, bobWall.WallID, page[2].CommentAuthor.WallID)- require.NotEmpty(t, nextCursor)-- page, nextCursor, err = module.Notifications.List(ctx, aliceID, nextCursor, 3)- require.NoError(t, err)require.Len(t, page, 2)- require.Equal(t, "commentedOnPost", page[0].Type)+ require.Equal(t, "addedYouAsFriend", page[0].Type)require.Equal(t, "likedPost", page[1].Type)require.Empty(t, nextCursor)}-func TestListCommentsPaginates(t *testing.T) {- ctx := context.Background()- module := newWallTestModule(t)-- aliceID := insertWallUser(t, module, "[email protected]", "alice-public")- wall, err := module.Walls.CreateWall(ctx, aliceID, "alice", "alice-wall-key", "alice-profile")- require.NoError(t, err)- postID, err := module.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key", nil, wall.CurrentVersion, nil)- require.NoError(t, err)-- first, err := module.Posts.CreateComment(ctx, postID, aliceID, "comment-1", nil)- require.NoError(t, err)- second, err := module.Posts.CreateComment(ctx, postID, aliceID, "comment-2", nil)- require.NoError(t, err)- third, err := module.Posts.CreateComment(ctx, postID, aliceID, "comment-3", nil)- require.NoError(t, err)-- page, nextCursor, err := module.Posts.ListComments(ctx, postID, aliceID, "", 2)- require.NoError(t, err)- require.Len(t, page, 2)- require.Equal(t, third.CommentID, page[0].CommentID)- require.Equal(t, second.CommentID, page[1].CommentID)- require.Equal(t, strconv.FormatInt(second.CommentID, 10), nextCursor)-- page, nextCursor, err = module.Posts.ListComments(ctx, postID, aliceID, nextCursor, 2)- require.NoError(t, err)- require.Len(t, page, 1)- require.Equal(t, first.CommentID, page[0].CommentID)- require.Empty(t, nextCursor)-}-func TestListPostLikersPaginates(t *testing.T) {ctx := context.Background()module := newWallTestModule(t)@@ -839,36 +771,6 @@ func TestListPostLikersPaginates(t *testing.T) {require.Empty(t, nextCursor)}-func TestDeleteCommentRequiresPostAndAuthorMatch(t *testing.T) {- ctx := context.Background()- module := newWallTestModule(t)-- aliceID := insertWallUser(t, module, "[email protected]", "alice-public")- bobID := insertWallUser(t, module, "[email protected]", "bob-public")- wall, err := module.Walls.CreateWall(ctx, aliceID, "alice", "alice-wall-key", "alice-profile")- require.NoError(t, err)- _, err = module.Walls.CreateWall(ctx, bobID, "bob", "bob-wall-key", "bob-profile")- require.NoError(t, err)- firstPostID, err := module.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key-1", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- secondPostID, err := module.Posts.CreatePost(ctx, aliceID, wall.WallID, "post-key-2", nil, wall.CurrentVersion, nil)- require.NoError(t, err)- comment, err := module.Posts.CreateComment(ctx, firstPostID, bobID, "comment", nil)- require.NoError(t, err)-- err = module.Posts.DeleteComment(ctx, secondPostID, comment.CommentID, bobID)- require.ErrorIs(t, err, sql.ErrNoRows)- require.Equal(t, 1, countActivePostComments(t, module, firstPostID))-- err = module.Posts.DeleteComment(ctx, firstPostID, comment.CommentID, aliceID)- require.ErrorIs(t, err, sql.ErrNoRows)- require.Equal(t, 1, countActivePostComments(t, module, firstPostID))-- err = module.Posts.DeleteComment(ctx, firstPostID, comment.CommentID, bobID)- require.NoError(t, err)- require.Equal(t, 0, countActivePostComments(t, module, firstPostID))-}-func ptr(value string) *string {return &value}@@ -881,14 +783,6 @@ func sqlNullString(value string) sql.NullString {return sql.NullString{String: value, Valid: value != ""}}-func countActivePostComments(t *testing.T, module *Module, postID int64) int {- t.Helper()- var count int- err := module.Posts.DB.QueryRow(`SELECT COUNT(*) FROM wall_post_comments WHERE post_id = $1 AND is_deleted = FALSE`, postID).Scan(&count)- require.NoError(t, err)- return count-}-func requireQueuedTempObject(t *testing.T, module *Module, objectKey, purpose, bucketID string) {t.Helper()var gotPurpose, gotBucketID string@@ -918,18 +812,6 @@ func setPostLikeCreatedAt(t *testing.T, module *Module, createdAt, postID, userIrequire.NoError(t, err)}-func setCommentCreatedAt(t *testing.T, module *Module, createdAt, commentID int64) {- t.Helper()- _, err := module.Posts.DB.Exec(`UPDATE wall_post_comments SET created_at = $1 WHERE comment_id = $2`, createdAt, commentID)- require.NoError(t, err)-}--func setCommentLikeCreatedAt(t *testing.T, module *Module, createdAt, commentID, userID int64) {- t.Helper()- _, err := module.Posts.DB.Exec(`UPDATE wall_comment_likes SET created_at = $1 WHERE comment_id = $2 AND user_id = $3`, createdAt, commentID, userID)- require.NoError(t, err)-}-func setFriendEventCreatedAt(t *testing.T, module *Module, createdAt, actorID, targetID int64) {t.Helper()_, err := module.Friends.DB.Exec(`UPDATE wall_friend_events SET created_at = $1 WHERE actor_id = $2 AND target_id = $3`, createdAt, actorID, targetID)diff --git a/server/wall/repo/notifications.go b/server/wall/repo/notifications.goindex 870a49aaab..27b2e906e2 100644--- a/server/wall/repo/notifications.go+++ b/server/wall/repo/notifications.go@@ -34,12 +34,7 @@ const wallNotificationRows = `asset.blur_hash_cipher AS post_object_blur_hash_cipher,asset.width AS post_object_width,asset.height AS post_object_height,- asset.media_type AS post_object_media_type,- NULL::bigint AS comment_id,- NULL::bigint AS parent_comment_id,- 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+ asset.media_type AS post_object_media_typeFROM wall_post_likes plJOIN wall_posts p ON p.post_id = pl.post_idJOIN walls actor_wall ON actor_wall.owner_id = pl.user_id@@ -60,180 +55,6 @@ const wallNotificationRows = `UNION ALL- SELECT- 'comment:' || c.comment_id::text AS notification_id,- 'commentedOnPost' AS notification_type,- c.created_at,- 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.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,- asset.variant AS post_object_variant,- asset.blur_hash_cipher AS post_object_blur_hash_cipher,- asset.width AS post_object_width,- asset.height AS post_object_height,- asset.media_type AS post_object_media_type,- c.comment_id,- NULL::bigint AS parent_comment_id,- 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- WHERE post_id = p.post_id- ORDER BY position ASC, asset_id ASC- LIMIT 1- ) asset ON TRUE- WHERE p.owner_id = $1- AND c.author_id <> $1- AND c.parent_comment_id IS NULL- AND c.is_deleted = FALSE- AND p.is_deleted = FALSE-- UNION ALL-- SELECT- 'reply:' || c.comment_id::text AS notification_id,- 'repliedToComment' AS notification_type,- c.created_at,- 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.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,- asset.variant AS post_object_variant,- asset.blur_hash_cipher AS post_object_blur_hash_cipher,- asset.width AS post_object_width,- asset.height AS post_object_height,- asset.media_type AS post_object_media_type,- c.comment_id,- c.parent_comment_id,- 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- WHERE post_id = p.post_id- ORDER BY position ASC, asset_id ASC- LIMIT 1- ) asset ON TRUE- WHERE parent.author_id = $1- AND c.author_id <> $1- AND c.is_deleted = FALSE- AND parent.is_deleted = FALSE- AND p.is_deleted = FALSE-- UNION ALL-- SELECT- 'comment_like:' || cl.comment_id::text || ':' || cl.user_id::text AS notification_id,- 'likedComment' AS notification_type,- cl.created_at,- 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.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,- asset.variant AS post_object_variant,- asset.blur_hash_cipher AS post_object_blur_hash_cipher,- asset.width AS post_object_width,- asset.height AS post_object_height,- asset.media_type AS post_object_media_type,- c.comment_id,- c.parent_comment_id,- 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- WHERE post_id = p.post_id- ORDER BY position ASC, asset_id ASC- LIMIT 1- ) asset ON TRUE- WHERE c.author_id = $1- AND cl.user_id <> $1- AND c.is_deleted = FALSE- AND p.is_deleted = FALSE-- UNION ALL-SELECT'friend_add:' || fe.event_id::text AS notification_id,'addedYouAsFriend' AS notification_type,@@ -255,12 +76,7 @@ const wallNotificationRows = `NULL::text AS post_object_blur_hash_cipher,NULL::integer AS post_object_width,NULL::integer AS post_object_height,- NULL::text AS post_object_media_type,- NULL::bigint AS comment_id,- NULL::bigint AS parent_comment_id,- 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+ NULL::text AS post_object_media_typeFROM wall_friend_events feJOIN walls actor_wall ON actor_wall.wall_id = fe.actor_wall_idJOIN key_attributes actor_ka ON actor_ka.user_id = actor_wall.owner_id@@ -317,9 +133,7 @@ func scanNotificationRecord(scanner interface{ Scan(dest ...any) error }) (*Walldest = 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)+ dest = append(dest, &rec.PostObjectKey, &rec.PostObjectSize, &rec.PostObjectPosition, &rec.PostObjectVariant, &rec.PostObjectBlurHashCipher, &rec.PostObjectWidth, &rec.PostObjectHeight, &rec.PostObjectMediaType)if err := scanner.Scan(dest...); err != nil {return nil, stacktrace.Propagate(err, "")}diff --git a/server/wall/repo/posts.go b/server/wall/repo/posts.goindex f4f2dbcc14..d0215eecb6 100644--- a/server/wall/repo/posts.go+++ b/server/wall/repo/posts.go@@ -67,8 +67,7 @@ func (r *PostsRepository) GetPost(ctx context.Context, postID int64, viewerID inp.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+ EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $2) AS viewer_likedFROM wall_posts pJOIN walls w ON w.wall_id = p.wall_idJOIN walls owner_wall ON owner_wall.owner_id = p.owner_id@@ -93,8 +92,7 @@ func (r *PostsRepository) ListPostsByWall(ctx context.Context, wallID string, vip.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+ EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $2) AS viewer_likedFROM wall_posts pJOIN walls w ON w.wall_id = p.wall_idJOIN walls owner_wall ON owner_wall.owner_id = p.owner_id@@ -146,8 +144,7 @@ func (r *PostsRepository) ListFeed(ctx context.Context, viewerID int64, cursor sp.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+ EXISTS (SELECT 1 FROM wall_post_likes pl WHERE pl.post_id = p.post_id AND pl.user_id = $1) AS viewer_likedFROM wall_posts pJOIN walls w ON w.wall_id = p.wall_idJOIN walls owner_wall ON owner_wall.owner_id = p.owner_id@@ -350,132 +347,11 @@ func (r *PostsRepository) UpdateCaption(ctx context.Context, postID, ownerID intreturn nil}-func (r *PostsRepository) CreateComment(ctx context.Context, postID, authorID int64, commentCipher string, parentCommentID *int64) (*WallCommentRecord, error) {- var commentID int64- if err := r.DB.QueryRowContext(ctx, `- INSERT INTO wall_post_comments (post_id, author_id, comment_cipher, parent_comment_id)- VALUES ($1, $2, $3, $4)- RETURNING comment_id- `, postID, authorID, commentCipher, parentCommentID).Scan(&commentID); err != nil {- return nil, stacktrace.Propagate(err, "")- }- return r.GetComment(ctx, commentID, authorID)-}--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,- 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))-}--func (r *PostsRepository) ListComments(ctx context.Context, postID, viewerID int64, cursor string, limit int) ([]WallCommentRecord, string, error) {- limit = optionalInt(limit, 20)- if limit > 100 {- limit = 100- }- args := []any{postID, viewerID}- query := `- 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 {- args = append(args, cursorID)- query += ` AND c.comment_id < $3`- }- }- args = append(args, limit+1)- query += ` ORDER BY c.comment_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()- var out []WallCommentRecord- for rows.Next() {- rec, err := scanCommentRecord(rows)- if err != nil {- return nil, "", err- }- out = append(out, *rec)- }- if err := rows.Err(); err != nil {- return nil, "", stacktrace.Propagate(err, "")- }- nextCursor := ""- if len(out) > limit {- nextCursor = strconv.FormatInt(out[limit-1].CommentID, 10)- out = out[:limit]- }- return out, nextCursor, nil-}--func (r *PostsRepository) SetCommentLike(ctx context.Context, postID, commentID, userID int64, like bool) error {- if like {- _, err := r.DB.ExecContext(ctx, `- INSERT INTO wall_comment_likes (comment_id, user_id)- SELECT c.comment_id, $3- FROM wall_post_comments c- WHERE c.post_id = $1 AND c.comment_id = $2 AND c.is_deleted = FALSE- ON CONFLICT DO NOTHING- `, postID, commentID, userID)- return stacktrace.Propagate(err, "")- }- _, err := r.DB.ExecContext(ctx, `- DELETE FROM wall_comment_likes cl- USING wall_post_comments c- WHERE cl.comment_id = c.comment_id- AND c.post_id = $1- AND c.comment_id = $2- AND cl.user_id = $3- `, postID, commentID, userID)- return stacktrace.Propagate(err, "")-}--func (r *PostsRepository) DeleteComment(ctx context.Context, postID, commentID, viewerID int64) error {- res, err := r.DB.ExecContext(ctx, `UPDATE wall_post_comments SET is_deleted = TRUE WHERE post_id = $1 AND comment_id = $2 AND author_id = $3 AND is_deleted = FALSE`, postID, commentID, viewerID)- if err != nil {- return stacktrace.Propagate(err, "")- }- affected, err := res.RowsAffected()- if err != nil {- return stacktrace.Propagate(err, "")- }- if affected == 0 {- return sql.ErrNoRows- }- return nil-}-func scanPostRecord(scanner interface{ Scan(dest ...any) error }) (*WallPostRecord, error) {var rec WallPostRecorddest := []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)+ dest = append(dest, &rec.EncryptedPostKey, &rec.CaptionCipher, &rec.KeyVersion, &rec.CreatedAt, &rec.Likes, &rec.ViewerLiked)if err := scanner.Scan(dest...); err != nil {return nil, stacktrace.Propagate(err, "")}@@ -522,17 +398,6 @@ func formatPostLikerCursor(liker WallPostLikerRecord) string {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- 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-}-func inClause(format string, ids []int64, offset int) (string, []any) {parts := make([]string, len(ids))args := make([]any, 0, len(ids))diff --git a/web/packages/wasm/src/wall.rs b/web/packages/wasm/src/wall.rsindex ebc6f8f7be..7fc6d5f5b1 100644--- a/web/packages/wasm/src/wall.rs+++ b/web/packages/wasm/src/wall.rs@@ -2,11 +2,10 @@use ente_core::http::Error as HttpError;use ente_wall::{- AccountWallCtx, AuthKeyAttributes, CommentResponse, CreatedWall, CreatedWallLink,- DecryptedPost, DecryptedWallProfile, OpenAccountWallCtxInput, OpenWallLinkCtxInput,- PostResponse, PrivateKeySource, ProfileAvatarResponse, WallActorResponse,- WallError as CoreWallError, WallLinkCtx, WallNotification, WallNotificationComment,- WallNotificationPost,+ AccountWallCtx, AuthKeyAttributes, CreatedWall, CreatedWallLink, DecryptedPost,+ DecryptedWallProfile, OpenAccountWallCtxInput, OpenWallLinkCtxInput, PostResponse,+ PrivateKeySource, ProfileAvatarResponse, WallActorResponse, WallError as CoreWallError,+ WallLinkCtx, WallNotification, WallNotificationPost,crypto::{decode_b64, encode_b64},};use serde::{Deserialize, Serialize};@@ -162,7 +161,6 @@ struct PostJs {created_at: String,likes: i64,viewer_liked: bool,- comments: i64,}#[derive(Serialize)]@@ -172,36 +170,6 @@ struct PostPageJs {next_cursor: String,}-#[derive(Serialize)]-#[serde(rename_all = "camelCase")]-struct CommentJs {- comment_id: i64,- author: ActorJs,- comment: String,- created_at: String,- likes: i64,- viewer_liked: bool,- viewer_can_delete: bool,- parent_comment_id: Option<i64>,-}--#[derive(Serialize)]-#[serde(rename_all = "camelCase")]-struct CommentPageJs {- comments: Vec<CommentJs>,- next_cursor: String,-}--#[derive(Serialize)]-#[serde(rename_all = "camelCase")]-struct NotificationCommentJs {- comment_id: i64,- author: ActorJs,- comment: Option<String>,- created_at: String,- parent_comment_id: Option<i64>,-}-#[derive(Serialize)]#[serde(rename_all = "camelCase")]struct NotificationPostJs {@@ -222,7 +190,6 @@ struct NotificationJs {created_at: String,actor: ActorJs,post: Option<NotificationPostJs>,- comment: Option<NotificationCommentJs>,}#[derive(Serialize)]@@ -355,7 +322,6 @@ async fn account_post_to_js(created_at: post.created_at,likes: post.likes,viewer_liked: post.viewer_liked,- comments: post.comments,})}@@ -377,43 +343,6 @@ async fn link_post_to_js(created_at: post.created_at,likes: post.likes,viewer_liked: post.viewer_liked,- comments: post.comments,- })-}--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,- 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,})}@@ -447,46 +376,6 @@ async fn link_post_page_to_js(})}-async fn account_comment_page_to_js(- ctx: &AccountWallCtx,- post_id: i64,- limit: Option<i32>,- cursor: Option<i64>,-) -> Result<CommentPageJs, WasmWallError> {- let post = ctx.get_post(post_id).await?;- let decrypted_post = ctx.decrypt_post_for_wall(&post.wall_id, &post).await?;- let page = ctx.list_comments(post_id, limit, cursor).await?;- 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(account_comment_to_js(ctx, comment, decrypted).await?);- }- Ok(CommentPageJs {- comments,- next_cursor: page.next_cursor,- })-}--async fn link_comment_page_to_js(- ctx: &WallLinkCtx,- post_id: i64,- limit: Option<i32>,- cursor: Option<i64>,-) -> Result<CommentPageJs, WasmWallError> {- let post = ctx.get_post(post_id).await?;- let decrypted_post = ctx.decrypt_post(&post).await?;- let page = ctx.list_comments(post_id, limit, cursor).await?;- 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(link_comment_to_js(ctx, comment, decrypted).await?);- }- Ok(CommentPageJs {- comments,- next_cursor: page.next_cursor,- })-}-async fn notification_to_js(ctx: &AccountWallCtx,notification: WallNotification,@@ -495,10 +384,6 @@ async fn notification_to_js(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, post.as_ref(), comment).await?),- None => None,- };let actor = account_actor_to_js(ctx, notification.actor).await?;Ok(NotificationJs {id: notification.id,@@ -506,7 +391,6 @@ async fn notification_to_js(created_at: notification.created_at,actor,post,- comment,})}@@ -525,44 +409,6 @@ async fn notification_post_to_js(})}-async fn notification_comment_to_js(- ctx: &AccountWallCtx,- post: Option<&NotificationPostJs>,- comment: WallNotificationComment,-) -> Result<NotificationCommentJs, WasmWallError> {- let plaintext = if comment.comment_cipher.trim().is_empty() {- None- } else if let Some(post) = post {- let post = ctx.get_post(post.post_id).await?;- let decrypted_post = ctx.decrypt_post_for_wall(&post.wall_id, &post).await?;- let comment_response = CommentResponse {- comment_id: comment.comment_id,- author: comment.author.clone(),- comment_cipher: comment.comment_cipher.clone(),- created_at: comment.created_at.clone(),- likes: 0,- viewer_liked: false,- viewer_can_delete: false,- parent_comment_id: comment.parent_comment_id,- };- Some(utf8_field(- ctx.decrypt_comment(&decrypted_post.post_key, &comment_response)?- .plaintext,- "comment",- )?)- } else {- None- };- let author = account_actor_to_js(ctx, comment.author).await?;- Ok(NotificationCommentJs {- comment_id: comment.comment_id,- author,- comment: plaintext,- created_at: comment.created_at,- parent_comment_id: comment.parent_comment_id,- })-}-/// Open an authenticated wall context for web.#[wasm_bindgen]pub async fn wall_open_account_ctx(input: JsValue) -> Result<WallAccountCtxHandle, WasmWallError> {@@ -780,7 +626,6 @@ impl WallAccountCtxHandle {created_at: item.created_at,likes: item.likes,viewer_liked: item.viewer_liked,- comments: item.comments,}).collect(),next_cursor: page.next_cursor,@@ -898,64 +743,6 @@ impl WallAccountCtxHandle {.map_err(Into::into)}- /// List comments with plaintext decrypted.- pub async fn list_comments(- &self,- post_id: i64,- limit: Option<i32>,- cursor: Option<i64>,- ) -> Result<JsValue, WasmWallError> {- swb::to_value(&account_comment_page_to_js(&self.inner, post_id, limit, cursor).await?)- .map_err(Into::into)- }-- /// Create a comment or reply.- pub async fn create_comment(- &self,- post_id: i64,- comment: String,- parent_comment_id: Option<i64>,- ) -> Result<JsValue, WasmWallError> {- let post = self.inner.get_post(post_id).await?;- let decrypted_post = self- .inner- .decrypt_post_for_wall(&post.wall_id, &post)- .await?;- let response = self- .inner- .create_comment(- post_id,- &decrypted_post.post_key,- comment.as_bytes(),- parent_comment_id,- )- .await?;- let decrypted = self- .inner- .decrypt_comment(&decrypted_post.post_key, &response)?;- swb::to_value(&account_comment_to_js(&self.inner, response, decrypted).await?)- .map_err(Into::into)- }-- /// Like or unlike a comment.- pub async fn like_comment(- &self,- post_id: i64,- comment_id: i64,- like: bool,- ) -> Result<JsValue, WasmWallError> {- swb::to_value(&self.inner.like_comment(post_id, comment_id, like).await?)- .map_err(Into::into)- }-- /// Delete a comment.- pub async fn delete_comment(&self, post_id: i64, comment_id: i64) -> Result<(), WasmWallError> {- self.inner- .delete_comment(post_id, comment_id)- .await- .map_err(Into::into)- }-/// Update a post caption.pub async fn update_post_caption(&self,@@ -1017,7 +804,7 @@ impl WallAccountCtxHandle {.map_err(Into::into)}- /// List notifications with comment plaintext decrypted where present.+ /// List notifications.pub async fn list_notifications(&self,cursor: Option<String>,@@ -1084,17 +871,6 @@ impl WallLinkCtxHandle {.map_err(Into::into)}- /// List comments with plaintext decrypted.- pub async fn list_comments(- &self,- post_id: i64,- limit: Option<i32>,- cursor: Option<i64>,- ) -> Result<JsValue, WasmWallError> {- swb::to_value(&link_comment_page_to_js(&self.inner, post_id, limit, cursor).await?)- .map_err(Into::into)- }-/// List people who liked a post.pub async fn list_post_likers(&self,