1 use crate::{check_is_apub_id_valid, ActorType, CommunityType};
2 use itertools::Itertools;
3 use lemmy_api_common::blocking;
4 use lemmy_db_queries::DbPool;
5 use lemmy_db_schema::source::community::Community;
6 use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
7 use lemmy_utils::LemmyError;
10 impl ActorType for Community {
11 fn is_local(&self) -> bool {
14 fn actor_id(&self) -> Url {
15 self.actor_id.to_owned().into()
17 fn name(&self) -> String {
20 fn public_key(&self) -> Option<String> {
21 self.public_key.to_owned()
23 fn private_key(&self) -> Option<String> {
24 self.private_key.to_owned()
27 fn get_shared_inbox_or_inbox_url(&self) -> Url {
31 .unwrap_or_else(|| self.inbox_url.to_owned())
36 #[async_trait::async_trait(?Send)]
37 impl CommunityType for Community {
38 fn followers_url(&self) -> Url {
39 self.followers_url.clone().into()
42 /// For a given community, returns the inboxes of all followers.
43 async fn get_follower_inboxes(&self, pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
46 let follows = blocking(pool, move |conn| {
47 CommunityFollowerView::for_community(conn, id)
52 .filter(|f| !f.follower.local)
53 .map(|f| f.follower.shared_inbox_url.unwrap_or(f.follower.inbox_url))
54 .map(|i| i.into_inner())
56 // Don't send to blocked instances
57 .filter(|inbox| check_is_apub_id_valid(inbox, false).is_ok())