3 community::block_user::BlockUserFromCommunity,
6 verify_person_in_community,
8 fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
10 use activitystreams::activity::kind::UndoType;
11 use lemmy_api_common::blocking;
12 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
13 use lemmy_db_queries::Bannable;
14 use lemmy_db_schema::source::community::{CommunityPersonBan, 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 UndoBlockUserFromCommunity {
23 object: BlockUserFromCommunity,
25 #[serde(rename = "type")]
28 common: ActivityCommonFields,
31 #[async_trait::async_trait(?Send)]
32 impl ActivityHandler for UndoBlockUserFromCommunity {
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?;
41 self.object.verify(context, request_counter).await?;
47 context: &LemmyContext,
48 request_counter: &mut i32,
49 ) -> Result<(), LemmyError> {
51 get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
53 get_or_fetch_and_upsert_person(&self.object.object, context, request_counter).await?;
55 let community_user_ban_form = CommunityPersonBanForm {
56 community_id: community.id,
57 person_id: blocked_user.id,
60 blocking(context.pool(), move |conn: &'_ _| {
61 CommunityPersonBan::unban(conn, &community_user_ban_form)
68 fn common(&self) -> &ActivityCommonFields {