]> Untitled Git - lemmy.git/blobdiff - crates/api/src/community/block.rs
Implement federated user following (fixes #752) (#2577)
[lemmy.git] / crates / api / src / community / block.rs
index 5f01ac3d7f86a4562e827ed376a21c0c9c9cdb99..840d1766578c7db39f87f8bae78265243930a43b 100644 (file)
@@ -2,9 +2,9 @@ use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
   community::{BlockCommunity, BlockCommunityResponse},
-  utils::{blocking, get_local_user_view_from_jwt},
+  utils::get_local_user_view_from_jwt,
 };
-use lemmy_apub::protocol::activities::following::undo_follow::UndoFollowCommunity;
+use lemmy_apub::protocol::activities::following::undo_follow::UndoFollow;
 use lemmy_db_schema::{
   source::{
     community::{Community, CommunityFollower, CommunityFollowerForm},
@@ -38,9 +38,8 @@ impl Perform for BlockCommunity {
     };
 
     if data.block {
-      let block = move |conn: &mut _| CommunityBlock::block(conn, &community_block_form);
-      blocking(context.pool(), block)
-        .await?
+      CommunityBlock::block(context.pool(), &community_block_form)
+        .await
         .map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
 
       // Also, unfollow the community, and send a federated unfollow
@@ -49,27 +48,19 @@ impl Perform for BlockCommunity {
         person_id,
         pending: false,
       };
-      blocking(context.pool(), move |conn: &mut _| {
-        CommunityFollower::unfollow(conn, &community_follower_form)
-      })
-      .await?
-      .ok();
-      let community = blocking(context.pool(), move |conn| {
-        Community::read(conn, community_id)
-      })
-      .await??;
-      UndoFollowCommunity::send(&local_user_view.person.into(), &community.into(), context).await?;
+
+      CommunityFollower::unfollow(context.pool(), &community_follower_form)
+        .await
+        .ok();
+      let community = Community::read(context.pool(), community_id).await?;
+      UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await?;
     } else {
-      let unblock = move |conn: &mut _| CommunityBlock::unblock(conn, &community_block_form);
-      blocking(context.pool(), unblock)
-        .await?
+      CommunityBlock::unblock(context.pool(), &community_block_form)
+        .await
         .map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
     }
 
-    let community_view = blocking(context.pool(), move |conn| {
-      CommunityView::read(conn, community_id, Some(person_id))
-    })
-    .await??;
+    let community_view = CommunityView::read(context.pool(), community_id, Some(person_id)).await?;
 
     Ok(BlockCommunityResponse {
       blocked: data.block,