]> Untitled Git - lemmy.git/blobdiff - crates/api_common/src/build_response.rs
Replace Option<bool> with bool for PostQuery and CommentQuery (#3819) (#3857)
[lemmy.git] / crates / api_common / src / build_response.rs
index acb7355bdea64c81c78f7c4a161dca42dd810bc7..e0d3997646bb3ee1f5d9a8fa5563a904a0c649d2 100644 (file)
@@ -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<LemmyContext>,
+  context: &LemmyContext,
   comment_id: CommentId,
   local_user_view: Option<LocalUserView>,
-  form_id: Option<String>,
   recipient_ids: Vec<LocalUserId>,
 ) -> Result<CommentResponse, LemmyError> {
   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<LemmyContext>,
+  context: &LemmyContext,
   local_user_view: LocalUserView,
   community_id: CommunityId,
-) -> Result<CommunityResponse, LemmyError> {
+) -> Result<Json<CommunityResponse>, 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<LemmyContext>,
+  context: &LemmyContext,
   community_id: CommunityId,
   person_id: PersonId,
   post_id: PostId,
-) -> Result<PostResponse, LemmyError> {
+) -> Result<Json<PostResponse>, 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<LemmyContext>,
-  _community_id: CommunityId,
-  person_id: PersonId,
-  post_id: PostId,
-) -> Result<PostResponse, LemmyError> {
-  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