X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapi_common%2Fsrc%2Fbuild_response.rs;h=e0d3997646bb3ee1f5d9a8fa5563a904a0c649d2;hb=c8063f3267cf2b3622f1fdc69128c6b55feefbbc;hp=acb7355bdea64c81c78f7c4a161dca42dd810bc7;hpb=38c621091273822f798dfd75046b9ce724cf4bc1;p=lemmy.git diff --git a/crates/api_common/src/build_response.rs b/crates/api_common/src/build_response.rs index acb7355b..e0d39976 100644 --- a/crates/api_common/src/build_response.rs +++ b/crates/api_common/src/build_response.rs @@ -5,7 +5,7 @@ use crate::{ post::PostResponse, utils::{check_person_block, get_interface_language, is_mod_or_admin, send_email_to_user}, }; -use actix_web::web::Data; +use actix_web::web::Json; use lemmy_db_schema::{ newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId}, source::{ @@ -23,10 +23,9 @@ use lemmy_db_views_actor::structs::CommunityView; use lemmy_utils::{error::LemmyError, utils::mention::MentionData}; pub async fn build_comment_response( - context: &Data, + context: &LemmyContext, comment_id: CommentId, local_user_view: Option, - form_id: Option, recipient_ids: Vec, ) -> Result { let person_id = local_user_view.map(|l| l.person.id); @@ -34,15 +33,14 @@ pub async fn build_comment_response( Ok(CommentResponse { comment_view, recipient_ids, - form_id, }) } pub async fn build_community_response( - context: &Data, + context: &LemmyContext, local_user_view: LocalUserView, community_id: CommunityId, -) -> Result { +) -> Result, LemmyError> { let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id) .await @@ -52,23 +50,23 @@ pub async fn build_community_response( &mut context.pool(), community_id, Some(person_id), - Some(is_mod_or_admin), + is_mod_or_admin, ) .await?; let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?; - Ok(CommunityResponse { + Ok(Json(CommunityResponse { community_view, discussion_languages, - }) + })) } pub async fn build_post_response( - context: &Data, + context: &LemmyContext, community_id: CommunityId, person_id: PersonId, post_id: PostId, -) -> Result { +) -> Result, LemmyError> { let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person_id, community_id) .await .is_ok(); @@ -76,23 +74,10 @@ pub async fn build_post_response( &mut context.pool(), post_id, Some(person_id), - Some(is_mod_or_admin), + is_mod_or_admin, ) .await?; - Ok(PostResponse { post_view }) -} - -// this is a variation of build_post_response that returns post even if end-user-delted or mod-removed. -// Assumption is that before this function is ever called, the user is already confirmed to be authorized to view post. -// See GitHub Issue #3588 -pub async fn build_post_response_deleted_allowed( - context: &Data, - _community_id: CommunityId, - person_id: PersonId, - post_id: PostId, -) -> Result { - let post_view = PostView::read(&mut context.pool(), post_id, Some(person_id), Some(true)).await?; - Ok(PostResponse { post_view }) + Ok(Json(PostResponse { post_view })) } // TODO: this function is a mess and should be split up to handle email seperately