3 community::{announce::GetCommunity, send_to_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::{activity::kind::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 {
33 community: &ApubCommunity,
36 context: &LemmyContext,
37 ) -> Result<(), LemmyError> {
38 let block = BlockUserFromCommunity::new(community, target, actor, context)?;
40 let id = generate_activity_id(
42 &context.settings().get_protocol_and_hostname(),
44 let undo = UndoBlockUserFromCommunity {
45 actor: ObjectId::new(actor.actor_id()),
48 cc: vec![community.actor_id()],
51 unparsed: Default::default(),
54 let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
55 let inboxes = vec![target.shared_inbox_or_inbox_url()];
56 send_to_community(activity, &id, actor, community, inboxes, context).await
60 #[async_trait::async_trait(?Send)]
61 impl ActivityHandler for UndoBlockUserFromCommunity {
62 type DataType = LemmyContext;
65 context: &Data<LemmyContext>,
66 request_counter: &mut i32,
67 ) -> Result<(), LemmyError> {
68 verify_is_public(&self.to, &self.cc)?;
69 verify_activity(&self.id, self.actor.inner(), &context.settings())?;
70 let community = self.get_community(context, request_counter).await?;
71 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
72 verify_mod_action(&self.actor, &community, context, request_counter).await?;
73 self.object.verify(context, request_counter).await?;
79 context: &Data<LemmyContext>,
80 request_counter: &mut i32,
81 ) -> Result<(), LemmyError> {
82 let community = self.get_community(context, request_counter).await?;
83 let blocked_user = self
86 .dereference(context, request_counter)
89 let community_user_ban_form = CommunityPersonBanForm {
90 community_id: community.id,
91 person_id: blocked_user.id,
94 blocking(context.pool(), move |conn: &'_ _| {
95 CommunityPersonBan::unban(conn, &community_user_ban_form)
103 #[async_trait::async_trait(?Send)]
104 impl GetCommunity for UndoBlockUserFromCommunity {
105 async fn get_community(
107 context: &LemmyContext,
108 request_counter: &mut i32,
109 ) -> Result<ApubCommunity, LemmyError> {
110 self.object.get_community(context, request_counter).await