2 activities::verify_community_matches,
3 objects::{community::ApubCommunity, person::ApubPerson},
4 protocol::{activities::CreateOrUpdateType, objects::page::Page, InCommunity},
6 use activitypub_federation::{
8 fetch::object_id::ObjectId,
9 protocol::helpers::deserialize_one_or_many,
11 use lemmy_api_common::context::LemmyContext;
12 use lemmy_utils::error::LemmyError;
13 use serde::{Deserialize, Serialize};
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,
28 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
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())?;