2 activities::verify_community_matches,
3 objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
6 use activitypub_federation::{
8 fetch::object_id::ObjectId,
9 kinds::activity::UndoType,
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};
16 use strum_macros::Display;
19 #[derive(Clone, Debug, Deserialize, Serialize, Display)]
24 #[derive(Clone, Debug, Deserialize, Serialize)]
25 #[serde(rename_all = "camelCase")]
27 pub(crate) actor: ObjectId<ApubPerson>,
28 #[serde(deserialize_with = "deserialize_one_or_many")]
29 pub(crate) to: Vec<Url>,
30 pub(crate) object: ObjectId<ApubPost>,
31 #[serde(deserialize_with = "deserialize_one_or_many")]
32 pub(crate) cc: Vec<Url>,
33 #[serde(rename = "type")]
34 pub(crate) kind: LockType,
36 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
39 #[derive(Clone, Debug, Deserialize, Serialize)]
40 #[serde(rename_all = "camelCase")]
41 pub struct UndoLockPage {
42 pub(crate) actor: ObjectId<ApubPerson>,
43 #[serde(deserialize_with = "deserialize_one_or_many")]
44 pub(crate) to: Vec<Url>,
45 pub(crate) object: LockPage,
46 #[serde(deserialize_with = "deserialize_one_or_many")]
47 pub(crate) cc: Vec<Url>,
48 #[serde(rename = "type")]
49 pub(crate) kind: UndoType,
51 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
54 #[async_trait::async_trait]
55 impl InCommunity for LockPage {
56 async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
57 let post = self.object.dereference(context).await?;
58 let community = Community::read(context.pool(), post.community_id).await?;
59 if let Some(audience) = &self.audience {
60 verify_community_matches(audience, community.actor_id.clone())?;
66 #[async_trait::async_trait]
67 impl InCommunity for UndoLockPage {
68 async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
69 let community = self.object.community(context).await?;
70 if let Some(audience) = &self.audience {
71 verify_community_matches(audience, community.actor_id.clone())?;