]> Untitled Git - lemmy.git/commitdiff
Expose remote site info in GetCommunity API (fixes #2208) (#2210)
authorNutomic <me@nutomic.com>
Wed, 13 Apr 2022 16:37:54 +0000 (16:37 +0000)
committerGitHub <noreply@github.com>
Wed, 13 Apr 2022 16:37:54 +0000 (16:37 +0000)
* Expose remote site info in GetCommunity API (fixes #2208)

* use instance_actor_id_from_url()

crates/api/src/community.rs
crates/api_common/src/community.rs
crates/api_crud/src/community/read.rs

index d71ef7fa01ca152dbcd9a05092e6f84d9a772fe3..82ee8072339ff5493900b2a1c651feff3e64f9fe 100644 (file)
@@ -505,6 +505,7 @@ impl Perform for TransferCommunity {
     // Return the jwt
     Ok(GetCommunityResponse {
       community_view,
+      site: None,
       moderators,
       online: 0,
     })
index fbfe3c6607d9c507c3293fda15cd2cd878d99c46..4b9209d6af98e1d54f21ba4048443d22515a3d9d 100644 (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::{
   community_moderator_view::CommunityModeratorView,
   community_view::CommunityView,
@@ -18,6 +21,7 @@ pub struct GetCommunity {
 #[derive(Debug, Serialize, Deserialize)]
 pub struct GetCommunityResponse {
   pub community_view: CommunityView,
+  pub site: Option<Site>,
   pub moderators: Vec<CommunityModeratorView>,
   pub online: usize,
 }
index de567c1fb647468f085d98db18c7dbbdfac5c6b1..d4a28b7819231326450d9528ec7bfda8ed7b6cbe 100644 (file)
@@ -6,10 +6,13 @@ use lemmy_api_common::{
   community::*,
   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::{
   from_opt_str_to_opt_enum,
-  source::community::Community,
+  source::{community::Community, site::Site},
   traits::DeleteableOrRemoveable,
   ListingType,
   SortType,
@@ -75,8 +78,22 @@ impl PerformCrud for GetCommunity {
       .await
       .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 {
       community_view,
+      site,
       moderators,
       online,
     };