]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/deletion/undo_delete.rs
Moving settings to Database. (#2492)
[lemmy.git] / crates / apub / src / activities / deletion / undo_delete.rs
index c43e4d87194c47a05c6b61663acf2be4fa81942f..f73c780c2de38670340d54a61f00fac5fe860786 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, undo_delete::UndoDelete},
@@ -13,8 +15,8 @@ use activitystreams_kinds::activity::UndoType;
 use lemmy_api_common::utils::blocking;
 use lemmy_db_schema::{
   source::{
-    comment::Comment,
-    community::Community,
+    comment::{Comment, CommentUpdateForm},
+    community::{Community, CommunityUpdateForm},
     moderator::{
       ModRemoveComment,
       ModRemoveCommentForm,
@@ -23,7 +25,7 @@ use lemmy_db_schema::{
       ModRemovePost,
       ModRemovePostForm,
     },
-    post::Post,
+    post::{Post, PostUpdateForm},
   },
   traits::Crud,
 };
@@ -54,6 +56,9 @@ impl ActivityHandler for UndoDelete {
     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)?;
     self.object.verify(context, request_counter).await?;
     verify_delete_activity(
       &self.object,
@@ -148,7 +153,11 @@ impl UndoDelete {
         })
         .await??;
         let deleted_community = blocking(context.pool(), move |conn| {
-          Community::update_removed(conn, community.id, false)
+          Community::update(
+            conn,
+            community.id,
+            &CommunityUpdateForm::builder().removed(Some(false)).build(),
+          )
         })
         .await??;
         send_community_ws_message(deleted_community.id, EditCommunity, None, None, context).await?;
@@ -165,7 +174,11 @@ impl UndoDelete {
         })
         .await??;
         let removed_post = blocking(context.pool(), move |conn| {
-          Post::update_removed(conn, post.id, false)
+          Post::update(
+            conn,
+            post.id,
+            &PostUpdateForm::builder().removed(Some(false)).build(),
+          )
         })
         .await??;
         send_post_ws_message(removed_post.id, EditPost, None, None, context).await?;
@@ -182,7 +195,11 @@ impl UndoDelete {
         })
         .await??;
         let removed_comment = blocking(context.pool(), move |conn| {
-          Comment::update_removed(conn, comment.id, false)
+          Comment::update(
+            conn,
+            comment.id,
+            &CommentUpdateForm::builder().removed(Some(false)).build(),
+          )
         })
         .await??;
         send_comment_ws_message_simple(removed_comment.id, EditComment, context).await?;