]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/activities/deletion/delete.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / apub / src / activities / deletion / delete.rs
index 337ba9e8afa271c37388ec1bdd63bacbc96e194c..8ad104173d6e4bc32e33fba735c1ce5c3d40733e 100644 (file)
@@ -8,13 +8,7 @@ use crate::{
   protocol::{activities::deletion::delete::Delete, IdOrNestedObject},
 };
 use activitypub_federation::{config::Data, kinds::activity::DeleteType, traits::ActivityHandler};
-use lemmy_api_common::{
-  context::LemmyContext,
-  websocket::{
-    send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
-    UserOperationCrud,
-  },
-};
+use lemmy_api_common::context::LemmyContext;
 use lemmy_db_schema::{
   source::{
     comment::{Comment, CommentUpdateForm},
@@ -31,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]
@@ -111,13 +105,10 @@ pub(in crate::activities) async fn receive_remove_action(
   reason: Option<String>,
   context: &Data<LemmyContext>,
 ) -> 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 remove community",
-        ));
+        return Err(LemmyErrorType::OnlyLocalAdminCanRemoveCommunity)?;
       }
       let form = ModRemoveCommunityForm {
         mod_person_id: actor.id,
@@ -126,15 +117,13 @@ pub(in crate::activities) async fn receive_remove_action(
         reason,
         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(true)).build(),
       )
       .await?;
-
-      send_community_ws_message(deleted_community.id, RemoveCommunity, None, None, context).await?;
     }
     DeletableObjects::Post(post) => {
       let form = ModRemovePostForm {
@@ -143,15 +132,13 @@ pub(in crate::activities) async fn receive_remove_action(
         removed: Some(true),
         reason,
       };
-      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(true)).build(),
       )
       .await?;
-
-      send_post_ws_message(removed_post.id, RemovePost, None, None, context).await?;
     }
     DeletableObjects::Comment(comment) => {
       let form = ModRemoveCommentForm {
@@ -160,15 +147,13 @@ pub(in crate::activities) async fn receive_remove_action(
         removed: Some(true),
         reason,
       };
-      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(true)).build(),
       )
       .await?;
-
-      send_comment_ws_message_simple(removed_comment.id, RemoveComment, context).await?;
     }
     DeletableObjects::PrivateMessage(_) => unimplemented!(),
   }