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::{
9 actor_language::{LocalUserLanguage, SiteLanguage},
13 use lemmy_db_views::structs::{CustomEmojiView, SiteView};
14 use lemmy_db_views_actor::structs::{
16 CommunityFollowerView,
17 CommunityModeratorView,
21 use lemmy_utils::{error::LemmyError, version, ConnectionId};
23 #[async_trait::async_trait(?Send)]
24 impl PerformCrud for GetSite {
25 type Response = GetSiteResponse;
27 #[tracing::instrument(skip(context, _websocket_id))]
30 context: &Data<LemmyContext>,
31 _websocket_id: Option<ConnectionId>,
32 ) -> Result<GetSiteResponse, LemmyError> {
33 let data: &GetSite = self;
35 let site_view = SiteView::read_local(context.pool()).await?;
37 let admins = PersonView::admins(context.pool()).await?;
39 let online = context.chat_server().get_users_online()?;
41 // Build the local user
42 let my_user = if let Some(local_user_view) = get_local_user_settings_view_from_jwt_opt(
49 let person_id = local_user_view.person.id;
50 let local_user_id = local_user_view.local_user.id;
52 let follows = CommunityFollowerView::for_person(context.pool(), person_id)
54 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
56 let person_id = local_user_view.person.id;
57 let community_blocks = CommunityBlockView::for_person(context.pool(), person_id)
59 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
61 let person_id = local_user_view.person.id;
62 let person_blocks = PersonBlockView::for_person(context.pool(), person_id)
64 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
66 let moderates = CommunityModeratorView::for_person(context.pool(), person_id)
68 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
70 let discussion_languages = LocalUserLanguage::read(context.pool(), local_user_id)
72 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
86 let federated_instances =
87 build_federated_instances(&site_view.local_site, context.pool()).await?;
89 let all_languages = Language::read_all(context.pool()).await?;
90 let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
91 let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
92 let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
98 version: version::VERSION.to_string(),
102 discussion_languages,