--- /dev/null
+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,
+ })
+ }
+}
online: 0,
version: version::VERSION.to_string(),
my_user: None,
- federated_instances: None,
all_languages,
discussion_languages,
taglines,
+mod federated_instances;
mod leave_admin;
mod mod_log;
mod purge;
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,
PurgeCommunity,
PurgePost,
PurgeComment,
+ GetFederatedInstances,
}
#[derive(EnumString, Display, Debug, Clone)]
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::{
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?;
online,
version: version::VERSION.to_string(),
my_user,
- federated_instances,
all_languages,
discussion_languages,
taglines,
ApproveRegistrationApplication,
CreateSite,
EditSite,
+ GetFederatedInstances,
+ GetFederatedInstancesResponse,
GetModlog,
GetModlogResponse,
GetSite,
impl SendActivity for DeleteCustomEmoji {
type Response = DeleteCustomEmojiResponse;
}
+
+impl SendActivity for GetFederatedInstances {
+ type Response = GetFederatedInstancesResponse;
+}
ApproveRegistrationApplication,
CreateSite,
EditSite,
+ GetFederatedInstances,
GetModlog,
GetSite,
GetUnreadRegistrationApplicationCount,
.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
ApproveRegistrationApplication,
CreateSite,
EditSite,
+ GetFederatedInstances,
GetModlog,
GetSite,
GetUnreadRegistrationApplicationCount,
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 => {