1 use crate::PerformCrud;
2 use actix_web::web::Data;
3 use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, person::*};
5 fetcher::webfinger::webfinger_resolve,
6 objects::person::ApubPerson,
9 use lemmy_apub_lib::object_id::ObjectId;
10 use lemmy_db_schema::{from_opt_str_to_opt_enum, SortType};
11 use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
12 use lemmy_db_views_actor::{
13 community_moderator_view::CommunityModeratorView,
14 person_view::PersonViewSafe,
16 use lemmy_utils::{ConnectionId, LemmyError};
17 use lemmy_websocket::LemmyContext;
19 #[async_trait::async_trait(?Send)]
20 impl PerformCrud for GetPersonDetails {
21 type Response = GetPersonDetailsResponse;
23 #[tracing::instrument(skip(self, context, _websocket_id))]
26 context: &Data<LemmyContext>,
27 _websocket_id: Option<ConnectionId>,
28 ) -> Result<GetPersonDetailsResponse, LemmyError> {
29 let data: &GetPersonDetails = self;
31 get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
34 let show_nsfw = local_user_view.as_ref().map(|t| t.local_user.show_nsfw);
35 let show_bot_accounts = local_user_view
37 .map(|t| t.local_user.show_bot_accounts);
38 let show_read_posts = local_user_view
40 .map(|t| t.local_user.show_read_posts);
42 let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
44 let person_details_id = match data.person_id {
50 .unwrap_or_else(|| "admin".to_string());
52 webfinger_resolve::<ApubPerson>(&name, EndpointType::Person, context, &mut 0).await?;
54 let person = ObjectId::<ApubPerson>::new(actor_id)
55 .dereference(context, &mut 0)
58 .map_err(LemmyError::from)
59 .map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
64 let person_id = local_user_view.map(|uv| uv.person.id);
66 // You don't need to return settings for the user, since this comes back with GetSite
68 let person_view = blocking(context.pool(), move |conn| {
69 PersonViewSafe::read(conn, person_details_id)
74 let limit = data.limit;
75 let saved_only = data.saved_only;
76 let community_id = data.community_id;
78 let (posts, comments) = blocking(context.pool(), move |conn| {
79 let mut posts_query = PostQueryBuilder::create(conn)
82 .show_bot_accounts(show_bot_accounts)
83 .show_read_posts(show_read_posts)
84 .saved_only(saved_only)
85 .community_id(community_id)
86 .my_person_id(person_id)
90 let mut comments_query = CommentQueryBuilder::create(conn)
91 .my_person_id(person_id)
92 .show_bot_accounts(show_bot_accounts)
94 .saved_only(saved_only)
95 .community_id(community_id)
99 // If its saved only, you don't care what creator it was
100 // Or, if its not saved, then you only want it for that specific creator
101 if !saved_only.unwrap_or(false) {
102 posts_query = posts_query.creator_id(person_details_id);
103 comments_query = comments_query.creator_id(person_details_id);
106 let posts = posts_query.list()?;
107 let comments = comments_query.list()?;
109 Ok((posts, comments)) as Result<_, LemmyError>
113 let moderates = blocking(context.pool(), move |conn| {
114 CommunityModeratorView::for_person(conn, person_details_id)
119 Ok(GetPersonDetailsResponse {