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