diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index 19851f0c0..f55119f72 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -44,6 +44,11 @@ impl PerformCrud for DeleteComment { }) .await??; + // Dont delete it if its already been deleted. + if orig_comment.comment.deleted == data.deleted { + return Err(ApiError::err_plain("couldnt_update_comment").into()); + } + check_community_ban( local_user_view.person.id, orig_comment.community.id, diff --git a/crates/api_crud/src/post/delete.rs b/crates/api_crud/src/post/delete.rs index a701e8355..af6999348 100644 --- a/crates/api_crud/src/post/delete.rs +++ b/crates/api_crud/src/post/delete.rs @@ -36,6 +36,11 @@ impl PerformCrud for DeletePost { let post_id = data.post_id; let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??; + // Dont delete it if its already been deleted. + if orig_post.deleted == data.deleted { + return Err(ApiError::err_plain("couldnt_update_post").into()); + } + check_community_ban( local_user_view.person.id, orig_post.community_id, diff --git a/crates/apub/src/activities/deletion/mod.rs b/crates/apub/src/activities/deletion/mod.rs index b9c11291f..99407fbda 100644 --- a/crates/apub/src/activities/deletion/mod.rs +++ b/crates/apub/src/activities/deletion/mod.rs @@ -175,18 +175,22 @@ async fn receive_delete_action( send_community_ws_message(community.id, ws_messages.community, None, None, context).await?; } DeletableObjects::Post(post) => { - let deleted_post = blocking(context.pool(), move |conn| { - Post::update_deleted(conn, post.id, deleted) - }) - .await??; - send_post_ws_message(deleted_post.id, ws_messages.post, None, None, context).await?; + if deleted != post.deleted { + let deleted_post = blocking(context.pool(), move |conn| { + Post::update_deleted(conn, post.id, deleted) + }) + .await??; + send_post_ws_message(deleted_post.id, ws_messages.post, None, None, context).await?; + } } DeletableObjects::Comment(comment) => { - let deleted_comment = blocking(context.pool(), move |conn| { - Comment::update_deleted(conn, comment.id, deleted) - }) - .await??; - send_comment_ws_message_simple(deleted_comment.id, ws_messages.comment, context).await?; + if deleted != comment.deleted { + let deleted_comment = blocking(context.pool(), move |conn| { + Comment::update_deleted(conn, comment.id, deleted) + }) + .await??; + send_comment_ws_message_simple(deleted_comment.id, ws_messages.comment, context).await?; + } } } Ok(()) diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index e5ffb7ca2..08a55bf9c 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -81,10 +81,12 @@ impl ApubObject for ApubComment { } async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> { - blocking(context.pool(), move |conn| { - Comment::update_deleted(conn, self.id, true) - }) - .await??; + if !self.deleted { + blocking(context.pool(), move |conn| { + Comment::update_deleted(conn, self.id, true) + }) + .await??; + } Ok(()) } diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index c19c62779..b835f812e 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -76,10 +76,12 @@ impl ApubObject for ApubPost { } async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> { - blocking(context.pool(), move |conn| { - Post::update_deleted(conn, self.id, true) - }) - .await??; + if !self.deleted { + blocking(context.pool(), move |conn| { + Post::update_deleted(conn, self.id, true) + }) + .await??; + } Ok(()) }