mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 06:41:18 +00:00
Check if post or comment are deleted first. Fixes #1864
This commit is contained in:
parent
1bec551945
commit
2c94fa880c
5 changed files with 36 additions and 18 deletions
|
@ -44,6 +44,11 @@ impl PerformCrud for DeleteComment {
|
||||||
})
|
})
|
||||||
.await??;
|
.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(
|
check_community_ban(
|
||||||
local_user_view.person.id,
|
local_user_view.person.id,
|
||||||
orig_comment.community.id,
|
orig_comment.community.id,
|
||||||
|
|
|
@ -36,6 +36,11 @@ impl PerformCrud for DeletePost {
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
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(
|
check_community_ban(
|
||||||
local_user_view.person.id,
|
local_user_view.person.id,
|
||||||
orig_post.community_id,
|
orig_post.community_id,
|
||||||
|
|
|
@ -175,13 +175,16 @@ async fn receive_delete_action(
|
||||||
send_community_ws_message(community.id, ws_messages.community, None, None, context).await?;
|
send_community_ws_message(community.id, ws_messages.community, None, None, context).await?;
|
||||||
}
|
}
|
||||||
DeletableObjects::Post(post) => {
|
DeletableObjects::Post(post) => {
|
||||||
|
if deleted != post.deleted {
|
||||||
let deleted_post = blocking(context.pool(), move |conn| {
|
let deleted_post = blocking(context.pool(), move |conn| {
|
||||||
Post::update_deleted(conn, post.id, deleted)
|
Post::update_deleted(conn, post.id, deleted)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
send_post_ws_message(deleted_post.id, ws_messages.post, None, None, context).await?;
|
send_post_ws_message(deleted_post.id, ws_messages.post, None, None, context).await?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
DeletableObjects::Comment(comment) => {
|
DeletableObjects::Comment(comment) => {
|
||||||
|
if deleted != comment.deleted {
|
||||||
let deleted_comment = blocking(context.pool(), move |conn| {
|
let deleted_comment = blocking(context.pool(), move |conn| {
|
||||||
Comment::update_deleted(conn, comment.id, deleted)
|
Comment::update_deleted(conn, comment.id, deleted)
|
||||||
})
|
})
|
||||||
|
@ -189,5 +192,6 @@ async fn receive_delete_action(
|
||||||
send_comment_ws_message_simple(deleted_comment.id, ws_messages.comment, context).await?;
|
send_comment_ws_message_simple(deleted_comment.id, ws_messages.comment, context).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,10 +81,12 @@ impl ApubObject for ApubComment {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||||
|
if !self.deleted {
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Comment::update_deleted(conn, self.id, true)
|
Comment::update_deleted(conn, self.id, true)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,10 +76,12 @@ impl ApubObject for ApubPost {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||||
|
if !self.deleted {
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Post::update_deleted(conn, self.id, true)
|
Post::update_deleted(conn, self.id, true)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue