mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 22:31:20 +00:00
Refactoring delete apub.
This commit is contained in:
parent
2c94fa880c
commit
f75e1e9f60
6 changed files with 36 additions and 45 deletions
|
@ -33,12 +33,7 @@ use lemmy_websocket::{
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::{
|
activities::{
|
||||||
community::{announce::GetCommunity, send_to_community},
|
community::{announce::GetCommunity, send_to_community},
|
||||||
deletion::{
|
deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
|
||||||
receive_delete_action,
|
|
||||||
verify_delete_activity,
|
|
||||||
DeletableObjects,
|
|
||||||
WebsocketMessages,
|
|
||||||
},
|
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
verify_is_public,
|
verify_is_public,
|
||||||
|
@ -87,19 +82,7 @@ impl ActivityHandler for Delete {
|
||||||
};
|
};
|
||||||
receive_remove_action(&self.actor, &self.object, reason, context, request_counter).await
|
receive_remove_action(&self.actor, &self.object, reason, context, request_counter).await
|
||||||
} else {
|
} else {
|
||||||
receive_delete_action(
|
receive_delete_action(&self.object, &self.actor, true, context, request_counter).await
|
||||||
&self.object,
|
|
||||||
&self.actor,
|
|
||||||
WebsocketMessages {
|
|
||||||
community: UserOperationCrud::DeleteCommunity,
|
|
||||||
post: UserOperationCrud::DeletePost,
|
|
||||||
comment: UserOperationCrud::DeleteComment,
|
|
||||||
},
|
|
||||||
true,
|
|
||||||
context,
|
|
||||||
request_counter,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,19 +143,12 @@ async fn verify_delete_activity_post_or_comment(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WebsocketMessages {
|
|
||||||
community: UserOperationCrud,
|
|
||||||
post: UserOperationCrud,
|
|
||||||
comment: UserOperationCrud,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write deletion or restoring of an object to the database, and send websocket message.
|
/// 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
|
/// TODO: we should do something similar for receive_remove_action(), but its much more complicated
|
||||||
/// because of the mod log
|
/// because of the mod log
|
||||||
async fn receive_delete_action(
|
async fn receive_delete_action(
|
||||||
object: &Url,
|
object: &Url,
|
||||||
actor: &ObjectId<ApubPerson>,
|
actor: &ObjectId<ApubPerson>,
|
||||||
ws_messages: WebsocketMessages,
|
|
||||||
deleted: bool,
|
deleted: bool,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
|
@ -172,7 +165,14 @@ async fn receive_delete_action(
|
||||||
Community::update_deleted(conn, community.id, deleted)
|
Community::update_deleted(conn, community.id, deleted)
|
||||||
})
|
})
|
||||||
.await??;
|
.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) => {
|
||||||
if deleted != post.deleted {
|
if deleted != post.deleted {
|
||||||
|
@ -180,7 +180,14 @@ async fn receive_delete_action(
|
||||||
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,
|
||||||
|
UserOperationCrud::DeletePost,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DeletableObjects::Comment(comment) => {
|
DeletableObjects::Comment(comment) => {
|
||||||
|
@ -189,7 +196,12 @@ async fn receive_delete_action(
|
||||||
Comment::update_deleted(conn, comment.id, deleted)
|
Comment::update_deleted(conn, comment.id, deleted)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
send_comment_ws_message_simple(deleted_comment.id, ws_messages.comment, context).await?;
|
send_comment_ws_message_simple(
|
||||||
|
deleted_comment.id,
|
||||||
|
UserOperationCrud::DeleteComment,
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,7 @@ use lemmy_websocket::{
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::{
|
activities::{
|
||||||
community::{announce::GetCommunity, send_to_community},
|
community::{announce::GetCommunity, send_to_community},
|
||||||
deletion::{
|
deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
|
||||||
receive_delete_action,
|
|
||||||
verify_delete_activity,
|
|
||||||
DeletableObjects,
|
|
||||||
WebsocketMessages,
|
|
||||||
},
|
|
||||||
generate_activity_id,
|
generate_activity_id,
|
||||||
verify_activity,
|
verify_activity,
|
||||||
verify_is_public,
|
verify_is_public,
|
||||||
|
@ -69,11 +64,6 @@ impl ActivityHandler for UndoDelete {
|
||||||
receive_delete_action(
|
receive_delete_action(
|
||||||
&self.object.object,
|
&self.object.object,
|
||||||
&self.actor,
|
&self.actor,
|
||||||
WebsocketMessages {
|
|
||||||
community: UserOperationCrud::EditCommunity,
|
|
||||||
post: UserOperationCrud::EditPost,
|
|
||||||
comment: UserOperationCrud::EditComment,
|
|
||||||
},
|
|
||||||
false,
|
false,
|
||||||
context,
|
context,
|
||||||
request_counter,
|
request_counter,
|
||||||
|
|
|
@ -24,7 +24,7 @@ use lemmy_utils::{
|
||||||
utils::{convert_datetime, remove_slurs},
|
utils::{convert_datetime, remove_slurs},
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::{send::send_comment_ws_message_simple, LemmyContext, UserOperationCrud};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::verify_person_in_community,
|
activities::verify_person_in_community,
|
||||||
|
@ -82,10 +82,12 @@ impl ApubObject for ApubComment {
|
||||||
|
|
||||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||||
if !self.deleted {
|
if !self.deleted {
|
||||||
|
let id = self.id;
|
||||||
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??;
|
||||||
|
send_comment_ws_message_simple(id, UserOperationCrud::DeleteComment, context).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ use lemmy_utils::{
|
||||||
utils::{convert_datetime, markdown_to_html},
|
utils::{convert_datetime, markdown_to_html},
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ApubCommunity(Community);
|
pub struct ApubCommunity(Community);
|
||||||
|
@ -73,10 +73,12 @@ impl ApubObject for ApubCommunity {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||||
|
let id = self.id;
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Community::update_deleted(conn, self.id, true)
|
Community::update_deleted(conn, id, true)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
send_community_ws_message(id, UserOperationCrud::DeleteCommunity, None, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ use lemmy_utils::{
|
||||||
utils::{convert_datetime, markdown_to_html, remove_slurs},
|
utils::{convert_datetime, markdown_to_html, remove_slurs},
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -77,10 +77,12 @@ impl ApubObject for ApubPost {
|
||||||
|
|
||||||
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
|
||||||
if !self.deleted {
|
if !self.deleted {
|
||||||
|
let id = self.id;
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Post::update_deleted(conn, self.id, true)
|
Post::update_deleted(conn, id, true)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
send_post_ws_message(id, UserOperationCrud::DeletePost, None, None, context).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue