]> Untitled Git - lemmy.git/blobdiff - crates/api_crud/src/comment/remove.rs
Automatically resolve report when post/comment is removed (#3850)
[lemmy.git] / crates / api_crud / src / comment / remove.rs
index b2071298656f6074f07223d6c0c68c57337ab626..c18a8c5b7486f24ce217435cbf8cc732781c5941 100644 (file)
@@ -10,10 +10,11 @@ use lemmy_api_common::{
 use lemmy_db_schema::{
   source::{
     comment::{Comment, CommentUpdateForm},
+    comment_report::CommentReport,
     moderator::{ModRemoveComment, ModRemoveCommentForm},
     post::Post,
   },
-  traits::Crud,
+  traits::{Crud, Reportable},
 };
 use lemmy_db_views::structs::CommentView;
 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
@@ -48,11 +49,17 @@ pub async fn remove_comment(
   let updated_comment = Comment::update(
     &mut context.pool(),
     comment_id,
-    &CommentUpdateForm::builder().removed(Some(removed)).build(),
+    &CommentUpdateForm {
+      removed: Some(removed),
+      ..Default::default()
+    },
   )
   .await
   .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
 
+  CommentReport::resolve_all_for_object(&mut context.pool(), comment_id, local_user_view.person.id)
+    .await?;
+
   // Mod tables
   let form = ModRemoveCommentForm {
     mod_person_id: local_user_view.person.id,
@@ -91,7 +98,6 @@ pub async fn remove_comment(
       &context,
       updated_comment_id,
       Some(local_user_view),
-      None,
       recipient_ids,
     )
     .await?,