1 use crate::{api::PerformApub, fetcher::resolve_actor_identifier, objects::person::ApubPerson};
2 use activitypub_federation::config::Data;
3 use lemmy_api_common::{
5 person::{GetPersonDetails, GetPersonDetailsResponse},
6 utils::{check_private_instance, is_admin, local_user_view_from_jwt_opt},
9 source::{local_site::LocalSite, person::Person},
10 utils::post_to_comment_sort_type,
12 use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery};
13 use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
14 use lemmy_utils::{error::LemmyError, ConnectionId};
16 #[async_trait::async_trait]
17 impl PerformApub for GetPersonDetails {
18 type Response = GetPersonDetailsResponse;
20 #[tracing::instrument(skip(self, context, _websocket_id))]
23 context: &Data<LemmyContext>,
24 _websocket_id: Option<ConnectionId>,
25 ) -> Result<GetPersonDetailsResponse, LemmyError> {
26 let data: &GetPersonDetails = self;
28 // Check to make sure a person name or an id is given
29 if data.username.is_none() && data.person_id.is_none() {
30 return Err(LemmyError::from_message("no_id_given"));
33 let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
34 let local_site = LocalSite::read(context.pool()).await?;
35 let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
37 check_private_instance(&local_user_view, &local_site)?;
39 let person_details_id = match data.person_id {
42 if let Some(username) = &data.username {
43 resolve_actor_identifier::<ApubPerson, Person>(username, context, &local_user_view, true)
45 .map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
48 return Err(LemmyError::from_message(
49 "couldnt_find_that_username_or_email",
55 // You don't need to return settings for the user, since this comes back with GetSite
57 let person_view = PersonView::read(context.pool(), person_details_id).await?;
61 let limit = data.limit;
62 let saved_only = data.saved_only;
63 let community_id = data.community_id;
64 let local_user = local_user_view.map(|l| l.local_user);
65 let local_user_clone = local_user.clone();
67 let posts_query = PostQuery::builder()
70 .saved_only(saved_only)
71 .local_user(local_user.as_ref())
72 .community_id(community_id)
73 .is_mod_or_admin(is_admin)
77 // If its saved only, you don't care what creator it was
78 // Or, if its not saved, then you only want it for that specific creator
79 let posts = if !saved_only.unwrap_or(false) {
81 .creator_id(Some(person_details_id))
85 posts_query.build().list()
89 let comments_query = CommentQuery::builder()
91 .local_user(local_user_clone.as_ref())
92 .sort(sort.map(post_to_comment_sort_type))
93 .saved_only(saved_only)
94 .show_deleted_and_removed(Some(false))
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 let comments = if !saved_only.unwrap_or(false) {
103 .creator_id(Some(person_details_id))
107 comments_query.build().list()
111 let moderates = CommunityModeratorView::for_person(context.pool(), person_details_id).await?;
114 Ok(GetPersonDetailsResponse {