3 community::{announce::AnnouncableActivities, block_user::BlockUserFromCommunity},
7 verify_person_in_community,
9 activity_queue::send_to_community_new,
10 extensions::context::lemmy_context,
11 fetcher::{community::get_or_fetch_and_upsert_community, person::get_or_fetch_and_upsert_person},
14 use activitystreams::{
15 activity::kind::UndoType,
17 primitives::OneOrMany,
20 use lemmy_api_common::blocking;
21 use lemmy_apub_lib::{values::PublicUrl, ActivityFields, ActivityHandler};
22 use lemmy_db_queries::Bannable;
23 use lemmy_db_schema::source::{
24 community::{Community, CommunityPersonBan, CommunityPersonBanForm},
27 use lemmy_utils::LemmyError;
28 use lemmy_websocket::LemmyContext;
29 use serde::{Deserialize, Serialize};
32 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
33 #[serde(rename_all = "camelCase")]
34 pub struct UndoBlockUserFromCommunity {
37 object: BlockUserFromCommunity,
39 #[serde(rename = "type")]
42 #[serde(rename = "@context")]
43 context: OneOrMany<AnyBase>,
48 impl UndoBlockUserFromCommunity {
50 community: &Community,
53 context: &LemmyContext,
54 ) -> Result<(), LemmyError> {
55 let block = BlockUserFromCommunity::new(community, target, actor)?;
57 let id = generate_activity_id(UndoType::Undo)?;
58 let undo = UndoBlockUserFromCommunity {
59 actor: actor.actor_id(),
60 to: [PublicUrl::Public],
62 cc: [community.actor_id()],
65 context: lemmy_context(),
66 unparsed: Default::default(),
69 let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
70 let inboxes = vec![target.get_shared_inbox_or_inbox_url()];
71 send_to_community_new(activity, &id, actor, community, inboxes, context).await
75 #[async_trait::async_trait(?Send)]
76 impl ActivityHandler for UndoBlockUserFromCommunity {
79 context: &LemmyContext,
80 request_counter: &mut i32,
81 ) -> Result<(), LemmyError> {
82 verify_activity(self)?;
83 verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
84 verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
85 self.object.verify(context, request_counter).await?;
91 context: &LemmyContext,
92 request_counter: &mut i32,
93 ) -> Result<(), LemmyError> {
95 get_or_fetch_and_upsert_community(&self.cc[0], context, request_counter).await?;
97 get_or_fetch_and_upsert_person(&self.object.object, context, request_counter).await?;
99 let community_user_ban_form = CommunityPersonBanForm {
100 community_id: community.id,
101 person_id: blocked_user.id,
104 blocking(context.pool(), move |conn: &'_ _| {
105 CommunityPersonBan::unban(conn, &community_user_ban_form)