]> Untitled Git - lemmy.git/blob - crates/apub/src/activities/community/mod.rs
Merge pull request #1678 from LemmyNet/rewrite-post
[lemmy.git] / crates / apub / src / activities / community / mod.rs
1 use crate::{check_is_apub_id_valid, CommunityType};
2 use itertools::Itertools;
3 use lemmy_api_common::{blocking, community::CommunityResponse};
4 use lemmy_db_schema::{source::community::Community, CommunityId};
5 use lemmy_db_views_actor::community_view::CommunityView;
6 use lemmy_utils::{settings::structs::Settings, LemmyError};
7 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext};
8 use url::Url;
9
10 pub mod add_mod;
11 pub mod announce;
12 pub mod block_user;
13 pub mod undo_block_user;
14 pub mod update;
15
16 pub(crate) async fn send_websocket_message<
17   OP: ToString + Send + lemmy_websocket::OperationType + 'static,
18 >(
19   community_id: CommunityId,
20   op: OP,
21   context: &LemmyContext,
22 ) -> Result<(), LemmyError> {
23   let community_view = blocking(context.pool(), move |conn| {
24     CommunityView::read(conn, community_id, None)
25   })
26   .await??;
27
28   let res = CommunityResponse { community_view };
29
30   context.chat_server().do_send(SendCommunityRoomMessage {
31     op,
32     response: res,
33     community_id,
34     websocket_id: None,
35   });
36
37   Ok(())
38 }
39
40 async fn list_community_follower_inboxes(
41   community: &Community,
42   additional_inboxes: Vec<Url>,
43   context: &LemmyContext,
44 ) -> Result<Vec<Url>, LemmyError> {
45   Ok(
46     vec![
47       community.get_follower_inboxes(context.pool()).await?,
48       additional_inboxes,
49     ]
50     .iter()
51     .flatten()
52     .unique()
53     .filter(|inbox| inbox.host_str() != Some(&Settings::get().hostname()))
54     .filter(|inbox| check_is_apub_id_valid(inbox, false).is_ok())
55     .map(|inbox| inbox.to_owned())
56     .collect(),
57   )
58 }