From: Felix Ableitner Date: Mon, 15 Nov 2021 21:37:19 +0000 (+0100) Subject: Activities in community should also be sent to actors in cc X-Git-Url: http://these/git/%7B%60https:/matrix.to?a=commitdiff_plain;h=c1f1b8aa0f5f445bb8296d35726f90e427a77553;p=lemmy.git Activities in community should also be sent to actors in cc --- diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index 7ac1e4e5..eab2a577 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -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 } } diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index f8026cce..7437750d 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -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 } } diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index fc6c5686..4eebcce3 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -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, 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), diff --git a/crates/apub/src/activities/community/block_user.rs b/crates/apub/src/activities/community/block_user.rs index 4be0660f..0dbf47b3 100644 --- a/crates/apub/src/activities/community/block_user.rs +++ b/crates/apub/src/activities/community/block_user.rs @@ -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 } } diff --git a/crates/apub/src/activities/community/mod.rs b/crates/apub/src/activities/community/mod.rs index c527f0a8..c2141c2d 100644 --- a/crates/apub/src/activities/community/mod.rs +++ b/crates/apub/src/activities/community/mod.rs @@ -18,23 +18,21 @@ pub mod report; pub mod undo_block_user; pub mod update; -pub(crate) async fn send_to_community( +pub(crate) async fn send_activity_in_community( activity: AnnouncableActivities, activity_id: &Url, actor: &T, community: &ApubCommunity, - additional_inboxes: Vec, + mut inboxes: Vec, 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(()) diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index a644c19d..985a2192 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -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 } } diff --git a/crates/apub/src/activities/community/undo_block_user.rs b/crates/apub/src/activities/community/undo_block_user.rs index f309fe2b..4aabb1d4 100644 --- a/crates/apub/src/activities/community/undo_block_user.rs +++ b/crates/apub/src/activities/community/undo_block_user.rs @@ -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 } } diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index cc82c9e3..e625fe0c 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -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 } } diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 54e9c394..cec8ab9a 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -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 } } diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index edd893bc..c6e5ddfc 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -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( diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index 3fb6a138..84c185be 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -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 } } diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index c066d731..e403a335 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -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 } } diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 304c512a..2253b9aa 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -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 } } diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index 330de0b8..6b95626d 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -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?; } } diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index f2fb45e4..87fca8d3 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -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, context: &LemmyContext, ) -> Result, LemmyError> { let id = self.id; @@ -201,7 +200,7 @@ impl ApubCommunity { CommunityFollowerView::for_community(conn, id) }) .await??; - let follower_inboxes: Vec = follows + let inboxes: Vec = 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();