2 activities::{block::SiteOrCommunity, verify_community_matches},
4 objects::{community::ApubCommunity, person::ApubPerson},
7 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
8 use activitystreams_kinds::activity::BlockType;
10 use chrono::{DateTime, FixedOffset};
11 use lemmy_api_common::context::LemmyContext;
12 use lemmy_utils::error::LemmyError;
13 use serde::{Deserialize, Serialize};
14 use serde_with::skip_serializing_none;
17 #[skip_serializing_none]
18 #[derive(Clone, Debug, Deserialize, Serialize)]
19 #[serde(rename_all = "camelCase")]
20 pub struct BlockUser {
21 pub(crate) actor: ObjectId<ApubPerson>,
22 #[serde(deserialize_with = "deserialize_one_or_many")]
23 pub(crate) to: Vec<Url>,
24 pub(crate) object: ObjectId<ApubPerson>,
25 #[serde(deserialize_with = "deserialize_one_or_many")]
26 pub(crate) cc: Vec<Url>,
27 pub(crate) target: ObjectId<SiteOrCommunity>,
28 #[serde(rename = "type")]
29 pub(crate) kind: BlockType,
31 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
33 /// Quick and dirty solution.
34 /// TODO: send a separate Delete activity instead
35 pub(crate) remove_data: Option<bool>,
36 /// block reason, written to mod log
37 pub(crate) summary: Option<String>,
38 pub(crate) expires: Option<DateTime<FixedOffset>>,
41 #[async_trait::async_trait(?Send)]
42 impl InCommunity for BlockUser {
45 context: &LemmyContext,
46 request_counter: &mut i32,
47 ) -> Result<ApubCommunity, LemmyError> {
50 .dereference(context, local_instance(context).await, request_counter)
52 let target_community = match target {
53 SiteOrCommunity::Community(c) => c,
54 SiteOrCommunity::Site(_) => return Err(anyhow!("activity is not in community").into()),
56 if let Some(audience) = &self.audience {
57 let audience = audience
58 .dereference(context, local_instance(context).await, request_counter)
60 verify_community_matches(&audience, target_community.id)?;