]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/activities/community/report.rs
add enable_federated_downvotes site option
[lemmy.git] / crates / apub / src / protocol / activities / community / report.rs
1 use crate::{
2   activities::verify_community_matches,
3   fetcher::post_or_comment::PostOrComment,
4   objects::{community::ApubCommunity, person::ApubPerson},
5   protocol::InCommunity,
6 };
7 use activitypub_federation::{
8   config::Data,
9   fetch::object_id::ObjectId,
10   kinds::activity::FlagType,
11   protocol::helpers::deserialize_one,
12 };
13 use lemmy_api_common::context::LemmyContext;
14 use lemmy_utils::error::LemmyError;
15 use serde::{Deserialize, Serialize};
16 use url::Url;
17
18 #[derive(Clone, Debug, Deserialize, Serialize)]
19 #[serde(rename_all = "camelCase")]
20 pub struct Report {
21   pub(crate) actor: ObjectId<ApubPerson>,
22   #[serde(deserialize_with = "deserialize_one")]
23   pub(crate) to: [ObjectId<ApubCommunity>; 1],
24   pub(crate) object: ObjectId<PostOrComment>,
25   pub(crate) summary: String,
26   #[serde(rename = "type")]
27   pub(crate) kind: FlagType,
28   pub(crate) id: Url,
29   pub(crate) audience: Option<ObjectId<ApubCommunity>>,
30 }
31
32 #[async_trait::async_trait]
33 impl InCommunity for Report {
34   async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
35     let community = self.to[0].dereference(context).await?;
36     if let Some(audience) = &self.audience {
37       verify_community_matches(audience, community.actor_id.clone())?;
38     }
39     Ok(community)
40   }
41 }