4 announce::{AnnouncableActivities, GetCommunity},
5 block_user::BlockUserFromCommunity,
12 verify_person_in_community,
14 fetcher::object_id::ObjectId,
15 objects::{community::ApubCommunity, person::ApubPerson},
17 use activitystreams::{activity::kind::UndoType, public, unparsed::Unparsed};
18 use lemmy_api_common::blocking;
21 traits::{ActivityFields, ActivityHandler, ActorType},
23 use lemmy_db_schema::{
24 source::community::{CommunityPersonBan, CommunityPersonBanForm},
27 use lemmy_utils::LemmyError;
28 use lemmy_websocket::LemmyContext;
29 use serde::{Deserialize, Serialize};
32 #[derive(Clone, Debug, Deserialize, Serialize, ActivityFields)]
33 #[serde(rename_all = "camelCase")]
34 pub struct UndoBlockUserFromCommunity {
35 actor: ObjectId<ApubPerson>,
37 object: BlockUserFromCommunity,
39 #[serde(rename = "type")]
46 impl UndoBlockUserFromCommunity {
48 community: &ApubCommunity,
51 context: &LemmyContext,
52 ) -> Result<(), LemmyError> {
53 let block = BlockUserFromCommunity::new(community, target, actor, context)?;
55 let id = generate_activity_id(
57 &context.settings().get_protocol_and_hostname(),
59 let undo = UndoBlockUserFromCommunity {
60 actor: ObjectId::new(actor.actor_id()),
63 cc: vec![community.actor_id()],
66 unparsed: Default::default(),
69 let activity = AnnouncableActivities::UndoBlockUserFromCommunity(undo);
70 let inboxes = vec![target.shared_inbox_or_inbox_url()];
71 send_to_community(activity, &id, actor, community, inboxes, context).await
75 #[async_trait::async_trait(?Send)]
76 impl ActivityHandler for UndoBlockUserFromCommunity {
77 type DataType = LemmyContext;
80 context: &Data<LemmyContext>,
81 request_counter: &mut i32,
82 ) -> Result<(), LemmyError> {
83 verify_is_public(&self.to)?;
84 verify_activity(self, &context.settings())?;
85 let community = self.get_community(context, request_counter).await?;
86 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
87 verify_mod_action(&self.actor, &community, context, request_counter).await?;
88 self.object.verify(context, request_counter).await?;
94 context: &Data<LemmyContext>,
95 request_counter: &mut i32,
96 ) -> Result<(), LemmyError> {
97 let community = self.get_community(context, request_counter).await?;
98 let blocked_user = self
101 .dereference(context, request_counter)
104 let community_user_ban_form = CommunityPersonBanForm {
105 community_id: community.id,
106 person_id: blocked_user.id,
109 blocking(context.pool(), move |conn: &'_ _| {
110 CommunityPersonBan::unban(conn, &community_user_ban_form)
118 #[async_trait::async_trait(?Send)]
119 impl GetCommunity for UndoBlockUserFromCommunity {
120 async fn get_community(
122 context: &LemmyContext,
123 request_counter: &mut i32,
124 ) -> Result<ApubCommunity, LemmyError> {
125 self.object.get_community(context, request_counter).await