Expose remote site info in GetCommunity API (fixes #2208) (#2210)

* Expose remote site info in GetCommunity API (fixes #2208)

* use instance_actor_id_from_url()
This commit is contained in:
Nutomic 2022-04-13 16:37:54 +00:00 committed by GitHub
parent 3d8709780a
commit e0381df88a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 3 deletions

View file

@ -505,6 +505,7 @@ impl Perform for TransferCommunity {
// Return the jwt // Return the jwt
Ok(GetCommunityResponse { Ok(GetCommunityResponse {
community_view, community_view,
site: None,
moderators, moderators,
online: 0, online: 0,
}) })

View file

@ -1,4 +1,7 @@
use lemmy_db_schema::newtypes::{CommunityId, PersonId}; use lemmy_db_schema::{
newtypes::{CommunityId, PersonId},
source::site::Site,
};
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_moderator_view::CommunityModeratorView, community_moderator_view::CommunityModeratorView,
community_view::CommunityView, community_view::CommunityView,
@ -18,6 +21,7 @@ pub struct GetCommunity {
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
pub struct GetCommunityResponse { pub struct GetCommunityResponse {
pub community_view: CommunityView, pub community_view: CommunityView,
pub site: Option<Site>,
pub moderators: Vec<CommunityModeratorView>, pub moderators: Vec<CommunityModeratorView>,
pub online: usize, pub online: usize,
} }

View file

@ -6,10 +6,13 @@ use lemmy_api_common::{
community::*, community::*,
get_local_user_view_from_jwt_opt, get_local_user_view_from_jwt_opt,
}; };
use lemmy_apub::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity}; use lemmy_apub::{
fetcher::resolve_actor_identifier,
objects::{community::ApubCommunity, instance::instance_actor_id_from_url},
};
use lemmy_db_schema::{ use lemmy_db_schema::{
from_opt_str_to_opt_enum, from_opt_str_to_opt_enum,
source::community::Community, source::{community::Community, site::Site},
traits::DeleteableOrRemoveable, traits::DeleteableOrRemoveable,
ListingType, ListingType,
SortType, SortType,
@ -75,8 +78,22 @@ impl PerformCrud for GetCommunity {
.await .await
.unwrap_or(1); .unwrap_or(1);
let site_id = instance_actor_id_from_url(community_view.community.actor_id.clone().into());
let mut site: Option<Site> = blocking(context.pool(), move |conn| {
Site::read_from_apub_id(conn, site_id)
})
.await??;
// no need to include metadata for local site (its already available through other endpoints).
// this also prevents us from leaking the federation private key.
if let Some(s) = &site {
if s.actor_id.domain() == Some(context.settings().hostname.as_ref()) {
site = None;
}
}
let res = GetCommunityResponse { let res = GetCommunityResponse {
community_view, community_view,
site,
moderators, moderators,
online, online,
}; };