4 announce::{AnnouncableActivities, GetCommunity},
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,
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: vec![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 let community = self.get_community(context, request_counter).await?;
96 verify_person_in_community(&self.actor, &community, context, request_counter).await?;
97 verify_mod_action(&self.actor, &community, context, request_counter).await?;
98 self.object.verify(context, request_counter).await?;
104 context: &Data<LemmyContext>,
105 request_counter: &mut i32,
106 ) -> Result<(), LemmyError> {
107 let community = self.get_community(context, request_counter).await?;
108 let blocked_user = self
111 .dereference(context, request_counter)
114 let community_user_ban_form = CommunityPersonBanForm {
115 community_id: community.id,
116 person_id: blocked_user.id,
119 blocking(context.pool(), move |conn: &'_ _| {
120 CommunityPersonBan::unban(conn, &community_user_ban_form)
128 #[async_trait::async_trait(?Send)]
129 impl GetCommunity for UndoBlockUserFromCommunity {
130 async fn get_community(
132 context: &LemmyContext,
133 request_counter: &mut i32,
134 ) -> Result<ApubCommunity, LemmyError> {
135 self.object.get_community(context, request_counter).await