3 community::{announce::GetCommunity, send_activity_in_community},
8 verify_person_in_community,
10 activity_lists::AnnouncableActivities,
11 objects::{community::ApubCommunity, person::ApubPerson},
12 protocol::activities::community::{
13 block_user::BlockUserFromCommunity,
14 undo_block_user::UndoBlockUserFromCommunity,
17 use activitystreams_kinds::{activity::UndoType, public};
18 use lemmy_api_common::blocking;
22 traits::{ActivityHandler, ActorType},
24 use lemmy_db_schema::{
25 source::community::{CommunityPersonBan, CommunityPersonBanForm},
28 use lemmy_utils::LemmyError;
29 use lemmy_websocket::LemmyContext;
31 impl UndoBlockUserFromCommunity {
32 #[tracing::instrument(skip_all)]
34 community: &ApubCommunity,
37 context: &LemmyContext,
38 ) -> Result<(), LemmyError> {
39 let block = BlockUserFromCommunity::new(community, target, actor, context)?;
41 let id = generate_activity_id(
43 &context.settings().get_protocol_and_hostname(),
45 let undo = UndoBlockUserFromCommunity {
46 actor: ObjectId::new(actor.actor_id()),
49 cc: vec![community.actor_id()],
52 unparsed: Default::default(),
55 let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
56 let inboxes = vec![target.shared_inbox_or_inbox_url()];
57 send_activity_in_community(activity, &id, actor, community, inboxes, context).await
61 #[async_trait::async_trait(?Send)]
62 impl ActivityHandler for UndoBlockUserFromCommunity {
63 type DataType = LemmyContext;
65 #[tracing::instrument(skip_all)]
68 context: &Data<LemmyContext>,
69 request_counter: &mut i32,
70 ) -> Result<(), LemmyError> {
71 verify_is_public(&self.to, &self.cc)?;
72 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
73 let community = self.get_community(context, request_counter).await?;
74 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
75 verify_mod_action(&self.actor, &community, context, request_counter).await?;
76 self.object.verify(context, request_counter).await?;
80 #[tracing::instrument(skip_all)]
83 context: &Data<LemmyContext>,
84 request_counter: &mut i32,
85 ) -> Result<(), LemmyError> {
86 let community = self.get_community(context, request_counter).await?;
87 let blocked_user = self
90 .dereference(context, request_counter)
93 let community_user_ban_form = CommunityPersonBanForm {
94 community_id: community.id,
95 person_id: blocked_user.id,
98 blocking(context.pool(), move |conn: &'_ _| {
99 CommunityPersonBan::unban(conn, &community_user_ban_form)
107 #[async_trait::async_trait(?Send)]
108 impl GetCommunity for UndoBlockUserFromCommunity {
109 #[tracing::instrument(skip_all)]
110 async fn get_community(
112 context: &LemmyContext,
113 request_counter: &mut i32,
114 ) -> Result<ApubCommunity, LemmyError> {
115 self.object.get_community(context, request_counter).await