1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 get_local_user_view_from_jwt_opt,
7 user_show_bot_accounts,
11 use lemmy_db_queries::{source::person::Person_, SortType};
12 use lemmy_db_schema::source::person::*;
13 use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
14 use lemmy_db_views_actor::{
15 community_follower_view::CommunityFollowerView,
16 community_moderator_view::CommunityModeratorView,
17 person_view::PersonViewSafe,
19 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
20 use lemmy_websocket::LemmyContext;
21 use std::str::FromStr;
23 #[async_trait::async_trait(?Send)]
24 impl PerformCrud for GetPersonDetails {
25 type Response = GetPersonDetailsResponse;
29 context: &Data<LemmyContext>,
30 _websocket_id: Option<ConnectionId>,
31 ) -> Result<GetPersonDetailsResponse, LemmyError> {
32 let data: &GetPersonDetails = &self;
33 let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
35 let show_nsfw = user_show_nsfw(&local_user_view);
36 let show_bot_accounts = user_show_bot_accounts(&local_user_view);
37 let show_read_posts = user_show_read_posts(&local_user_view);
39 let sort = SortType::from_str(&data.sort)?;
44 .unwrap_or_else(|| "admin".to_string());
45 let person_details_id = match data.person_id {
48 let person = blocking(context.pool(), move |conn| {
49 Person::find_by_name(conn, &username)
53 .map_err(|_| ApiError::err("couldnt_find_that_username_or_email"))?
58 let person_id = local_user_view.map(|uv| uv.person.id);
60 // You don't need to return settings for the user, since this comes back with GetSite
62 let person_view = blocking(context.pool(), move |conn| {
63 PersonViewSafe::read(conn, person_details_id)
68 let limit = data.limit;
69 let saved_only = data.saved_only;
70 let community_id = data.community_id;
72 let (posts, comments) = blocking(context.pool(), move |conn| {
73 let mut posts_query = PostQueryBuilder::create(conn)
76 .show_bot_accounts(show_bot_accounts)
77 .show_read_posts(show_read_posts)
78 .saved_only(saved_only)
79 .community_id(community_id)
80 .my_person_id(person_id)
84 let mut comments_query = CommentQueryBuilder::create(conn)
85 .my_person_id(person_id)
86 .show_bot_accounts(show_bot_accounts)
88 .saved_only(saved_only)
89 .community_id(community_id)
93 // If its saved only, you don't care what creator it was
94 // Or, if its not saved, then you only want it for that specific creator
96 posts_query = posts_query.creator_id(person_details_id);
97 comments_query = comments_query.creator_id(person_details_id);
100 let posts = posts_query.list()?;
101 let comments = comments_query.list()?;
103 Ok((posts, comments)) as Result<_, LemmyError>
107 let mut follows = vec![];
108 if let Some(pid) = person_id {
109 if pid == person_details_id {
110 follows = blocking(context.pool(), move |conn| {
111 CommunityFollowerView::for_person(conn, person_details_id)
116 let moderates = blocking(context.pool(), move |conn| {
117 CommunityModeratorView::for_person(conn, person_details_id)
122 Ok(GetPersonDetailsResponse {