3 fetcher::resolve_actor_identifier,
4 objects::community::ApubCommunity,
6 use activitypub_federation::config::Data;
7 use lemmy_api_common::{
8 community::{GetCommunity, GetCommunityResponse},
10 utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_mod_or_admin_opt},
11 websocket::handlers::online_users::GetCommunityUsersOnline,
13 use lemmy_db_schema::source::{
14 actor_language::CommunityLanguage,
16 local_site::LocalSite,
19 use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
20 use lemmy_utils::{error::LemmyError, ConnectionId};
22 #[async_trait::async_trait]
23 impl PerformApub for GetCommunity {
24 type Response = GetCommunityResponse;
26 #[tracing::instrument(skip(context, _websocket_id))]
29 context: &Data<LemmyContext>,
30 _websocket_id: Option<ConnectionId>,
31 ) -> Result<GetCommunityResponse, LemmyError> {
32 let data: &GetCommunity = self;
34 get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
36 let local_site = LocalSite::read(context.pool()).await?;
38 if data.name.is_none() && data.id.is_none() {
39 return Err(LemmyError::from_message("no_id_given"));
42 check_private_instance(&local_user_view, &local_site)?;
44 let person_id = local_user_view.as_ref().map(|u| u.person.id);
46 let community_id = match data.id {
49 let name = data.name.clone().unwrap_or_else(|| "main".to_string());
50 resolve_actor_identifier::<ApubCommunity, Community>(&name, context, &local_user_view, true)
52 .map_err(|e| e.with_message("couldnt_find_community"))?
58 is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), Some(community_id))
62 let community_view = CommunityView::read(
66 Some(is_mod_or_admin),
69 .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
71 let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
73 .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
77 .send(GetCommunityUsersOnline { community_id })
81 Site::instance_actor_id_from_url(community_view.community.actor_id.clone().into());
82 let mut site = Site::read_from_apub_id(context.pool(), &site_id.into()).await?;
83 // no need to include metadata for local site (its already available through other endpoints).
84 // this also prevents us from leaking the federation private key.
85 if let Some(s) = &site {
86 if s.actor_id.domain() == Some(context.settings().hostname.as_ref()) {
91 let community_id = community_view.community.id;
92 let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
94 let res = GetCommunityResponse {