2 activities::verify_community_matches,
3 mentions::MentionOrValue,
4 objects::{community::ApubCommunity, person::ApubPerson},
5 protocol::{activities::CreateOrUpdateType, objects::note::Note, 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_db_schema::{source::community::Community, traits::Crud};
10 use lemmy_utils::error::LemmyError;
11 use serde::{Deserialize, Serialize};
14 #[derive(Clone, Debug, Deserialize, Serialize)]
15 #[serde(rename_all = "camelCase")]
16 pub struct CreateOrUpdateNote {
17 pub(crate) actor: ObjectId<ApubPerson>,
18 #[serde(deserialize_with = "deserialize_one_or_many")]
19 pub(crate) to: Vec<Url>,
20 pub(crate) object: Note,
21 #[serde(deserialize_with = "deserialize_one_or_many")]
22 pub(crate) cc: Vec<Url>,
24 pub(crate) tag: Vec<MentionOrValue>,
25 #[serde(rename = "type")]
26 pub(crate) kind: CreateOrUpdateType,
28 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
31 #[async_trait::async_trait(?Send)]
32 impl InCommunity for CreateOrUpdateNote {
35 context: &LemmyContext,
36 request_counter: &mut i32,
37 ) -> Result<ApubCommunity, LemmyError> {
38 let post = self.object.get_parents(context, request_counter).await?.0;
39 let community = Community::read(context.pool(), post.community_id).await?;
40 if let Some(audience) = &self.audience {
41 verify_community_matches(audience, community.actor_id.clone())?;