Activities in community should also be sent to actors in cc

This commit is contained in:
Felix Ableitner 2021-11-15 22:37:19 +01:00
parent dc416bf255
commit c1f1b8aa0f
15 changed files with 44 additions and 47 deletions

View 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
}
}

View 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
}
}

View 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),

View 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
}
}

View 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(())

View 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
}
}

View 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
}
}

View 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
}
}

View 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
}
}

View 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(

View 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
}
}

View 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
}
}

View 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
}
}

View 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?;
}
}

View 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();