4 announce::AnnouncableActivities,
5 block_user::BlockUserFromCommunity,
11 verify_person_in_community,
13 context::lemmy_context,
14 fetcher::object_id::ObjectId,
15 objects::{community::ApubCommunity, person::ApubPerson},
17 use activitystreams::{
18 activity::kind::UndoType,
20 primitives::OneOrMany,
23 use lemmy_api_common::blocking;
26 traits::{ActivityFields, ActivityHandler, ActorType},
29 use lemmy_db_schema::{
30 source::community::{CommunityPersonBan, CommunityPersonBanForm},
33 use lemmy_utils::LemmyError;
34 use lemmy_websocket::LemmyContext;
35 use serde::{Deserialize, Serialize};
38 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
39 #[serde(rename_all = "camelCase")]
40 pub struct UndoBlockUserFromCommunity {
41 actor: ObjectId<ApubPerson>,
43 object: BlockUserFromCommunity,
44 cc: [ObjectId<ApubCommunity>; 1],
45 #[serde(rename = "type")]
48 #[serde(rename = "@context")]
49 context: OneOrMany<AnyBase>,
54 impl UndoBlockUserFromCommunity {
56 community: &ApubCommunity,
59 context: &LemmyContext,
60 ) -> Result<(), LemmyError> {
61 let block = BlockUserFromCommunity::new(community, target, actor, context)?;
63 let id = generate_activity_id(
65 &context.settings().get_protocol_and_hostname(),
67 let undo = UndoBlockUserFromCommunity {
68 actor: ObjectId::new(actor.actor_id()),
69 to: [PublicUrl::Public],
71 cc: [ObjectId::new(community.actor_id())],
74 context: lemmy_context(),
75 unparsed: Default::default(),
78 let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
79 let inboxes = vec![target.shared_inbox_or_inbox_url()];
80 send_to_community(activity, &id, actor, community, inboxes, context).await
84 #[async_trait::async_trait(?Send)]
85 impl ActivityHandler for UndoBlockUserFromCommunity {
86 type DataType = LemmyContext;
89 context: &Data<LemmyContext>,
90 request_counter: &mut i32,
91 ) -> Result<(), LemmyError> {
92 verify_activity(self, &context.settings())?;
93 verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
94 verify_mod_action(&self.actor, &self.cc[0], context, request_counter).await?;
95 self.object.verify(context, request_counter).await?;
101 context: &Data<LemmyContext>,
102 request_counter: &mut i32,
103 ) -> Result<(), LemmyError> {
104 let community = self.cc[0].dereference(context, request_counter).await?;
105 let blocked_user = self
108 .dereference(context, request_counter)
111 let community_user_ban_form = CommunityPersonBanForm {
112 community_id: community.id,
113 person_id: blocked_user.id,
116 blocking(context.pool(), move |conn: &'_ _| {
117 CommunityPersonBan::unban(conn, &community_user_ban_form)