X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapub%2Fsrc%2Factivities%2Fdeletion%2Fundo_delete.rs;h=541a7455fe376082931f957524c859bcdd357236;hb=e9e76549a88cfbdab36f00d302cceabcaaa24f4c;hp=13a32cabcc66082115a35feb62781b550f88fe6b;hpb=63f54a3103684fd375428331f730b9a104add3a9;p=lemmy.git diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index 13a32cab..541a7455 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -3,12 +3,12 @@ use crate::{ deletion::{receive_delete_action, verify_delete_activity, DeletableObjects}, generate_activity_id, }, - insert_activity, + insert_received_activity, objects::person::ApubPerson, protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete}, }; use activitypub_federation::{config::Data, kinds::activity::UndoType, traits::ActivityHandler}; -use lemmy_api_common::{context::LemmyContext, websocket::UserOperationCrud}; +use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{ source::{ comment::{Comment, CommentUpdateForm}, @@ -25,7 +25,7 @@ use lemmy_db_schema::{ }, traits::Crud, }; -use lemmy_utils::error::LemmyError; +use lemmy_utils::error::{LemmyError, LemmyErrorType}; use url::Url; #[async_trait::async_trait] @@ -42,6 +42,7 @@ impl ActivityHandler for UndoDelete { } async fn verify(&self, data: &Data) -> Result<(), Self::Error> { + insert_received_activity(&self.id, data).await?; self.object.verify(data).await?; verify_delete_activity(&self.object, self.object.summary.is_some(), data).await?; Ok(()) @@ -49,7 +50,6 @@ impl ActivityHandler for UndoDelete { #[tracing::instrument(skip_all)] async fn receive(self, context: &Data) -> Result<(), LemmyError> { - insert_activity(&self.id, &self, false, false, context).await?; if self.object.summary.is_some() { UndoDelete::receive_undo_remove_action( &self.actor.dereference(context).await?, @@ -97,13 +97,10 @@ impl UndoDelete { object: &Url, context: &Data, ) -> Result<(), LemmyError> { - use UserOperationCrud::*; match DeletableObjects::read_from_db(object, context).await? { DeletableObjects::Community(community) => { if community.local { - return Err(LemmyError::from_message( - "Only local admin can restore community", - )); + return Err(LemmyErrorType::OnlyLocalAdminCanRestoreCommunity)?; } let form = ModRemoveCommunityForm { mod_person_id: actor.id, @@ -112,16 +109,13 @@ impl UndoDelete { reason: None, expires: None, }; - ModRemoveCommunity::create(context.pool(), &form).await?; - let deleted_community = Community::update( - context.pool(), + ModRemoveCommunity::create(&mut context.pool(), &form).await?; + Community::update( + &mut context.pool(), community.id, &CommunityUpdateForm::builder().removed(Some(false)).build(), ) .await?; - context - .send_community_ws_message(&EditCommunity, deleted_community.id, None, None) - .await?; } DeletableObjects::Post(post) => { let form = ModRemovePostForm { @@ -130,16 +124,13 @@ impl UndoDelete { removed: Some(false), reason: None, }; - ModRemovePost::create(context.pool(), &form).await?; - let removed_post = Post::update( - context.pool(), + ModRemovePost::create(&mut context.pool(), &form).await?; + Post::update( + &mut context.pool(), post.id, &PostUpdateForm::builder().removed(Some(false)).build(), ) .await?; - context - .send_post_ws_message(&EditPost, removed_post.id, None, None) - .await?; } DeletableObjects::Comment(comment) => { let form = ModRemoveCommentForm { @@ -148,16 +139,13 @@ impl UndoDelete { removed: Some(false), reason: None, }; - ModRemoveComment::create(context.pool(), &form).await?; - let removed_comment = Comment::update( - context.pool(), + ModRemoveComment::create(&mut context.pool(), &form).await?; + Comment::update( + &mut context.pool(), comment.id, &CommentUpdateForm::builder().removed(Some(false)).build(), ) .await?; - context - .send_comment_ws_message_simple(&EditComment, removed_comment.id) - .await?; } DeletableObjects::PrivateMessage(_) => unimplemented!(), }