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,
};
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
}
}
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,
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
}
}
};
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
-use url::Url;
#[async_trait::async_trait(?Send)]
pub(crate) trait GetCommunity {
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,
)
.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),
use crate::{
activities::{
- community::{announce::GetCommunity, send_to_community},
+ community::{announce::GetCommunity, send_activity_in_community},
generate_activity_id,
verify_activity,
verify_is_public,
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
}
}
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(())
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,
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
}
}
use crate::{
activities::{
- community::{announce::GetCommunity, send_to_community},
+ community::{announce::GetCommunity, send_activity_in_community},
generate_activity_id,
verify_activity,
verify_is_public,
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
}
}
use crate::{
activities::{
- community::{announce::GetCommunity, send_to_community},
+ community::{announce::GetCommunity, send_activity_in_community},
generate_activity_id,
verify_activity,
verify_is_public,
};
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
}
}
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,
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
}
}
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,
};
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(
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,
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
}
}
use crate::{
activities::{
- community::{announce::GetCommunity, send_to_community},
+ community::{announce::GetCommunity, send_activity_in_community},
generate_activity_id,
verify_activity,
verify_is_public,
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
}
}
use crate::{
activities::{
- community::{announce::GetCommunity, send_to_community},
+ community::{announce::GetCommunity, send_activity_in_community},
generate_activity_id,
verify_activity,
verify_is_public,
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
}
}
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?;
}
}
/// 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;
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| {
.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();