From b853ac280006d4aadb822a0d135d9ce50ffc2d4b Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 2 Apr 2025 18:58:42 +0000 Subject: [PATCH] Properly federate distinguish comment (fixes #5575) (#5586) --- api_tests/src/comment.spec.ts | 24 +++++++++++++++++++++++- crates/api/src/comment/distinguish.rs | 8 ++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/api_tests/src/comment.spec.ts b/api_tests/src/comment.spec.ts index 5eeeb59b6..853427d26 100644 --- a/api_tests/src/comment.spec.ts +++ b/api_tests/src/comment.spec.ts @@ -43,6 +43,7 @@ import { CommentReportView, CommentView, CommunityView, + DistinguishComment, PersonCommentMentionView, ReportCombinedView, SaveUserSettings, @@ -872,7 +873,7 @@ test("Dont send a comment reply to a blocked community", async () => { /// Fetching a deeply nested comment can lead to stack overflow as all parent comments are also /// fetched recursively. Ensure that it works properly. -test.skip("Fetch a deeply nested comment", async () => { +test("Fetch a deeply nested comment", async () => { let lastComment; for (let i = 0; i < 50; i++) { let commentRes = await createComment( @@ -893,6 +894,27 @@ test.skip("Fetch a deeply nested comment", async () => { expect(betaComment?.comment?.post).toBeDefined(); }); +test("Distinguish comment", async () => { + const community = (await resolveBetaCommunity(beta)).community; + let post = await createPost(beta, community!.community.id); + let commentRes = await createComment(beta, post.post_view.post.id); + const form: DistinguishComment = { + comment_id: commentRes.comment_view.comment.id, + distinguished: true, + }; + await beta.distinguishComment(form); + + let alphaPost = (await resolvePost(alpha, post.post_view.post)).post; + + // Find the comment on alpha (home of community) + let alphaComments = await waitUntil( + () => getComments(alpha, alphaPost?.post.id), + c => c.comments[0].comment.distinguished, + ); + + assertCommentFederation(alphaComments.comments[0], commentRes.comment_view); +}); + function checkCommentReportReason(rcv: ReportCombinedView, reason: string) { switch (rcv.type_) { case "Comment": diff --git a/crates/api/src/comment/distinguish.rs b/crates/api/src/comment/distinguish.rs index b8526eca6..a1c32746d 100644 --- a/crates/api/src/comment/distinguish.rs +++ b/crates/api/src/comment/distinguish.rs @@ -1,7 +1,9 @@ -use actix_web::web::{Data, Json}; +use activitypub_federation::config::Data; +use actix_web::web::Json; use lemmy_api_common::{ comment::{CommentResponse, DistinguishComment}, context::LemmyContext, + send_activity::{ActivityChannel, SendActivityData}, utils::{check_community_mod_action, check_community_user_action}, }; use lemmy_db_schema::{ @@ -49,10 +51,12 @@ pub async fn distinguish_comment( distinguished: Some(data.distinguished), ..Default::default() }; - Comment::update(&mut context.pool(), data.comment_id, &form) + let comment = Comment::update(&mut context.pool(), data.comment_id, &form) .await .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?; + ActivityChannel::submit_activity(SendActivityData::UpdateComment(comment), &context)?; + let comment_view = CommentView::read( &mut context.pool(), data.comment_id,