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;
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, LemmyErrorType};
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 match DeletableObjects::read_from_db(object, context).await? {
101 DeletableObjects::Community(community) => {
103 return Err(LemmyErrorType::OnlyLocalAdminCanRestoreCommunity)?;
105 let form = ModRemoveCommunityForm {
106 mod_person_id: actor.id,
107 community_id: community.id,
108 removed: Some(false),
112 ModRemoveCommunity::create(context.pool(), &form).await?;
116 &CommunityUpdateForm::builder().removed(Some(false)).build(),
120 DeletableObjects::Post(post) => {
121 let form = ModRemovePostForm {
122 mod_person_id: actor.id,
124 removed: Some(false),
127 ModRemovePost::create(context.pool(), &form).await?;
131 &PostUpdateForm::builder().removed(Some(false)).build(),
135 DeletableObjects::Comment(comment) => {
136 let form = ModRemoveCommentForm {
137 mod_person_id: actor.id,
138 comment_id: comment.id,
139 removed: Some(false),
142 ModRemoveComment::create(context.pool(), &form).await?;
146 &CommentUpdateForm::builder().removed(Some(false)).build(),
150 DeletableObjects::PrivateMessage(_) => unimplemented!(),