]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/deletion/delete.rs
Moving settings to Database. (#2492)
[lemmy.git] / crates / apub / src / activities / deletion / delete.rs
index d2572590ad7a4691426e05671e3c678234933416..95024c475c3c1b3ac609c03e9b6320d33bbcbb4f 100644 (file)
@@ -4,6 +4,8 @@ use crate::{
     deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
     generate_activity_id,
   },
+  check_apub_id_valid,
+  fetch_local_site_data,
   local_instance,
   objects::{community::ApubCommunity, person::ApubPerson},
   protocol::{activities::deletion::delete::Delete, IdOrNestedObject},
@@ -14,8 +16,8 @@ use anyhow::anyhow;
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
   source::{
-    comment::Comment,
-    community::Community,
+    comment::{Comment, CommentUpdateForm},
+    community::{Community, CommunityUpdateForm},
     moderator::{
       ModRemoveComment,
       ModRemoveCommentForm,
@@ -24,7 +26,7 @@ use lemmy_db_schema::{
       ModRemovePost,
       ModRemovePostForm,
     },
-    post::Post,
+    post::{Post, PostUpdateForm},
   },
   traits::Crud,
 };
@@ -55,6 +57,9 @@ impl ActivityHandler for Delete {
     context: &Data<LemmyContext>,
     request_counter: &mut i32,
   ) -> Result<(), LemmyError> {
+    let local_site_data = blocking(context.pool(), fetch_local_site_data).await??;
+    check_apub_id_valid(self.id(), &local_site_data, context.settings())
+      .map_err(LemmyError::from_message)?;
     verify_delete_activity(self, self.summary.is_some(), context, request_counter).await?;
     Ok(())
   }
@@ -150,7 +155,11 @@ pub(in crate::activities) async fn receive_remove_action(
       })
       .await??;
       let deleted_community = blocking(context.pool(), move |conn| {
-        Community::update_removed(conn, community.id, true)
+        Community::update(
+          conn,
+          community.id,
+          &CommunityUpdateForm::builder().removed(Some(true)).build(),
+        )
       })
       .await??;
 
@@ -168,7 +177,11 @@ pub(in crate::activities) async fn receive_remove_action(
       })
       .await??;
       let removed_post = blocking(context.pool(), move |conn| {
-        Post::update_removed(conn, post.id, true)
+        Post::update(
+          conn,
+          post.id,
+          &PostUpdateForm::builder().removed(Some(true)).build(),
+        )
       })
       .await??;
 
@@ -186,7 +199,11 @@ pub(in crate::activities) async fn receive_remove_action(
       })
       .await??;
       let removed_comment = blocking(context.pool(), move |conn| {
-        Comment::update_removed(conn, comment.id, true)
+        Comment::update(
+          conn,
+          comment.id,
+          &CommentUpdateForm::builder().removed(Some(true)).build(),
+        )
       })
       .await??;