]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/activities/create_or_update/page.rs
Implement separate mod activities for feature, lock post (#2716)
[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::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
7 use lemmy_api_common::context::LemmyContext;
8 use lemmy_utils::error::LemmyError;
9 use serde::{Deserialize, Serialize};
10 use url::Url;
11
12 #[derive(Clone, Debug, Deserialize, Serialize)]
13 #[serde(rename_all = "camelCase")]
14 pub struct CreateOrUpdatePage {
15   pub(crate) actor: ObjectId<ApubPerson>,
16   #[serde(deserialize_with = "deserialize_one_or_many")]
17   pub(crate) to: Vec<Url>,
18   pub(crate) object: Page,
19   #[serde(deserialize_with = "deserialize_one_or_many")]
20   pub(crate) cc: Vec<Url>,
21   #[serde(rename = "type")]
22   pub(crate) kind: CreateOrUpdateType,
23   pub(crate) id: Url,
24   pub(crate) audience: Option<ObjectId<ApubCommunity>>,
25 }
26
27 #[async_trait::async_trait(?Send)]
28 impl InCommunity for CreateOrUpdatePage {
29   async fn community(
30     &self,
31     context: &LemmyContext,
32     request_counter: &mut i32,
33   ) -> Result<ApubCommunity, LemmyError> {
34     let community = self.object.community(context, request_counter).await?;
35     if let Some(audience) = &self.audience {
36       verify_community_matches(audience, community.actor_id.clone())?;
37     }
38     Ok(community)
39   }
40 }