2 activities::{verify_activity, verify_mod_action, verify_person_in_community},
3 fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
5 use activitystreams::activity::kind::BlockType;
6 use lemmy_api_common::blocking;
7 use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
8 use lemmy_db_queries::{Bannable, Followable};
9 use lemmy_db_schema::source::community::{
11 CommunityFollowerForm,
13 CommunityPersonBanForm,
15 use lemmy_utils::LemmyError;
16 use lemmy_websocket::LemmyContext;
19 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
20 #[serde(rename_all = "camelCase")]
21 pub struct BlockUserFromCommunity {
23 pub(in crate::activities::community) object: Url,
25 #[serde(rename = "type")]
28 common: ActivityCommonFields,
31 #[async_trait::async_trait(?Send)]
32 impl ActivityHandler for BlockUserFromCommunity {
35 context: &LemmyContext,
36 request_counter: &mut i32,
37 ) -> Result<(), LemmyError> {
38 verify_activity(self.common())?;
39 verify_person_in_community(&self.common.actor, &self.cc[0], context, request_counter).await?;
40 verify_mod_action(&self.common.actor, self.cc[0].clone(), context).await?;
46 context: &LemmyContext,
47 request_counter: &mut i32,
48 ) -> Result<(), LemmyError> {
50 get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
52 get_or_fetch_and_upsert_person(&self.object, context, request_counter).await?;
54 let community_user_ban_form = CommunityPersonBanForm {
55 community_id: community.id,
56 person_id: blocked_user.id,
59 blocking(context.pool(), move |conn: &'_ _| {
60 CommunityPersonBan::ban(conn, &community_user_ban_form)
64 // Also unsubscribe them from the community, if they are subscribed
65 let community_follower_form = CommunityFollowerForm {
66 community_id: community.id,
67 person_id: blocked_user.id,
70 blocking(context.pool(), move |conn: &'_ _| {
71 CommunityFollower::unfollow(conn, &community_follower_form)
79 fn common(&self) -> &ActivityCommonFields {