2 activities::send_lemmy_activity,
3 activity_lists::AnnouncableActivities,
5 objects::{community::ApubCommunity, person::ApubPerson},
6 protocol::activities::community::announce::AnnounceActivity,
8 use activitypub_federation::{core::object_id::ObjectId, traits::Actor};
9 use lemmy_api_common::LemmyContext;
10 use lemmy_db_schema::source::person::PersonFollower;
11 use lemmy_utils::error::LemmyError;
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?;
66 #[tracing::instrument(skip_all)]
67 pub(crate) async fn get_community_from_moderators_url(
69 context: &LemmyContext,
70 request_counter: &mut i32,
71 ) -> Result<ApubCommunity, LemmyError> {
72 let community_id = Url::parse(&moderators.to_string().replace("/moderators", ""))?;
73 ObjectId::new(community_id)
74 .dereference(context, local_instance(context).await, request_counter)