mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-24 11:51:32 +00:00
move my_user to separate endpoint
This commit is contained in:
parent
0c580887d7
commit
88b0aba101
6 changed files with 50 additions and 50 deletions
|
@ -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),
|
||||
|
|
|
@ -448,8 +448,6 @@ pub struct GetSiteResponse {
|
|||
pub site_view: SiteView,
|
||||
pub admins: Vec<PersonView>,
|
||||
pub version: String,
|
||||
#[cfg_attr(feature = "full", ts(optional))]
|
||||
pub my_user: Option<MyUserInfo>,
|
||||
pub all_languages: Vec<Language>,
|
||||
pub discussion_languages: Vec<LanguageId>,
|
||||
/// deprecated, use field `tagline` or /api/v3/tagline/list
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod my_user;
|
||||
|
|
43
crates/api_crud/src/user/my_user.rs
Normal file
43
crates/api_crud/src/user/my_user.rs
Normal file
|
@ -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<LemmyContext>,
|
||||
) -> LemmyResult<Json<MyUserInfo>> {
|
||||
// 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,
|
||||
}))
|
||||
}
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue