]> Untitled Git - lemmy.git/commitdiff
Activities in community should also be sent to actors in cc
authorFelix Ableitner <me@nutomic.com>
Mon, 15 Nov 2021 21:37:19 +0000 (22:37 +0100)
committerFelix Ableitner <me@nutomic.com>
Tue, 16 Nov 2021 17:07:45 +0000 (18:07 +0100)
15 files changed:
crates/apub/src/activities/comment/create_or_update.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/block_user.rs
crates/apub/src/activities/community/mod.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/undo_block_user.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/post/create_or_update.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/http/community.rs
crates/apub/src/objects/community.rs

index 7ac1e4e599811f53beecb16b0df9c993fe8bd7e5..eab2a5771a4b7a04c0c231d7380faa52f37fcc49 100644 (file)
@@ -2,7 +2,7 @@ use crate::{
   activities::{
     check_community_deleted_or_removed,
     comment::{collect_non_local_mentions, get_notif_recipients},
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
@@ -62,7 +62,7 @@ impl CreateOrUpdateComment {
     };
 
     let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
-    send_to_community(activity, &id, actor, &community, maa.inboxes, context).await
+    send_activity_in_community(activity, &id, actor, &community, maa.inboxes, context).await
   }
 }
 
index f8026cce63f82074029f893119226608178b1f0d..7437750db2bb3de04d7696b6abeec146c79dd031 100644 (file)
@@ -1,6 +1,10 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
+    community::{
+      announce::GetCommunity,
+      get_community_from_moderators_url,
+      send_activity_in_community,
+    },
     generate_activity_id,
     verify_activity,
     verify_add_remove_moderator_target,
@@ -51,7 +55,7 @@ impl AddMod {
 
     let activity = AnnouncableActivities::AddMod(add);
     let inboxes = vec![added_mod.shared_inbox_or_inbox_url()];
-    send_to_community(activity, &id, actor, community, inboxes, context).await
+    send_activity_in_community(activity, &id, actor, community, inboxes, context).await
   }
 }
 
index fc6c5686cc0abb021e6f270e2c5cf77f89a0873c..4eebcce38d7bf6331d5882f06c28581371f22690 100644 (file)
@@ -14,7 +14,6 @@ use lemmy_apub_lib::{
 };
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use url::Url;
 
 #[async_trait::async_trait(?Send)]
 pub(crate) trait GetCommunity {
@@ -48,13 +47,10 @@ impl AnnounceActivity {
   pub async fn send(
     object: AnnouncableActivities,
     community: &ApubCommunity,
-    additional_inboxes: Vec<Url>,
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
     let announce = AnnounceActivity::new(object.clone(), community, context)?;
-    let inboxes = community
-      .get_follower_inboxes(additional_inboxes.clone(), context)
-      .await?;
+    let inboxes = community.get_follower_inboxes(context).await?;
     send_lemmy_activity(
       context,
       &announce,
@@ -65,9 +61,9 @@ impl AnnounceActivity {
     )
     .await?;
 
-    // Pleroma (and likely Mastodon) can't handle activities like Announce/Create/Page, so for
-    // compatibility, we also send Announce/Page and Announce/Note (for new and updated
-    // posts/comments).
+    // Pleroma (and likely Mastodon) can't handle activities like Announce/Create/Page. So for
+    // compatibility to allow them to follow Lemmy communities, we also send Announce/Page and
+    // Announce/Note (for new and updated posts/comments).
     use AnnouncableActivities::*;
     let object = match object {
       CreateOrUpdatePost(c) => Page(c.object),
index 4be0660f8bb0cfc38d96ea24754f2aa6171d48c1..0dbf47b3c074b7878b205ec40da73a90f3ba6f34 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
@@ -63,7 +63,7 @@ impl BlockUserFromCommunity {
 
     let activity = AnnouncableActivities::BlockUserFromCommunity(block);
     let inboxes = vec![target.shared_inbox_or_inbox_url()];
-    send_to_community(activity, &block_id, actor, community, inboxes, context).await
+    send_activity_in_community(activity, &block_id, actor, community, inboxes, context).await
   }
 }
 
index c527f0a81523505e89597134b9a8574f1a409490..c2141c2df2bd7c84efbcee52e879ea56066524ea 100644 (file)
@@ -18,23 +18,21 @@ pub mod report;
 pub mod undo_block_user;
 pub mod update;
 
-pub(crate) async fn send_to_community<T: ActorType>(
+pub(crate) async fn send_activity_in_community<T: ActorType>(
   activity: AnnouncableActivities,
   activity_id: &Url,
   actor: &T,
   community: &ApubCommunity,
-  additional_inboxes: Vec<Url>,
+  mut inboxes: Vec<Url>,
   context: &LemmyContext,
 ) -> Result<(), LemmyError> {
-  // if this is a local community, we need to do an announce from the community instead
-  let object_value = serde_json::to_value(&activity)?;
+  inboxes.push(community.shared_inbox_or_inbox_url());
+  send_lemmy_activity(context, &activity, activity_id, actor, inboxes, false).await?;
+
   if community.local {
+    let object_value = serde_json::to_value(&activity)?;
     insert_activity(activity_id, object_value, true, false, context.pool()).await?;
-    AnnounceActivity::send(activity, community, additional_inboxes, context).await?;
-  } else {
-    let mut inboxes = additional_inboxes;
-    inboxes.push(community.shared_inbox_or_inbox_url());
-    send_lemmy_activity(context, &activity, activity_id, actor, inboxes, false).await?;
+    AnnounceActivity::send(activity, community, context).await?;
   }
 
   Ok(())
index a644c19d7a8ec47e15c1cbe2ef84c0f08b87bfe2..985a2192245eb3782aef31770aa1a0451ab1dad7 100644 (file)
@@ -1,6 +1,10 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, get_community_from_moderators_url, send_to_community},
+    community::{
+      announce::GetCommunity,
+      get_community_from_moderators_url,
+      send_activity_in_community,
+    },
     generate_activity_id,
     verify_activity,
     verify_add_remove_moderator_target,
@@ -51,7 +55,7 @@ impl RemoveMod {
 
     let activity = AnnouncableActivities::RemoveMod(remove);
     let inboxes = vec![removed_mod.shared_inbox_or_inbox_url()];
-    send_to_community(activity, &id, actor, community, inboxes, context).await
+    send_activity_in_community(activity, &id, actor, community, inboxes, context).await
   }
 }
 
index f309fe2b8bc5ff66690708f05ca8b065afd8a034..4aabb1d4cd0fcd8a6651b614f7b9209bfcdaeedd 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
@@ -53,7 +53,7 @@ impl UndoBlockUserFromCommunity {
 
     let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
     let inboxes = vec![target.shared_inbox_or_inbox_url()];
-    send_to_community(activity, &id, actor, community, inboxes, context).await
+    send_activity_in_community(activity, &id, actor, community, inboxes, context).await
   }
 }
 
index cc82c9e310d76f44ec15f2db268b2a2d35e8daaa..e625fe0c74c0c8fc0aed3e2fc76ee407d289f6ed 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
@@ -46,7 +46,7 @@ impl UpdateCommunity {
     };
 
     let activity = AnnouncableActivities::UpdateCommunity(update);
-    send_to_community(activity, &id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, &id, actor, &community, vec![], context).await
   }
 }
 
index 54e9c3941e2dbb985e32a7546d2023cd636f3075..cec8ab9a3c543dedf6fd8bf000b5a138ef0bbd11 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
     generate_activity_id,
     verify_activity,
@@ -118,7 +118,7 @@ impl Delete {
     let delete_id = delete.id.clone();
 
     let activity = AnnouncableActivities::Delete(delete);
-    send_to_community(activity, &delete_id, actor, community, vec![], context).await
+    send_activity_in_community(activity, &delete_id, actor, community, vec![], context).await
   }
 }
 
index edd893bc3afcebee91f4109700d568dff51bde6d..c6e5ddfc0b7e518ca5bb76b2d66b8ab7bf7aef03 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
     generate_activity_id,
     verify_activity,
@@ -96,7 +96,7 @@ impl UndoDelete {
     };
 
     let activity = AnnouncableActivities::UndoDelete(undo);
-    send_to_community(activity, &id, actor, community, vec![], context).await
+    send_activity_in_community(activity, &id, actor, community, vec![], context).await
   }
 
   pub(in crate::activities) async fn receive_undo_remove_action(
index 3fb6a13894be3656cd7a13a81cfd1875a4e7b309..84c185bef955d2b5254b35109d8f7514af25d137 100644 (file)
@@ -1,7 +1,7 @@
 use crate::{
   activities::{
     check_community_deleted_or_removed,
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
@@ -63,7 +63,7 @@ impl CreateOrUpdatePost {
     let create_or_update = CreateOrUpdatePost::new(post, actor, &community, kind, context).await?;
     let id = create_or_update.id.clone();
     let activity = AnnouncableActivities::CreateOrUpdatePost(create_or_update);
-    send_to_community(activity, &id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, &id, actor, &community, vec![], context).await
   }
 }
 
index c066d731ca6e47718a9a0ddb09b406ae80cb09b9..e403a335aa9344bdb9a426463b3a349bf5100cd1 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
@@ -56,7 +56,7 @@ impl UndoVote {
       unparsed: Default::default(),
     };
     let activity = AnnouncableActivities::UndoVote(undo_vote);
-    send_to_community(activity, &id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, &id, actor, &community, vec![], context).await
   }
 }
 
index 304c512a75ff656755ebb56cf73064e5d590593f..2253b9aa739b289e05601e8b32c0e118cc770c2e 100644 (file)
@@ -1,6 +1,6 @@
 use crate::{
   activities::{
-    community::{announce::GetCommunity, send_to_community},
+    community::{announce::GetCommunity, send_activity_in_community},
     generate_activity_id,
     verify_activity,
     verify_is_public,
@@ -62,7 +62,7 @@ impl Vote {
     let vote_id = vote.id.clone();
 
     let activity = AnnouncableActivities::Vote(vote);
-    send_to_community(activity, &vote_id, actor, &community, vec![], context).await
+    send_activity_in_community(activity, &vote_id, actor, &community, vec![], context).await
   }
 }
 
index 330de0b854cb8a46a6d53b1583174dfe6160eb58..6b95626d5920b3af49eefd39993c780e509a2488 100644 (file)
@@ -85,7 +85,7 @@ pub(in crate::http) async fn receive_group_inbox(
     let community = announcable.get_community(context, &mut 0).await?;
     verify_person_in_community(&actor_id, &community, context, &mut 0).await?;
     if community.local {
-      AnnounceActivity::send(*announcable, &community, vec![], context).await?;
+      AnnounceActivity::send(*announcable, &community, context).await?;
     }
   }
 
index f2fb45e4fb30899ce18684341b78c5cc9e050737..87fca8d3504a350bae14ac02e398010245e4864d 100644 (file)
@@ -192,7 +192,6 @@ impl ApubCommunity {
   /// For a given community, returns the inboxes of all followers.
   pub(crate) async fn get_follower_inboxes(
     &self,
-    additional_inboxes: Vec<Url>,
     context: &LemmyContext,
   ) -> Result<Vec<Url>, LemmyError> {
     let id = self.id;
@@ -201,7 +200,7 @@ impl ApubCommunity {
       CommunityFollowerView::for_community(conn, id)
     })
     .await??;
-    let follower_inboxes: Vec<Url> = follows
+    let inboxes: Vec<Url> = follows
       .into_iter()
       .filter(|f| !f.follower.local)
       .map(|f| {
@@ -210,12 +209,8 @@ impl ApubCommunity {
           .unwrap_or(f.follower.inbox_url)
           .into()
       })
-      .collect();
-    let inboxes = vec![follower_inboxes, additional_inboxes]
-      .into_iter()
-      .flatten()
       .unique()
-      .filter(|inbox| inbox.host_str() != Some(&context.settings().hostname))
+      .filter(|inbox: &Url| inbox.host_str() != Some(&context.settings().hostname))
       // Don't send to blocked instances
       .filter(|inbox| check_is_apub_id_valid(inbox, false, &context.settings()).is_ok())
       .collect();