1 use crate::activities::{
2 community::block_user::BlockUserFromCommunity,
5 verify_person_in_community,
7 use activitystreams::activity::kind::UndoType;
8 use lemmy_api_common::blocking;
9 use lemmy_apub::fetcher::{
10 community::get_or_fetch_and_upsert_community,
11 person::get_or_fetch_and_upsert_person,
13 use lemmy_apub_lib::{ActivityCommonFields, ActivityHandler, PublicUrl};
14 use lemmy_db_queries::Bannable;
15 use lemmy_db_schema::source::community::{CommunityPersonBan, CommunityPersonBanForm};
16 use lemmy_utils::LemmyError;
17 use lemmy_websocket::LemmyContext;
20 #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
21 #[serde(rename_all = "camelCase")]
22 pub struct UndoBlockUserFromCommunity {
24 object: BlockUserFromCommunity,
26 #[serde(rename = "type")]
29 common: ActivityCommonFields,
32 #[async_trait::async_trait(?Send)]
33 impl ActivityHandler for UndoBlockUserFromCommunity {
36 context: &LemmyContext,
37 request_counter: &mut i32,
38 ) -> Result<(), LemmyError> {
39 verify_activity(self.common())?;
40 verify_person_in_community(&self.common.actor, &self.cc, context, request_counter).await?;
41 verify_mod_action(&self.common.actor, self.cc[0].clone(), context).await?;
42 self.object.verify(context, request_counter).await?;
48 context: &LemmyContext,
49 request_counter: &mut i32,
50 ) -> Result<(), LemmyError> {
52 get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
54 get_or_fetch_and_upsert_person(&self.object.object, context, request_counter).await?;
56 let community_user_ban_form = CommunityPersonBanForm {
57 community_id: community.id,
58 person_id: blocked_user.id,
61 blocking(context.pool(), move |conn: &'_ _| {
62 CommunityPersonBan::unban(conn, &community_user_ban_form)
69 fn common(&self) -> &ActivityCommonFields {