]> Untitled Git - lemmy.git/commitdiff
Separate federated_instances into its own endpoint. Fixes #1931 (#2813)
authorDessalines <dessalines@users.noreply.github.com>
Sun, 16 Apr 2023 21:00:31 +0000 (17:00 -0400)
committerGitHub <noreply@github.com>
Sun, 16 Apr 2023 21:00:31 +0000 (17:00 -0400)
crates/api/src/site/federated_instances.rs [new file with mode: 0644]
crates/api/src/site/leave_admin.rs
crates/api/src/site/mod.rs
crates/api_common/src/site.rs
crates/api_common/src/websocket/mod.rs
crates/api_crud/src/site/read.rs
crates/apub/src/activities/unfederated.rs
src/api_routes_http.rs
src/api_routes_websocket.rs

diff --git a/crates/api/src/site/federated_instances.rs b/crates/api/src/site/federated_instances.rs
new file mode 100644 (file)
index 0000000..107fece
--- /dev/null
@@ -0,0 +1,29 @@
+use crate::Perform;
+use actix_web::web::Data;
+use lemmy_api_common::{
+  context::LemmyContext,
+  site::{GetFederatedInstances, GetFederatedInstancesResponse},
+  utils::build_federated_instances,
+};
+use lemmy_db_views::structs::SiteView;
+use lemmy_utils::{error::LemmyError, ConnectionId};
+
+#[async_trait::async_trait(?Send)]
+impl Perform for GetFederatedInstances {
+  type Response = GetFederatedInstancesResponse;
+
+  #[tracing::instrument(skip(context, _websocket_id))]
+  async fn perform(
+    &self,
+    context: &Data<LemmyContext>,
+    _websocket_id: Option<ConnectionId>,
+  ) -> Result<Self::Response, LemmyError> {
+    let site_view = SiteView::read_local(context.pool()).await?;
+    let federated_instances =
+      build_federated_instances(&site_view.local_site, context.pool()).await?;
+
+    Ok(Self::Response {
+      federated_instances,
+    })
+  }
+}
index c0f20eaf084685e2d675e107cf4217cfd26cb4e8..4cec5fc4ad1958665ec14fc0f4b1572c375f53dd 100644 (file)
@@ -73,7 +73,6 @@ impl Perform for LeaveAdmin {
       online: 0,
       version: version::VERSION.to_string(),
       my_user: None,
-      federated_instances: None,
       all_languages,
       discussion_languages,
       taglines,
index 4e3694ce4640172d7a1b3d6e01021bc52d9e23b8..c23839c946f94876ca9e011e1562790db344baac 100644 (file)
@@ -1,3 +1,4 @@
+mod federated_instances;
 mod leave_admin;
 mod mod_log;
 mod purge;
index 524d102047b5d0ab7ae7a028efbb5a93ce7da964..a290beb1092121cb6328fab0ce1968b2aa4c2756 100644 (file)
@@ -222,13 +222,20 @@ pub struct GetSiteResponse {
   pub online: usize,
   pub version: String,
   pub my_user: Option<MyUserInfo>,
-  pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
   pub all_languages: Vec<Language>,
   pub discussion_languages: Vec<LanguageId>,
   pub taglines: Vec<Tagline>,
   pub custom_emojis: Vec<CustomEmojiView>,
 }
 
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct GetFederatedInstances {}
+
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct GetFederatedInstancesResponse {
+  pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
+}
+
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct MyUserInfo {
   pub local_user_view: LocalUserView,
index 2726b7d4cb788f982900d2caf0c44185a52fbd3a..2f13d8b8cef6c9a929e5c8f3b60aeea4ed800d1b 100644 (file)
@@ -94,6 +94,7 @@ pub enum UserOperation {
   PurgeCommunity,
   PurgePost,
   PurgeComment,
+  GetFederatedInstances,
 }
 
 #[derive(EnumString, Display, Debug, Clone)]
index 2330d0f739dbec1fd1616372fbb7193393f77ab0..fc74ecaebc597f1966499adce44880c99b440649 100644 (file)
@@ -3,7 +3,7 @@ use actix_web::web::Data;
 use lemmy_api_common::{
   context::LemmyContext,
   site::{GetSite, GetSiteResponse, MyUserInfo},
-  utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
+  utils::get_local_user_settings_view_from_jwt_opt,
   websocket::handlers::online_users::GetUsersOnline,
 };
 use lemmy_db_schema::source::{
@@ -84,9 +84,6 @@ impl PerformCrud for GetSite {
       None
     };
 
-    let federated_instances =
-      build_federated_instances(&site_view.local_site, context.pool()).await?;
-
     let all_languages = Language::read_all(context.pool()).await?;
     let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
     let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
@@ -98,7 +95,6 @@ impl PerformCrud for GetSite {
       online,
       version: version::VERSION.to_string(),
       my_user,
-      federated_instances,
       all_languages,
       discussion_languages,
       taglines,
index e2fff292de8b913eab0ee9cd5b6bde0d7d7c5e7c..0a7981a47c82f03413c83cd2b6e6fef88ce371d0 100644 (file)
@@ -93,6 +93,8 @@ use lemmy_api_common::{
     ApproveRegistrationApplication,
     CreateSite,
     EditSite,
+    GetFederatedInstances,
+    GetFederatedInstancesResponse,
     GetModlog,
     GetModlogResponse,
     GetSite,
@@ -373,3 +375,7 @@ impl SendActivity for EditCustomEmoji {
 impl SendActivity for DeleteCustomEmoji {
   type Response = DeleteCustomEmojiResponse;
 }
+
+impl SendActivity for GetFederatedInstances {
+  type Response = GetFederatedInstancesResponse;
+}
index d59253deecd4ab7f40651e0b1f27d2a3507bf9b0..725e5babdecf3ca4de0bf80e64a8a2f447cb2d7f 100644 (file)
@@ -86,6 +86,7 @@ use lemmy_api_common::{
     ApproveRegistrationApplication,
     CreateSite,
     EditSite,
+    GetFederatedInstances,
     GetModlog,
     GetSite,
     GetUnreadRegistrationApplicationCount,
@@ -165,6 +166,11 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
           .route("/join", web::post().to(route_post::<CommunityJoin>))
           .route("/mod/join", web::post().to(route_post::<ModJoin>)),
       )
+      .service(
+        web::scope("/federated_instances")
+          .wrap(rate_limit.message())
+          .route("", web::get().to(route_get::<GetFederatedInstances>)),
+      )
       // Post
       .service(
         // Handle POST to /post separately to add the post() rate limitter
index b3ce85bdbfd9711edcdaaa1a7dd53bfbc168a479..23b9a5b5e14e9240797f3a3035169e1d23a06378 100644 (file)
@@ -98,6 +98,7 @@ use lemmy_api_common::{
     ApproveRegistrationApplication,
     CreateSite,
     EditSite,
+    GetFederatedInstances,
     GetModlog,
     GetSite,
     GetUnreadRegistrationApplicationCount,
@@ -640,6 +641,9 @@ pub async fn match_websocket_operation(
       do_websocket_operation::<TransferCommunity>(context, id, op, data).await
     }
     UserOperation::LeaveAdmin => do_websocket_operation::<LeaveAdmin>(context, id, op, data).await,
+    UserOperation::GetFederatedInstances => {
+      do_websocket_operation::<GetFederatedInstances>(context, id, op, data).await
+    }
 
     // Community ops
     UserOperation::FollowCommunity => {