2021-10-28 15:52:11 +00:00
|
|
|
use crate::generate_followers_url;
|
|
|
|
use activitystreams::collection::kind::CollectionType;
|
|
|
|
use lemmy_api_common::blocking;
|
|
|
|
use lemmy_db_schema::source::community::Community;
|
|
|
|
use lemmy_db_views_actor::community_follower_view::CommunityFollowerView;
|
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-11-01 13:05:20 +00:00
|
|
|
pub(crate) struct GroupFollowers {
|
2021-10-28 15:52:11 +00:00
|
|
|
id: Url,
|
|
|
|
r#type: CollectionType,
|
|
|
|
total_items: i32,
|
|
|
|
items: Vec<()>,
|
|
|
|
}
|
|
|
|
|
2021-11-01 13:05:20 +00:00
|
|
|
impl GroupFollowers {
|
2021-10-28 15:52:11 +00:00
|
|
|
pub(crate) async fn new(
|
|
|
|
community: Community,
|
|
|
|
context: &LemmyContext,
|
2021-11-01 13:05:20 +00:00
|
|
|
) -> Result<GroupFollowers, LemmyError> {
|
2021-10-28 15:52:11 +00:00
|
|
|
let community_id = community.id;
|
|
|
|
let community_followers = blocking(context.pool(), move |conn| {
|
|
|
|
CommunityFollowerView::for_community(conn, community_id)
|
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
|
2021-11-01 13:05:20 +00:00
|
|
|
Ok(GroupFollowers {
|
2021-11-05 00:24:10 +00:00
|
|
|
id: generate_followers_url(&community.actor_id)?.into(),
|
2021-10-28 15:52:11 +00:00
|
|
|
r#type: CollectionType::Collection,
|
|
|
|
total_items: community_followers.len() as i32,
|
|
|
|
items: vec![],
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|