Properly federate distinguish comment (fixes #5575) (#5586)

This commit is contained in:
Nutomic 2025-04-02 18:58:42 +00:00 committed by GitHub
parent 7711562bd5
commit b853ac2800
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions

View file

@ -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":

View file

@ -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,