1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 site::{GetSite, GetSiteResponse, MyUserInfo},
6 utils::get_local_user_settings_view_from_jwt_opt,
7 websocket::handlers::online_users::GetUsersOnline,
9 use lemmy_db_schema::source::{
10 actor_language::{LocalUserLanguage, SiteLanguage},
14 use lemmy_db_views::structs::{CustomEmojiView, SiteView};
15 use lemmy_db_views_actor::structs::{
17 CommunityFollowerView,
18 CommunityModeratorView,
22 use lemmy_utils::{error::LemmyError, version, ConnectionId};
24 #[async_trait::async_trait(?Send)]
25 impl PerformCrud for GetSite {
26 type Response = GetSiteResponse;
28 #[tracing::instrument(skip(context, _websocket_id))]
31 context: &Data<LemmyContext>,
32 _websocket_id: Option<ConnectionId>,
33 ) -> Result<GetSiteResponse, LemmyError> {
34 let data: &GetSite = self;
36 let site_view = SiteView::read_local(context.pool()).await?;
38 let admins = PersonView::admins(context.pool()).await?;
40 let online = context.chat_server().send(GetUsersOnline).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 = LocalUserLanguage::read(context.pool(), local_user_id)
73 .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
87 let all_languages = Language::read_all(context.pool()).await?;
88 let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
89 let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
90 let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
96 version: version::VERSION.to_string(),