diff --git a/crates/api/src/site/leave_admin.rs b/crates/api/src/site/leave_admin.rs index 97ad7e2e5..9f94e06db 100644 --- a/crates/api/src/site/leave_admin.rs +++ b/crates/api/src/site/leave_admin.rs @@ -69,7 +69,6 @@ pub async fn leave_admin( site_view, admins, version: VERSION.to_string(), - my_user: None, all_languages, discussion_languages, oauth_providers: Some(oauth_providers), diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index 91c6151d7..c03051939 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -448,8 +448,6 @@ pub struct GetSiteResponse { pub site_view: SiteView, pub admins: Vec, pub version: String, - #[cfg_attr(feature = "full", ts(optional))] - pub my_user: Option, pub all_languages: Vec, pub discussion_languages: Vec, /// deprecated, use field `tagline` or /api/v3/tagline/list diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 47fd1f154..a840cd3c3 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -1,22 +1,16 @@ use actix_web::web::{Data, Json}; -use lemmy_api_common::{ - context::LemmyContext, - site::{GetSiteResponse, MyUserInfo}, -}; +use lemmy_api_common::{context::LemmyContext, site::GetSiteResponse}; use lemmy_db_schema::source::{ - actor_language::{LocalUserLanguage, SiteLanguage}, - community_block::CommunityBlock, - instance_block::InstanceBlock, + actor_language::SiteLanguage, language::Language, local_site_url_blocklist::LocalSiteUrlBlocklist, oauth_provider::OAuthProvider, - person_block::PersonBlock, tagline::Tagline, }; use lemmy_db_views::structs::{LocalUserView, SiteView}; -use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView, PersonView}; +use lemmy_db_views_actor::structs::PersonView; use lemmy_utils::{ - error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult}, + error::{LemmyError, LemmyResult}, CACHE_DURATION_API, VERSION, }; @@ -52,7 +46,6 @@ pub async fn get_site( site_view, admins, version: VERSION.to_string(), - my_user: None, all_languages, discussion_languages, blocked_urls, @@ -66,42 +59,6 @@ pub async fn get_site( .await .map_err(|e| anyhow::anyhow!("Failed to construct site response: {e}"))?; - // Build the local user with parallel queries and add it to site response - site_response.my_user = if let Some(ref local_user_view) = local_user_view { - let person_id = local_user_view.person.id; - let local_user_id = local_user_view.local_user.id; - let pool = &mut context.pool(); - - let ( - follows, - community_blocks, - instance_blocks, - person_blocks, - moderates, - discussion_languages, - ) = lemmy_db_schema::try_join_with_pool!(pool => ( - |pool| CommunityFollowerView::for_person(pool, person_id), - |pool| CommunityBlock::for_person(pool, person_id), - |pool| InstanceBlock::for_person(pool, person_id), - |pool| PersonBlock::for_person(pool, person_id), - |pool| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)), - |pool| LocalUserLanguage::read(pool, local_user_id) - )) - .with_lemmy_type(LemmyErrorType::SystemErrLogin)?; - - Some(MyUserInfo { - local_user_view: local_user_view.clone(), - follows, - moderates, - community_blocks, - instance_blocks, - person_blocks, - discussion_languages, - }) - } else { - None - }; - // filter oauth_providers for public access if !local_user_view .map(|l| l.local_user.admin) diff --git a/crates/api_crud/src/user/mod.rs b/crates/api_crud/src/user/mod.rs index da1aa3ace..e6e88e6cd 100644 --- a/crates/api_crud/src/user/mod.rs +++ b/crates/api_crud/src/user/mod.rs @@ -1,2 +1,3 @@ pub mod create; pub mod delete; +pub mod my_user; diff --git a/crates/api_crud/src/user/my_user.rs b/crates/api_crud/src/user/my_user.rs new file mode 100644 index 000000000..805c9dabb --- /dev/null +++ b/crates/api_crud/src/user/my_user.rs @@ -0,0 +1,43 @@ +use actix_web::web::{Data, Json}; +use lemmy_api_common::{context::LemmyContext, site::MyUserInfo}; +use lemmy_db_schema::source::{ + actor_language::LocalUserLanguage, + community_block::CommunityBlock, + instance_block::InstanceBlock, + person_block::PersonBlock, +}; +use lemmy_db_views::structs::LocalUserView; +use lemmy_db_views_actor::structs::{CommunityFollowerView, CommunityModeratorView}; +use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult}; + +#[tracing::instrument(skip(context))] +pub async fn get_my_user( + local_user_view: LocalUserView, + context: Data, +) -> LemmyResult> { + // Build the local user with parallel queries and add it to site response + let person_id = local_user_view.person.id; + let local_user_id = local_user_view.local_user.id; + let pool = &mut context.pool(); + + let (follows, community_blocks, instance_blocks, person_blocks, moderates, discussion_languages) = + lemmy_db_schema::try_join_with_pool!(pool => ( + |pool| CommunityFollowerView::for_person(pool, person_id), + |pool| CommunityBlock::for_person(pool, person_id), + |pool| InstanceBlock::for_person(pool, person_id), + |pool| PersonBlock::for_person(pool, person_id), + |pool| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)), + |pool| LocalUserLanguage::read(pool, local_user_id) + )) + .with_lemmy_type(LemmyErrorType::SystemErrLogin)?; + + Ok(Json(MyUserInfo { + local_user_view: local_user_view.clone(), + follows, + moderates, + community_blocks, + instance_blocks, + person_blocks, + discussion_languages, + })) +} diff --git a/src/api_routes_http.rs b/src/api_routes_http.rs index 795ae3a1b..42a2cf0ab 100644 --- a/src/api_routes_http.rs +++ b/src/api_routes_http.rs @@ -145,6 +145,7 @@ use lemmy_api_crud::{ user::{ create::{authenticate_with_oauth, register}, delete::delete_account, + my_user::get_my_user, }, }; use lemmy_apub::api::{ @@ -304,6 +305,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) { ) .service( web::scope("/account") + .route("/my_user", web::get().to(get_my_user)) .route("/list_media", web::get().to(list_media)) .route("/mention", web::get().to(list_mentions)) .route("/replies", web::get().to(list_replies))