+ // 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,
check_community_ban(
local_user_view.person.id,
orig_comment.community.id,
let post_id = data.post_id;
let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
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,
check_community_ban(
local_user_view.person.id,
orig_post.community_id,
use crate::{
activities::{
community::{announce::GetCommunity, send_to_community},
use crate::{
activities::{
community::{announce::GetCommunity, send_to_community},
- deletion::{
- receive_delete_action,
- verify_delete_activity,
- DeletableObjects,
- WebsocketMessages,
- },
+ deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
generate_activity_id,
verify_activity,
verify_is_public,
generate_activity_id,
verify_activity,
verify_is_public,
};
receive_remove_action(&self.actor, &self.object, reason, context, request_counter).await
} else {
};
receive_remove_action(&self.actor, &self.object, reason, context, request_counter).await
} else {
- receive_delete_action(
- &self.object,
- &self.actor,
- WebsocketMessages {
- community: UserOperationCrud::DeleteCommunity,
- post: UserOperationCrud::DeletePost,
- comment: UserOperationCrud::DeleteComment,
- },
- true,
- context,
- request_counter,
- )
- .await
+ receive_delete_action(&self.object, &self.actor, true, context, request_counter).await
-struct WebsocketMessages {
- community: UserOperationCrud,
- post: UserOperationCrud,
- comment: UserOperationCrud,
-}
-
/// Write deletion or restoring of an object to the database, and send websocket message.
/// TODO: we should do something similar for receive_remove_action(), but its much more complicated
/// because of the mod log
async fn receive_delete_action(
object: &Url,
actor: &ObjectId<ApubPerson>,
/// Write deletion or restoring of an object to the database, and send websocket message.
/// TODO: we should do something similar for receive_remove_action(), but its much more complicated
/// because of the mod log
async fn receive_delete_action(
object: &Url,
actor: &ObjectId<ApubPerson>,
- ws_messages: WebsocketMessages,
deleted: bool,
context: &LemmyContext,
request_counter: &mut i32,
deleted: bool,
context: &LemmyContext,
request_counter: &mut i32,
Community::update_deleted(conn, community.id, deleted)
})
.await??;
Community::update_deleted(conn, community.id, deleted)
})
.await??;
- send_community_ws_message(community.id, ws_messages.community, None, None, context).await?;
+ send_community_ws_message(
+ community.id,
+ UserOperationCrud::DeleteCommunity,
+ None,
+ None,
+ context,
+ )
+ .await?;
}
DeletableObjects::Post(post) => {
}
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,
+ UserOperationCrud::DeletePost,
+ None,
+ None,
+ context,
+ )
+ .await?;
+ }
}
DeletableObjects::Comment(comment) => {
}
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,
+ UserOperationCrud::DeleteComment,
+ context,
+ )
+ .await?;
+ }
use crate::{
activities::{
community::{announce::GetCommunity, send_to_community},
use crate::{
activities::{
community::{announce::GetCommunity, send_to_community},
- deletion::{
- receive_delete_action,
- verify_delete_activity,
- DeletableObjects,
- WebsocketMessages,
- },
+ deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
generate_activity_id,
verify_activity,
verify_is_public,
generate_activity_id,
verify_activity,
verify_is_public,
receive_delete_action(
&self.object.object,
&self.actor,
receive_delete_action(
&self.object.object,
&self.actor,
- WebsocketMessages {
- community: UserOperationCrud::EditCommunity,
- post: UserOperationCrud::EditPost,
- comment: UserOperationCrud::EditComment,
- },
false,
context,
request_counter,
false,
context,
request_counter,
}
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
}
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??;
+ }
}
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
}
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??;
+ }