2 activities::verify_community_matches,
4 mentions::MentionOrValue,
5 objects::{community::ApubCommunity, person::ApubPerson},
6 protocol::{activities::CreateOrUpdateType, objects::note::Note, InCommunity},
8 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
9 use lemmy_api_common::context::LemmyContext;
10 use lemmy_db_schema::{source::community::Community, traits::Crud};
11 use lemmy_utils::error::LemmyError;
12 use serde::{Deserialize, Serialize};
15 #[derive(Clone, Debug, Deserialize, Serialize)]
16 #[serde(rename_all = "camelCase")]
17 pub struct CreateOrUpdateNote {
18 pub(crate) actor: ObjectId<ApubPerson>,
19 #[serde(deserialize_with = "deserialize_one_or_many")]
20 pub(crate) to: Vec<Url>,
21 pub(crate) object: Note,
22 #[serde(deserialize_with = "deserialize_one_or_many")]
23 pub(crate) cc: Vec<Url>,
25 pub(crate) tag: Vec<MentionOrValue>,
26 #[serde(rename = "type")]
27 pub(crate) kind: CreateOrUpdateType,
29 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
32 #[async_trait::async_trait(?Send)]
33 impl InCommunity for CreateOrUpdateNote {
36 context: &LemmyContext,
37 request_counter: &mut i32,
38 ) -> Result<ApubCommunity, LemmyError> {
39 let post = self.object.get_parents(context, request_counter).await?.0;
40 if let Some(audience) = &self.audience {
41 let audience = audience
42 .dereference(context, local_instance(context).await, request_counter)
44 verify_community_matches(&audience, post.community_id)?;
47 let community = Community::read(context.pool(), post.community_id).await?;