4 announce::AnnouncableActivities,
5 block_user::BlockUserFromCommunity,
12 verify_person_in_community,
14 context::lemmy_context,
15 fetcher::object_id::ObjectId,
16 objects::{community::ApubCommunity, person::ApubPerson},
18 use activitystreams::{
19 activity::kind::UndoType,
21 primitives::OneOrMany,
25 use lemmy_api_common::blocking;
28 traits::{ActivityFields, ActivityHandler, ActorType},
30 use lemmy_db_schema::{
31 source::community::{CommunityPersonBan, CommunityPersonBanForm},
34 use lemmy_utils::LemmyError;
35 use lemmy_websocket::LemmyContext;
36 use serde::{Deserialize, Serialize};
39 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
40 #[serde(rename_all = "camelCase")]
41 pub struct UndoBlockUserFromCommunity {
42 actor: ObjectId<ApubPerson>,
44 object: BlockUserFromCommunity,
45 cc: [ObjectId<ApubCommunity>; 1],
46 #[serde(rename = "type")]
49 #[serde(rename = "@context")]
50 context: OneOrMany<AnyBase>,
55 impl UndoBlockUserFromCommunity {
57 community: &ApubCommunity,
60 context: &LemmyContext,
61 ) -> Result<(), LemmyError> {
62 let block = BlockUserFromCommunity::new(community, target, actor, context)?;
64 let id = generate_activity_id(
66 &context.settings().get_protocol_and_hostname(),
68 let undo = UndoBlockUserFromCommunity {
69 actor: ObjectId::new(actor.actor_id()),
72 cc: [ObjectId::new(community.actor_id())],
75 context: lemmy_context(),
76 unparsed: Default::default(),
79 let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
80 let inboxes = vec![target.shared_inbox_or_inbox_url()];
81 send_to_community(activity, &id, actor, community, inboxes, context).await
85 #[async_trait::async_trait(?Send)]
86 impl ActivityHandler for UndoBlockUserFromCommunity {
87 type DataType = LemmyContext;
90 context: &Data<LemmyContext>,
91 request_counter: &mut i32,
92 ) -> Result<(), LemmyError> {
93 verify_is_public(&self.to)?;
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], 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)