2 use actix_web::web::Data;
3 use lemmy_api_common::{
4 community::{BlockCommunity, BlockCommunityResponse},
6 utils::local_user_view_from_jwt,
10 community::{CommunityFollower, CommunityFollowerForm},
11 community_block::{CommunityBlock, CommunityBlockForm},
13 traits::{Blockable, Followable},
15 use lemmy_db_views_actor::structs::CommunityView;
16 use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
18 #[async_trait::async_trait(?Send)]
19 impl Perform for BlockCommunity {
20 type Response = BlockCommunityResponse;
22 #[tracing::instrument(skip(context))]
25 context: &Data<LemmyContext>,
26 ) -> Result<BlockCommunityResponse, LemmyError> {
27 let data: &BlockCommunity = self;
28 let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
30 let community_id = data.community_id;
31 let person_id = local_user_view.person.id;
32 let community_block_form = CommunityBlockForm {
38 CommunityBlock::block(context.pool(), &community_block_form)
40 .with_lemmy_type(LemmyErrorType::CommunityBlockAlreadyExists)?;
42 // Also, unfollow the community, and send a federated unfollow
43 let community_follower_form = CommunityFollowerForm {
44 community_id: data.community_id,
49 CommunityFollower::unfollow(context.pool(), &community_follower_form)
53 CommunityBlock::unblock(context.pool(), &community_block_form)
55 .with_lemmy_type(LemmyErrorType::CommunityBlockAlreadyExists)?;
59 CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
61 Ok(BlockCommunityResponse {