3 deletion::{receive_delete_action, verify_delete_activity, DeletableObjects},
7 objects::person::ApubPerson,
8 protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete},
10 use activitypub_federation::{config::Data, kinds::activity::UndoType, traits::ActivityHandler};
11 use lemmy_api_common::{context::LemmyContext, websocket::UserOperationCrud};
12 use lemmy_db_schema::{
14 comment::{Comment, CommentUpdateForm},
15 community::{Community, CommunityUpdateForm},
20 ModRemoveCommunityForm,
24 post::{Post, PostUpdateForm},
28 use lemmy_utils::error::LemmyError;
31 #[async_trait::async_trait]
32 impl ActivityHandler for UndoDelete {
33 type DataType = LemmyContext;
34 type Error = LemmyError;
36 fn id(&self) -> &Url {
40 fn actor(&self) -> &Url {
44 async fn verify(&self, data: &Data<Self::DataType>) -> Result<(), Self::Error> {
45 self.object.verify(data).await?;
46 verify_delete_activity(&self.object, self.object.summary.is_some(), data).await?;
50 #[tracing::instrument(skip_all)]
51 async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
52 insert_activity(&self.id, &self, false, false, context).await?;
53 if self.object.summary.is_some() {
54 UndoDelete::receive_undo_remove_action(
55 &self.actor.dereference(context).await?,
56 self.object.object.id(),
61 receive_delete_action(self.object.object.id(), &self.actor, false, context).await
67 #[tracing::instrument(skip_all)]
68 pub(in crate::activities::deletion) fn new(
70 object: DeletableObjects,
72 community: Option<&Community>,
73 summary: Option<String>,
74 context: &Data<LemmyContext>,
75 ) -> Result<UndoDelete, LemmyError> {
76 let object = Delete::new(actor, object, to.clone(), community, summary, context)?;
78 let id = generate_activity_id(
80 &context.settings().get_protocol_and_hostname(),
82 let cc: Option<Url> = community.map(|c| c.actor_id.clone().into());
84 actor: actor.actor_id.clone().into(),
87 cc: cc.into_iter().collect(),
90 audience: community.map(|c| c.actor_id.clone().into()),
94 #[tracing::instrument(skip_all)]
95 pub(in crate::activities) async fn receive_undo_remove_action(
98 context: &Data<LemmyContext>,
99 ) -> Result<(), LemmyError> {
100 use UserOperationCrud::*;
101 match DeletableObjects::read_from_db(object, context).await? {
102 DeletableObjects::Community(community) => {
104 return Err(LemmyError::from_message(
105 "Only local admin can restore community",
108 let form = ModRemoveCommunityForm {
109 mod_person_id: actor.id,
110 community_id: community.id,
111 removed: Some(false),
115 ModRemoveCommunity::create(context.pool(), &form).await?;
116 let deleted_community = Community::update(
119 &CommunityUpdateForm::builder().removed(Some(false)).build(),
123 .send_community_ws_message(&EditCommunity, deleted_community.id, None, None)
126 DeletableObjects::Post(post) => {
127 let form = ModRemovePostForm {
128 mod_person_id: actor.id,
130 removed: Some(false),
133 ModRemovePost::create(context.pool(), &form).await?;
134 let removed_post = Post::update(
137 &PostUpdateForm::builder().removed(Some(false)).build(),
141 .send_post_ws_message(&EditPost, removed_post.id, None, None)
144 DeletableObjects::Comment(comment) => {
145 let form = ModRemoveCommentForm {
146 mod_person_id: actor.id,
147 comment_id: comment.id,
148 removed: Some(false),
151 ModRemoveComment::create(context.pool(), &form).await?;
152 let removed_comment = Comment::update(
155 &CommentUpdateForm::builder().removed(Some(false)).build(),
159 .send_comment_ws_message_simple(&EditComment, removed_comment.id)
162 DeletableObjects::PrivateMessage(_) => unimplemented!(),