2 activities::verify_community_matches,
4 objects::{community::ApubCommunity, person::ApubPerson},
5 protocol::{activities::CreateOrUpdateType, objects::page::Page, InCommunity},
7 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
8 use lemmy_api_common::context::LemmyContext;
9 use lemmy_utils::error::LemmyError;
10 use serde::{Deserialize, Serialize};
13 #[derive(Clone, Debug, Deserialize, Serialize)]
14 #[serde(rename_all = "camelCase")]
15 pub struct CreateOrUpdatePage {
16 pub(crate) actor: ObjectId<ApubPerson>,
17 #[serde(deserialize_with = "deserialize_one_or_many")]
18 pub(crate) to: Vec<Url>,
19 pub(crate) object: Page,
20 #[serde(deserialize_with = "deserialize_one_or_many")]
21 pub(crate) cc: Vec<Url>,
22 #[serde(rename = "type")]
23 pub(crate) kind: CreateOrUpdateType,
25 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
28 #[async_trait::async_trait(?Send)]
29 impl InCommunity for CreateOrUpdatePage {
32 context: &LemmyContext,
33 request_counter: &mut i32,
34 ) -> Result<ApubCommunity, LemmyError> {
35 let object_community = self.object.community(context, request_counter).await?;
36 if let Some(audience) = &self.audience {
37 let audience = audience
38 .dereference(context, local_instance(context).await, request_counter)
40 verify_community_matches(&audience, object_community.id)?;