3 community::{announce::GetCommunity, send_to_community},
4 deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
9 activity_lists::AnnouncableActivities,
10 fetcher::object_id::ObjectId,
11 objects::{community::ApubCommunity, person::ApubPerson},
12 protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
14 use activitystreams::{activity::kind::UndoType, public};
16 use lemmy_api_common::blocking;
19 traits::{ActivityHandler, ActorType},
21 use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post};
22 use lemmy_utils::LemmyError;
23 use lemmy_websocket::{
24 send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
30 #[async_trait::async_trait(?Send)]
31 impl ActivityHandler for UndoDelete {
32 type DataType = LemmyContext;
35 context: &Data<LemmyContext>,
36 request_counter: &mut i32,
37 ) -> Result<(), LemmyError> {
38 verify_is_public(&self.to)?;
39 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
40 self.object.verify(context, request_counter).await?;
41 let community = self.get_community(context, request_counter).await?;
42 verify_delete_activity(
46 self.object.summary.is_some(),
56 context: &Data<LemmyContext>,
57 request_counter: &mut i32,
58 ) -> Result<(), LemmyError> {
59 if self.object.summary.is_some() {
60 UndoDelete::receive_undo_remove_action(&self.object.object, context).await
62 receive_delete_action(
75 pub(in crate::activities::deletion) async fn send(
77 community: &ApubCommunity,
79 summary: Option<String>,
80 context: &LemmyContext,
81 ) -> Result<(), LemmyError> {
82 let object = Delete::new(actor, community, object_id, summary, context)?;
84 let id = generate_activity_id(
86 &context.settings().get_protocol_and_hostname(),
88 let undo = UndoDelete {
89 actor: ObjectId::new(actor.actor_id()),
92 cc: vec![community.actor_id()],
95 unparsed: Default::default(),
98 let activity = AnnouncableActivities::UndoDelete(undo);
99 send_to_community(activity, &id, actor, community, vec![], context).await
102 pub(in crate::activities) async fn receive_undo_remove_action(
104 context: &LemmyContext,
105 ) -> Result<(), LemmyError> {
106 use UserOperationCrud::*;
107 match DeletableObjects::read_from_db(object, context).await? {
108 DeletableObjects::Community(community) => {
110 return Err(anyhow!("Only local admin can restore community").into());
112 let deleted_community = blocking(context.pool(), move |conn| {
113 Community::update_removed(conn, community.id, false)
116 send_community_ws_message(deleted_community.id, EditCommunity, None, None, context).await?;
118 DeletableObjects::Post(post) => {
119 let removed_post = blocking(context.pool(), move |conn| {
120 Post::update_removed(conn, post.id, false)
123 send_post_ws_message(removed_post.id, EditPost, None, None, context).await?;
125 DeletableObjects::Comment(comment) => {
126 let removed_comment = blocking(context.pool(), move |conn| {
127 Comment::update_removed(conn, comment.id, false)
130 send_comment_ws_message_simple(removed_comment.id, EditComment, context).await?;
137 #[async_trait::async_trait(?Send)]
138 impl GetCommunity for UndoDelete {
139 async fn get_community(
141 context: &LemmyContext,
142 request_counter: &mut i32,
143 ) -> Result<ApubCommunity, LemmyError> {
144 self.object.get_community(context, request_counter).await