1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 site::{GetSite, GetSiteResponse, MyUserInfo},
6 utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
8 use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language, tagline::Tagline};
9 use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
10 use lemmy_db_views_actor::structs::{
12 CommunityFollowerView,
13 CommunityModeratorView,
17 use lemmy_utils::{error::LemmyError, version, ConnectionId};
19 #[async_trait::async_trait(?Send)]
20 impl PerformCrud for GetSite {
21 type Response = GetSiteResponse;
23 #[tracing::instrument(skip(context, _websocket_id))]
26 context: &Data<LemmyContext>,
27 _websocket_id: Option<ConnectionId>,
28 ) -> Result<GetSiteResponse, LemmyError> {
29 let data: &GetSite = self;
31 let site_view = SiteView::read_local(context.pool()).await?;
33 let admins = PersonViewSafe::admins(context.pool()).await?;
35 let online = context.chat_server().get_users_online()?;
37 // Build the local user
38 let my_user = if let Some(local_user_view) = get_local_user_settings_view_from_jwt_opt(
45 let person_id = local_user_view.person.id;
46 let local_user_id = local_user_view.local_user.id;
48 let follows = CommunityFollowerView::for_person(context.pool(), person_id)
50 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
52 let person_id = local_user_view.person.id;
53 let community_blocks = CommunityBlockView::for_person(context.pool(), person_id)
55 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
57 let person_id = local_user_view.person.id;
58 let person_blocks = PersonBlockView::for_person(context.pool(), person_id)
60 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
62 let moderates = CommunityModeratorView::for_person(context.pool(), person_id)
64 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
66 let discussion_languages =
67 LocalUserDiscussionLanguageView::read_languages(context.pool(), local_user_id)
69 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
83 let federated_instances =
84 build_federated_instances(&site_view.local_site, context.pool()).await?;
86 let all_languages = Language::read_all(context.pool()).await?;
87 let discussion_languages = SiteLanguage::read_local(context.pool()).await?;
88 let taglines_res = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
89 let taglines = (!taglines_res.is_empty()).then_some(taglines_res);
95 version: version::VERSION.to_string(),