2 activities::{block::SiteOrCommunity, verify_community_matches},
3 objects::{community::ApubCommunity, person::ApubPerson},
6 use activitypub_federation::{
8 fetch::object_id::ObjectId,
9 kinds::activity::BlockType,
10 protocol::helpers::deserialize_one_or_many,
13 use chrono::{DateTime, FixedOffset};
14 use lemmy_api_common::context::LemmyContext;
15 use lemmy_utils::error::LemmyError;
16 use serde::{Deserialize, Serialize};
17 use serde_with::skip_serializing_none;
20 #[skip_serializing_none]
21 #[derive(Clone, Debug, Deserialize, Serialize)]
22 #[serde(rename_all = "camelCase")]
23 pub struct BlockUser {
24 pub(crate) actor: ObjectId<ApubPerson>,
25 #[serde(deserialize_with = "deserialize_one_or_many")]
26 pub(crate) to: Vec<Url>,
27 pub(crate) object: ObjectId<ApubPerson>,
28 #[serde(deserialize_with = "deserialize_one_or_many")]
29 pub(crate) cc: Vec<Url>,
30 pub(crate) target: ObjectId<SiteOrCommunity>,
31 #[serde(rename = "type")]
32 pub(crate) kind: BlockType,
34 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
36 /// Quick and dirty solution.
37 /// TODO: send a separate Delete activity instead
38 pub(crate) remove_data: Option<bool>,
39 /// block reason, written to mod log
40 pub(crate) summary: Option<String>,
41 pub(crate) expires: Option<DateTime<FixedOffset>>,
44 #[async_trait::async_trait]
45 impl InCommunity for BlockUser {
46 async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
47 let target = self.target.dereference(context).await?;
48 let community = match target {
49 SiteOrCommunity::Community(c) => c,
50 SiteOrCommunity::Site(_) => return Err(anyhow!("activity is not in community").into()),
52 if let Some(audience) = &self.audience {
53 verify_community_matches(audience, community.actor_id.clone())?;