2 activities::{deletion::DeletableObjects, verify_community_matches},
3 objects::{community::ApubCommunity, person::ApubPerson},
4 protocol::{objects::tombstone::Tombstone, IdOrNestedObject, InCommunity},
6 use activitypub_federation::{
8 fetch::object_id::ObjectId,
9 kinds::activity::DeleteType,
10 protocol::helpers::deserialize_one_or_many,
13 use lemmy_api_common::context::LemmyContext;
14 use lemmy_db_schema::{
15 source::{community::Community, post::Post},
18 use lemmy_utils::error::LemmyError;
19 use serde::{Deserialize, Serialize};
20 use serde_with::skip_serializing_none;
23 #[skip_serializing_none]
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: IdOrNestedObject<Tombstone>,
31 #[serde(rename = "type")]
32 pub(crate) kind: DeleteType,
34 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
36 #[serde(deserialize_with = "deserialize_one_or_many")]
38 #[serde(skip_serializing_if = "Vec::is_empty")]
39 pub(crate) cc: Vec<Url>,
40 /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
41 /// deleting their own content.
42 pub(crate) summary: Option<String>,
45 #[async_trait::async_trait]
46 impl InCommunity for Delete {
47 async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
48 let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
49 DeletableObjects::Community(c) => c.id,
50 DeletableObjects::Comment(c) => {
51 let post = Post::read(context.pool(), c.post_id).await?;
54 DeletableObjects::Post(p) => p.community_id,
55 DeletableObjects::PrivateMessage(_) => {
56 return Err(anyhow!("Private message is not part of community").into())
59 let community = Community::read(context.pool(), community_id).await?;
60 if let Some(audience) = &self.audience {
61 verify_community_matches(audience, community.actor_id.clone())?;