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::{
9 fetch::object_id::ObjectId,
10 protocol::helpers::deserialize_one_or_many,
12 use lemmy_api_common::context::LemmyContext;
13 use lemmy_db_schema::{source::community::Community, traits::Crud};
14 use lemmy_utils::error::LemmyError;
15 use serde::{Deserialize, Serialize};
18 #[derive(Clone, Debug, Deserialize, Serialize)]
19 #[serde(rename_all = "camelCase")]
20 pub struct CreateOrUpdateNote {
21 pub(crate) actor: ObjectId<ApubPerson>,
22 #[serde(deserialize_with = "deserialize_one_or_many")]
23 pub(crate) to: Vec<Url>,
24 pub(crate) object: Note,
25 #[serde(deserialize_with = "deserialize_one_or_many")]
26 pub(crate) cc: Vec<Url>,
28 pub(crate) tag: Vec<MentionOrValue>,
29 #[serde(rename = "type")]
30 pub(crate) kind: CreateOrUpdateType,
32 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
35 #[async_trait::async_trait]
36 impl InCommunity for CreateOrUpdateNote {
37 async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
38 let post = self.object.get_parents(context).await?.0;
39 let community = Community::read(&mut context.pool(), post.community_id).await?;
40 if let Some(audience) = &self.audience {
41 verify_community_matches(audience, community.actor_id.clone())?;