2 activities::send_lemmy_activity,
3 activity_lists::AnnouncableActivities,
4 objects::{community::ApubCommunity, person::ApubPerson},
5 protocol::activities::community::announce::AnnounceActivity,
7 use activitypub_federation::traits::Actor;
8 use lemmy_api_common::context::LemmyContext;
9 use lemmy_db_schema::source::person::PersonFollower;
10 use lemmy_utils::error::LemmyError;
14 pub mod collection_add;
15 pub mod collection_remove;
20 /// This function sends all activities which are happening in a community to the right inboxes.
21 /// For example Create/Page, Add/Mod etc, but not private messages.
23 /// Activities are sent to the community itself if it lives on another instance. If the community
24 /// is local, the activity is directly wrapped into Announce and sent to community followers.
25 /// Activities are also sent to those who follow the actor (with exception of moderation activities).
27 /// * `activity` - The activity which is being sent
28 /// * `actor` - The user who is sending the activity
29 /// * `community` - Community inside which the activity is sent
30 /// * `inboxes` - Any additional inboxes the activity should be sent to (for example,
31 /// to the user who is being promoted to moderator)
32 /// * `is_mod_activity` - True for things like Add/Mod, these are not sent to user followers
33 pub(crate) async fn send_activity_in_community(
34 activity: AnnouncableActivities,
36 community: &ApubCommunity,
37 extra_inboxes: Vec<Url>,
39 context: &LemmyContext,
40 ) -> Result<(), LemmyError> {
41 // send to extra_inboxes
42 send_lemmy_activity(context, activity.clone(), actor, extra_inboxes, false).await?;
45 // send directly to community followers
46 AnnounceActivity::send(activity.clone().try_into()?, community, context).await?;
48 // send to the community, which will then forward to followers
49 let inbox = vec![community.shared_inbox_or_inbox()];
50 send_lemmy_activity(context, activity.clone(), actor, inbox, false).await?;
53 // send to those who follow `actor`
55 let inboxes = PersonFollower::list_followers(context.pool(), actor.id)
58 .map(|p| ApubPerson(p).shared_inbox_or_inbox())
60 send_lemmy_activity(context, activity, actor, inboxes, false).await?;