2 activities::{deletion::DeletableObjects, verify_community_matches},
3 objects::{community::ApubCommunity, person::ApubPerson},
4 protocol::{objects::tombstone::Tombstone, IdOrNestedObject, InCommunity},
6 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
7 use activitystreams_kinds::activity::DeleteType;
9 use lemmy_api_common::context::LemmyContext;
10 use lemmy_db_schema::{
11 source::{community::Community, post::Post},
14 use lemmy_utils::error::LemmyError;
15 use serde::{Deserialize, Serialize};
16 use serde_with::skip_serializing_none;
19 #[skip_serializing_none]
20 #[derive(Clone, Debug, Deserialize, Serialize)]
21 #[serde(rename_all = "camelCase")]
23 pub(crate) actor: ObjectId<ApubPerson>,
24 #[serde(deserialize_with = "deserialize_one_or_many")]
25 pub(crate) to: Vec<Url>,
26 pub(crate) object: IdOrNestedObject<Tombstone>,
27 #[serde(rename = "type")]
28 pub(crate) kind: DeleteType,
30 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
32 #[serde(deserialize_with = "deserialize_one_or_many")]
34 #[serde(skip_serializing_if = "Vec::is_empty")]
35 pub(crate) cc: Vec<Url>,
36 /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
37 /// deleting their own content.
38 pub(crate) summary: Option<String>,
41 #[async_trait::async_trait(?Send)]
42 impl InCommunity for Delete {
45 context: &LemmyContext,
46 _request_counter: &mut i32,
47 ) -> 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())?;