2 activities::{deletion::DeletableObjects, verify_community_matches},
4 objects::{community::ApubCommunity, person::ApubPerson},
5 protocol::{objects::tombstone::Tombstone, IdOrNestedObject, InCommunity},
7 use activitypub_federation::{core::object_id::ObjectId, deser::helpers::deserialize_one_or_many};
8 use activitystreams_kinds::activity::DeleteType;
10 use lemmy_api_common::context::LemmyContext;
11 use lemmy_db_schema::{
12 source::{community::Community, post::Post},
15 use lemmy_utils::error::LemmyError;
16 use serde::{Deserialize, Serialize};
17 use serde_with::skip_serializing_none;
20 #[skip_serializing_none]
21 #[derive(Clone, Debug, Deserialize, Serialize)]
22 #[serde(rename_all = "camelCase")]
24 pub(crate) actor: ObjectId<ApubPerson>,
25 #[serde(deserialize_with = "deserialize_one_or_many")]
26 pub(crate) to: Vec<Url>,
27 pub(crate) object: IdOrNestedObject<Tombstone>,
28 #[serde(rename = "type")]
29 pub(crate) kind: DeleteType,
31 pub(crate) audience: Option<ObjectId<ApubCommunity>>,
33 #[serde(deserialize_with = "deserialize_one_or_many")]
35 #[serde(skip_serializing_if = "Vec::is_empty")]
36 pub(crate) cc: Vec<Url>,
37 /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
38 /// deleting their own content.
39 pub(crate) summary: Option<String>,
42 #[async_trait::async_trait(?Send)]
43 impl InCommunity for Delete {
46 context: &LemmyContext,
47 request_counter: &mut i32,
48 ) -> Result<ApubCommunity, LemmyError> {
49 let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
50 DeletableObjects::Community(c) => c.id,
51 DeletableObjects::Comment(c) => {
52 let post = Post::read(context.pool(), c.post_id).await?;
55 DeletableObjects::Post(p) => p.community_id,
56 DeletableObjects::PrivateMessage(_) => {
57 return Err(anyhow!("Private message is not part of community").into())
60 if let Some(audience) = &self.audience {
61 let audience = audience
62 .dereference(context, local_instance(context).await, request_counter)
64 verify_community_matches(&audience, community_id)?;
67 let community = Community::read(context.pool(), community_id).await?;