1 use itertools::Itertools;
4 use lemmy_apub_lib::traits::ActorType;
5 use lemmy_utils::LemmyError;
6 use lemmy_websocket::LemmyContext;
9 activities::send_lemmy_activity,
10 activity_lists::AnnouncableActivities,
11 check_is_apub_id_valid,
12 fetcher::object_id::ObjectId,
14 objects::community::ApubCommunity,
15 protocol::activities::community::announce::AnnounceActivity,
23 pub mod undo_block_user;
26 async fn list_community_follower_inboxes(
27 community: &ApubCommunity,
28 additional_inboxes: Vec<Url>,
29 context: &LemmyContext,
30 ) -> Result<Vec<Url>, LemmyError> {
34 .get_follower_inboxes(context.pool(), &context.settings())
41 .filter(|inbox| inbox.host_str() != Some(&context.settings().hostname))
42 .filter(|inbox| check_is_apub_id_valid(inbox, false, &context.settings()).is_ok())
43 .map(|inbox| inbox.to_owned())
48 pub(crate) async fn send_to_community<T: ActorType>(
49 activity: AnnouncableActivities,
52 community: &ApubCommunity,
53 additional_inboxes: Vec<Url>,
54 context: &LemmyContext,
55 ) -> Result<(), LemmyError> {
56 // if this is a local community, we need to do an announce from the community instead
58 insert_activity(activity_id, activity.clone(), true, false, context.pool()).await?;
59 AnnounceActivity::send(activity, community, additional_inboxes, context).await?;
61 let mut inboxes = additional_inboxes;
62 inboxes.push(community.shared_inbox_or_inbox_url());
63 send_lemmy_activity(context, &activity, activity_id, actor, inboxes, false).await?;
69 async fn get_community_from_moderators_url(
71 context: &LemmyContext,
72 request_counter: &mut i32,
73 ) -> Result<ApubCommunity, LemmyError> {
74 let community_id = Url::parse(&moderators.to_string().replace("/moderators", ""))?;
75 ObjectId::new(community_id)
76 .dereference(context, request_counter)