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,
10 use lemmy_db_queries::{source::person::Person_, SortType};
11 use lemmy_db_schema::source::person::*;
12 use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
13 use lemmy_db_views_actor::{
14 community_follower_view::CommunityFollowerView,
15 community_moderator_view::CommunityModeratorView,
16 person_view::PersonViewSafe,
18 use lemmy_utils::{ApiError, ConnectionId, LemmyError};
19 use lemmy_websocket::LemmyContext;
20 use std::str::FromStr;
22 #[async_trait::async_trait(?Send)]
23 impl PerformCrud for GetPersonDetails {
24 type Response = GetPersonDetailsResponse;
28 context: &Data<LemmyContext>,
29 _websocket_id: Option<ConnectionId>,
30 ) -> Result<GetPersonDetailsResponse, LemmyError> {
31 let data: &GetPersonDetails = &self;
32 let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
34 let show_nsfw = user_show_nsfw(&local_user_view);
35 let show_bot_accounts = user_show_bot_accounts(&local_user_view);
37 let sort = SortType::from_str(&data.sort)?;
42 .unwrap_or_else(|| "admin".to_string());
43 let person_details_id = match data.person_id {
46 let person = blocking(context.pool(), move |conn| {
47 Person::find_by_name(conn, &username)
51 .map_err(|_| ApiError::err("couldnt_find_that_username_or_email"))?
56 let person_id = local_user_view.map(|uv| uv.person.id);
58 // You don't need to return settings for the user, since this comes back with GetSite
60 let person_view = blocking(context.pool(), move |conn| {
61 PersonViewSafe::read(conn, person_details_id)
66 let limit = data.limit;
67 let saved_only = data.saved_only;
68 let community_id = data.community_id;
70 let (posts, comments) = blocking(context.pool(), move |conn| {
71 let mut posts_query = PostQueryBuilder::create(conn)
74 .show_bot_accounts(show_bot_accounts)
75 .saved_only(saved_only)
76 .community_id(community_id)
77 .my_person_id(person_id)
81 let mut comments_query = CommentQueryBuilder::create(conn)
82 .my_person_id(person_id)
83 .show_bot_accounts(show_bot_accounts)
85 .saved_only(saved_only)
86 .community_id(community_id)
90 // If its saved only, you don't care what creator it was
91 // Or, if its not saved, then you only want it for that specific creator
93 posts_query = posts_query.creator_id(person_details_id);
94 comments_query = comments_query.creator_id(person_details_id);
97 let posts = posts_query.list()?;
98 let comments = comments_query.list()?;
100 Ok((posts, comments)) as Result<_, LemmyError>
104 let mut follows = vec![];
105 if let Some(pid) = person_id {
106 if pid == person_details_id {
107 follows = blocking(context.pool(), move |conn| {
108 CommunityFollowerView::for_person(conn, person_details_id)
113 let moderates = blocking(context.pool(), move |conn| {
114 CommunityModeratorView::for_person(conn, person_details_id)
119 Ok(GetPersonDetailsResponse {