4 announce::AnnouncableActivities,
5 block_user::BlockUserFromCommunity,
11 verify_person_in_community,
13 context::lemmy_context,
14 fetcher::object_id::ObjectId,
16 use activitystreams::{
17 activity::kind::UndoType,
19 primitives::OneOrMany,
22 use lemmy_api_common::blocking;
25 traits::{ActivityFields, ActivityHandler, ActorType},
28 use lemmy_db_schema::{
30 community::{Community, CommunityPersonBan, CommunityPersonBanForm},
35 use lemmy_utils::LemmyError;
36 use lemmy_websocket::LemmyContext;
37 use serde::{Deserialize, Serialize};
40 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
41 #[serde(rename_all = "camelCase")]
42 pub struct UndoBlockUserFromCommunity {
43 actor: ObjectId<Person>,
45 object: BlockUserFromCommunity,
46 cc: [ObjectId<Community>; 1],
47 #[serde(rename = "type")]
50 #[serde(rename = "@context")]
51 context: OneOrMany<AnyBase>,
56 impl UndoBlockUserFromCommunity {
58 community: &Community,
61 context: &LemmyContext,
62 ) -> Result<(), LemmyError> {
63 let block = BlockUserFromCommunity::new(community, target, actor, context)?;
65 let id = generate_activity_id(
67 &context.settings().get_protocol_and_hostname(),
69 let undo = UndoBlockUserFromCommunity {
70 actor: ObjectId::new(actor.actor_id()),
71 to: [PublicUrl::Public],
73 cc: [ObjectId::new(community.actor_id())],
76 context: lemmy_context(),
77 unparsed: Default::default(),
80 let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
81 let inboxes = vec![target.shared_inbox_or_inbox_url()];
82 send_to_community(activity, &id, actor, community, inboxes, context).await
86 #[async_trait::async_trait(?Send)]
87 impl ActivityHandler for UndoBlockUserFromCommunity {
88 type DataType = LemmyContext;
91 context: &Data<LemmyContext>,
92 request_counter: &mut i32,
93 ) -> Result<(), LemmyError> {
94 verify_activity(self, &context.settings())?;
95 verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
96 verify_mod_action(&self.actor, self.cc[0].clone(), context, request_counter).await?;
97 self.object.verify(context, request_counter).await?;
103 context: &Data<LemmyContext>,
104 request_counter: &mut i32,
105 ) -> Result<(), LemmyError> {
106 let community = self.cc[0].dereference(context, request_counter).await?;
107 let blocked_user = self
110 .dereference(context, request_counter)
113 let community_user_ban_form = CommunityPersonBanForm {
114 community_id: community.id,
115 person_id: blocked_user.id,
118 blocking(context.pool(), move |conn: &'_ _| {
119 CommunityPersonBan::unban(conn, &community_user_ban_form)