]> Untitled Git - lemmy.git/commitdiff
Three instance inbox bug (#1866)
authorDessalines <dessalines@users.noreply.github.com>
Thu, 28 Oct 2021 20:46:24 +0000 (16:46 -0400)
committerGitHub <noreply@github.com>
Thu, 28 Oct 2021 20:46:24 +0000 (20:46 +0000)
* 3 instance shared inbox bug test

* Fixing shared inbox bug. Fixes #1865

* A few fixes.

api_tests/src/comment.spec.ts
crates/apub/src/http/community.rs

index 2915d26120f18666cf5080f0a38be833c4f4211e..55d0c5d46421681f5423384fd365931b83ec673e 100644 (file)
@@ -325,6 +325,51 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
   // expect(mentionsRes.mentions[0].score).toBe(1);
 });
 
+test('Check that activity from another instance is sent to third instance', async () => {
+  // Alpha and gamma users follow beta community
+  let alphaFollow = await followBeta(alpha);
+  expect(alphaFollow.community_view.community.local).toBe(false);
+  expect(alphaFollow.community_view.community.name).toBe('main');
+
+  let gammaFollow = await followBeta(gamma);
+  expect(gammaFollow.community_view.community.local).toBe(false);
+  expect(gammaFollow.community_view.community.name).toBe('main');
+
+  // Create a post on beta
+  let betaPost = await createPost(beta, 2);
+  expect(betaPost.post_view.community.local).toBe(true);
+
+  // Make sure gamma and alpha see it
+  let gammaPost = (await resolvePost(gamma, betaPost.post_view.post)).post;
+  expect(gammaPost.post).toBeDefined();
+  let alphaPost = (await resolvePost(alpha, betaPost.post_view.post)).post;
+  expect(alphaPost.post).toBeDefined();
+
+  // The bug: gamma comments, and alpha should see it.
+  let commentContent = 'Comment from gamma';
+  let commentRes = await createComment(
+    gamma,
+    gammaPost.post.id,
+    undefined,
+    commentContent
+  );
+  expect(commentRes.comment_view.comment.content).toBe(commentContent);
+  expect(commentRes.comment_view.community.local).toBe(false);
+  expect(commentRes.comment_view.creator.local).toBe(true);
+  expect(commentRes.comment_view.counts.score).toBe(1);
+
+  // Make sure alpha sees it
+  let alphaPost2 = await getPost(alpha, alphaPost.post.id);
+  expect(alphaPost2.comments[0].comment.content).toBe(commentContent);
+  expect(alphaPost2.comments[0].community.local).toBe(false);
+  expect(alphaPost2.comments[0].creator.local).toBe(false);
+  expect(alphaPost2.comments[0].counts.score).toBe(1);
+  assertCommentFederation(alphaPost2.comments[0], commentRes.comment_view);
+
+  await unfollowRemotes(alpha);
+  await unfollowRemotes(gamma);
+});
+
 test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedded comments, A subs to B, B updates the lowest level comment, A fetches both the post and all the inreplyto comments for that post.', async () => {
   // Unfollow all remote communities
   let site = await unfollowRemotes(alpha);
@@ -403,4 +448,4 @@ test('Report a comment', async () => {
   expect(betaReport.resolved).toBe(false);
   expect(betaReport.original_comment_text).toBe(alphaReport.original_comment_text);
   expect(betaReport.reason).toBe(alphaReport.reason);
-});
\ No newline at end of file
+});
index 1e10e3844d567f49daaaeafe79a3a809a3d5596d..dcaf551f16837a65667f2b19761faaefffaa69e7 100644 (file)
@@ -83,12 +83,6 @@ pub async fn community_inbox(
 
   receive_group_inbox(activity.clone(), request, &context).await?;
 
-  if let GroupInboxActivities::AnnouncableActivities(announcable) = activity {
-    let community = extract_community(&announcable.cc(), &context, &mut 0).await?;
-    if community.local {
-      AnnounceActivity::send(announcable, &community, vec![], &context).await?;
-    }
-  }
   Ok(HttpResponse::Ok().finish())
 }
 
@@ -97,7 +91,14 @@ pub(in crate::http) async fn receive_group_inbox(
   request: HttpRequest,
   context: &LemmyContext,
 ) -> Result<HttpResponse, LemmyError> {
-  receive_activity(request, activity.clone(), context).await
+  let res = receive_activity(request, activity.clone(), context).await;
+  if let GroupInboxActivities::AnnouncableActivities(announcable) = activity.clone() {
+    let community = extract_community(&announcable.cc(), context, &mut 0).await?;
+    if community.local {
+      AnnounceActivity::send(announcable, &community, vec![], context).await?;
+    }
+  }
+  res
 }
 
 /// Returns an empty followers collection, only populating the size (for privacy).