1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 site::{GetSite, GetSiteResponse, MyUserInfo},
5 utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
6 websocket::messages::GetUsersOnline,
9 use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language, tagline::Tagline};
10 use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
11 use lemmy_db_views_actor::structs::{
13 CommunityFollowerView,
14 CommunityModeratorView,
18 use lemmy_utils::{error::LemmyError, version, ConnectionId};
20 #[async_trait::async_trait(?Send)]
21 impl PerformCrud for GetSite {
22 type Response = GetSiteResponse;
24 #[tracing::instrument(skip(context, _websocket_id))]
27 context: &Data<LemmyContext>,
28 _websocket_id: Option<ConnectionId>,
29 ) -> Result<GetSiteResponse, LemmyError> {
30 let data: &GetSite = self;
32 let site_view = SiteView::read_local(context.pool()).await?;
34 let admins = PersonViewSafe::admins(context.pool()).await?;
42 // Build the local user
43 let my_user = if let Some(local_user_view) = get_local_user_settings_view_from_jwt_opt(
50 let person_id = local_user_view.person.id;
51 let local_user_id = local_user_view.local_user.id;
53 let follows = CommunityFollowerView::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 community_blocks = CommunityBlockView::for_person(context.pool(), person_id)
60 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
62 let person_id = local_user_view.person.id;
63 let person_blocks = PersonBlockView::for_person(context.pool(), person_id)
65 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
67 let moderates = CommunityModeratorView::for_person(context.pool(), person_id)
69 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
71 let discussion_languages =
72 LocalUserDiscussionLanguageView::read_languages(context.pool(), local_user_id)
74 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
88 let federated_instances =
89 build_federated_instances(&site_view.local_site, context.pool()).await?;
91 let all_languages = Language::read_all(context.pool()).await?;
92 let discussion_languages = SiteLanguage::read_local(context.pool()).await?;
93 let taglines_res = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
94 let taglines = (!taglines_res.is_empty()).then_some(taglines_res);
100 version: version::VERSION.to_string(),
104 discussion_languages,