3 comment::send_websocket_message as send_comment_message,
4 community::send_websocket_message as send_community_message,
5 deletion::delete::DeletePostCommentOrCommunity,
6 post::send_websocket_message as send_post_message,
9 verify_person_in_community,
12 community::get_or_fetch_and_upsert_community,
13 objects::get_or_fetch_and_insert_post_or_comment,
14 person::get_or_fetch_and_upsert_person,
19 use activitystreams::activity::kind::UndoType;
20 use lemmy_api_common::blocking;
21 use lemmy_apub_lib::{values::PublicUrl, verify_urls_match, ActivityCommonFields, ActivityHandler};
22 use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
23 use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
24 use lemmy_utils::LemmyError;
25 use lemmy_websocket::{LemmyContext, UserOperationCrud};
28 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
29 #[serde(rename_all = "camelCase")]
30 pub struct UndoDeletePostCommentOrCommunity {
32 object: DeletePostCommentOrCommunity,
34 #[serde(rename = "type")]
37 common: ActivityCommonFields,
40 #[async_trait::async_trait(?Send)]
41 impl ActivityHandler for UndoDeletePostCommentOrCommunity {
44 context: &LemmyContext,
45 request_counter: &mut i32,
46 ) -> Result<(), LemmyError> {
47 verify_activity(self.common())?;
48 self.object.verify(context, request_counter).await?;
49 let object_community =
50 get_or_fetch_and_upsert_community(&self.object.object, context, request_counter).await;
51 // restoring a community
52 if object_community.is_ok() {
53 verify_mod_action(&self.common.actor, self.object.object.clone(), context).await?;
55 // restoring a post or comment
57 verify_person_in_community(&self.common().actor, &self.cc[0], context, request_counter)
59 verify_urls_match(&self.common.actor, &self.object.common().actor)?;
66 context: &LemmyContext,
67 request_counter: &mut i32,
68 ) -> Result<(), LemmyError> {
69 let object_community =
70 get_or_fetch_and_upsert_community(&self.object.object, context, request_counter).await;
71 // restoring a community
72 if let Ok(community) = object_community {
74 // repeat these checks just to be sure
75 verify_person_in_community(&self.common().actor, &self.cc[0], context, request_counter)
77 verify_mod_action(&self.common.actor, self.object.object.clone(), context).await?;
79 get_or_fetch_and_upsert_person(&self.common.actor, context, request_counter).await?;
80 community.send_undo_delete(mod_, context).await?;
82 let deleted_community = blocking(context.pool(), move |conn| {
83 Community::update_deleted(conn, community.id, false)
87 send_community_message(
89 UserOperationCrud::EditCommunity,
94 // restoring a post or comment
96 match get_or_fetch_and_insert_post_or_comment(&self.object.object, context, request_counter)
99 PostOrComment::Post(post) => {
100 let deleted_post = blocking(context.pool(), move |conn| {
101 Post::update_deleted(conn, post.id, false)
104 send_post_message(deleted_post.id, UserOperationCrud::EditPost, context).await
106 PostOrComment::Comment(comment) => {
107 let deleted_comment = blocking(context.pool(), move |conn| {
108 Comment::update_deleted(conn, comment.id, false)
111 send_comment_message(
114 UserOperationCrud::EditComment,
123 fn common(&self) -> &ActivityCommonFields {