3 community::{announce::GetCommunity, send_activity_in_community},
4 deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
9 activity_lists::AnnouncableActivities,
10 objects::{community::ApubCommunity, person::ApubPerson},
11 protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
13 use activitystreams_kinds::{activity::UndoType, public};
14 use lemmy_api_common::blocking;
18 traits::{ActivityHandler, ActorType},
20 use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
21 use lemmy_utils::LemmyError;
22 use lemmy_websocket::{
23 send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
29 #[async_trait::async_trait(?Send)]
30 impl ActivityHandler for UndoDelete {
31 type DataType = LemmyContext;
33 #[tracing::instrument(skip_all)]
36 context: &Data<LemmyContext>,
37 request_counter: &mut i32,
38 ) -> Result<(), LemmyError> {
39 verify_is_public(&self.to, &self.cc)?;
40 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
41 self.object.verify(context, request_counter).await?;
42 let community = self.get_community(context, request_counter).await?;
43 verify_delete_activity(
44 &self.object.object.id,
47 self.object.summary.is_some(),
55 #[tracing::instrument(skip_all)]
58 context: &Data<LemmyContext>,
59 request_counter: &mut i32,
60 ) -> Result<(), LemmyError> {
61 if self.object.summary.is_some() {
62 UndoDelete::receive_undo_remove_action(&self.object.object.id, context).await
64 receive_delete_action(
65 &self.object.object.id,
77 #[tracing::instrument(skip_all)]
78 pub(in crate::activities::deletion) async fn send(
80 community: &ApubCommunity,
81 object: DeletableObjects,
82 summary: Option<String>,
83 context: &LemmyContext,
84 ) -> Result<(), LemmyError> {
85 let object = Delete::new(actor, object, summary, context)?;
87 let id = generate_activity_id(
89 &context.settings().get_protocol_and_hostname(),
91 let undo = UndoDelete {
92 actor: ObjectId::new(actor.actor_id()),
95 cc: vec![community.actor_id()],
98 unparsed: Default::default(),
101 let activity = AnnouncableActivities::UndoDelete(undo);
102 send_activity_in_community(activity, &id, actor, community, vec![], context).await
105 #[tracing::instrument(skip_all)]
106 pub(in crate::activities) async fn receive_undo_remove_action(
108 context: &LemmyContext,
109 ) -> Result<(), LemmyError> {
110 use UserOperationCrud::*;
111 match DeletableObjects::read_from_db(object, context).await? {
112 DeletableObjects::Community(community) => {
114 return Err(LemmyError::from_message(
115 "Only local admin can restore community",
118 let deleted_community = blocking(context.pool(), move |conn| {
119 Community::update_removed(conn, community.id, false)
122 send_community_ws_message(deleted_community.id, EditCommunity, None, None, context).await?;
124 DeletableObjects::Post(post) => {
125 let removed_post = blocking(context.pool(), move |conn| {
126 Post::update_removed(conn, post.id, false)
129 send_post_ws_message(removed_post.id, EditPost, None, None, context).await?;
131 DeletableObjects::Comment(comment) => {
132 let removed_comment = blocking(context.pool(), move |conn| {
133 Comment::update_removed(conn, comment.id, false)
136 send_comment_ws_message_simple(removed_comment.id, EditComment, context).await?;
143 #[async_trait::async_trait(?Send)]
144 impl GetCommunity for UndoDelete {
145 #[tracing::instrument(skip_all)]
146 async fn get_community(
148 context: &LemmyContext,
149 request_counter: &mut i32,
150 ) -> Result<ApubCommunity, LemmyError> {
151 self.object.get_community(context, request_counter).await