};
use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery};
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
-use lemmy_utils::error::LemmyError;
+use lemmy_utils::error::{LemmyError, LemmyErrorExt2, LemmyErrorType};
#[tracing::instrument(skip(context))]
pub async fn read_person(
) -> Result<Json<GetPersonDetailsResponse>, LemmyError> {
// Check to make sure a person name or an id is given
if data.username.is_none() && data.person_id.is_none() {
- return Err(LemmyError::from_message("no_id_given"));
+ return Err(LemmyErrorType::NoIdGiven)?;
}
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
check_private_instance(&local_user_view, &local_site)?;
if let Some(username) = &data.username {
resolve_actor_identifier::<ApubPerson, Person>(username, &context, &local_user_view, true)
.await
- .map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
+ .with_lemmy_type(LemmyErrorType::CouldntFindPerson)?
.id
} else {
- return Err(LemmyError::from_message(
- "couldnt_find_that_username_or_email",
- ));
+ return Err(LemmyErrorType::CouldntFindPerson)?;
}
}
};
// You don't need to return settings for the user, since this comes back with GetSite
// `my_user`
- let person_view = PersonView::read(context.pool(), person_details_id).await?;
+ let person_view = PersonView::read(&mut context.pool(), person_details_id).await?;
let sort = data.sort;
let page = data.page;
let local_user = local_user_view.map(|l| l.local_user);
let local_user_clone = local_user.clone();
- let posts_query = PostQuery::builder()
- .pool(context.pool())
+ let posts = PostQuery::builder()
+ .pool(&mut context.pool())
.sort(sort)
.saved_only(saved_only)
.local_user(local_user.as_ref())
.community_id(community_id)
.is_mod_or_admin(is_admin)
.page(page)
- .limit(limit);
-
- // If its saved only, you don't care what creator it was
- // Or, if its not saved, then you only want it for that specific creator
- let posts = if !saved_only.unwrap_or(false) {
- posts_query
- .creator_id(Some(person_details_id))
- .build()
- .list()
- } else {
- posts_query.build().list()
- }
- .await?;
+ .limit(limit)
+ .creator_id(
+ // If its saved only, you don't care what creator it was
+ // Or, if its not saved, then you only want it for that specific creator
+ if !saved_only.unwrap_or(false) {
+ Some(person_details_id)
+ } else {
+ None
+ },
+ )
+ .build()
+ .list()
+ .await?;
- let comments_query = CommentQuery::builder()
- .pool(context.pool())
+ let comments = CommentQuery::builder()
+ .pool(&mut context.pool())
.local_user(local_user_clone.as_ref())
.sort(sort.map(post_to_comment_sort_type))
.saved_only(saved_only)
.show_deleted_and_removed(Some(false))
.community_id(community_id)
.page(page)
- .limit(limit);
-
- // If its saved only, you don't care what creator it was
- // Or, if its not saved, then you only want it for that specific creator
- let comments = if !saved_only.unwrap_or(false) {
- comments_query
- .creator_id(Some(person_details_id))
- .build()
- .list()
- } else {
- comments_query.build().list()
- }
- .await?;
+ .limit(limit)
+ .creator_id(
+ // If its saved only, you don't care what creator it was
+ // Or, if its not saved, then you only want it for that specific creator
+ if !saved_only.unwrap_or(false) {
+ Some(person_details_id)
+ } else {
+ None
+ },
+ )
+ .build()
+ .list()
+ .await?;
- let moderates = CommunityModeratorView::for_person(context.pool(), person_details_id).await?;
+ let moderates =
+ CommunityModeratorView::for_person(&mut context.pool(), person_details_id).await?;
// Return the jwt
Ok(Json(GetPersonDetailsResponse {