]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/collections/group_followers.rs
a3814501c82e7e7b012b215443b6e98c79a7abc2
[lemmy.git] / crates / apub / src / protocol / collections / group_followers.rs
1 use activitypub_federation::kinds::collection::CollectionType;
2 use lemmy_api_common::{context::LemmyContext, utils::generate_followers_url};
3 use lemmy_db_schema::source::community::Community;
4 use lemmy_db_views_actor::structs::CommunityFollowerView;
5 use lemmy_utils::error::LemmyError;
6 use serde::{Deserialize, Serialize};
7 use url::Url;
8
9 #[derive(Clone, Debug, Deserialize, Serialize)]
10 #[serde(rename_all = "camelCase")]
11 pub(crate) struct GroupFollowers {
12   id: Url,
13   r#type: CollectionType,
14   total_items: i32,
15   items: Vec<()>,
16 }
17
18 impl GroupFollowers {
19   pub(crate) async fn new(
20     community: Community,
21     context: &LemmyContext,
22   ) -> Result<GroupFollowers, LemmyError> {
23     let community_id = community.id;
24     let community_followers =
25       CommunityFollowerView::count_community_followers(&mut context.pool(), community_id).await?;
26
27     Ok(GroupFollowers {
28       id: generate_followers_url(&community.actor_id)?.into(),
29       r#type: CollectionType::Collection,
30       total_items: community_followers as i32,
31       items: vec![],
32     })
33   }
34 }