]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/activities/deletion/delete.rs
Merge different delete activities for better compatibility (fixes #2066) (#2073)
[lemmy.git] / crates / apub / src / protocol / activities / deletion / delete.rs
1 use crate::{objects::person::ApubPerson, protocol::Unparsed};
2 use activitystreams_kinds::activity::DeleteType;
3 use lemmy_apub_lib::object_id::ObjectId;
4 use serde::{Deserialize, Serialize};
5 use serde_with::skip_serializing_none;
6 use url::Url;
7
8 #[skip_serializing_none]
9 #[derive(Clone, Debug, Deserialize, Serialize)]
10 #[serde(rename_all = "camelCase")]
11 pub struct Delete {
12   pub(crate) actor: ObjectId<ApubPerson>,
13   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
14   pub(crate) to: Vec<Url>,
15   pub(crate) object: IdOrNestedObject,
16   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
17   #[serde(default)]
18   #[serde(skip_serializing_if = "Vec::is_empty")]
19   pub(crate) cc: Vec<Url>,
20   #[serde(rename = "type")]
21   pub(crate) kind: DeleteType,
22   /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
23   /// deleting their own content.
24   pub(crate) summary: Option<String>,
25   pub(crate) id: Url,
26   #[serde(flatten)]
27   pub(crate) unparsed: Unparsed,
28 }
29
30 /// Instead of a simple ID string as object, Mastodon sends a nested tombstone for some reason,
31 /// so we need to handle that as well.
32 #[derive(Clone, Debug, Deserialize, Serialize)]
33 #[serde(untagged)]
34 pub(crate) enum IdOrNestedObject {
35   Id(Url),
36   NestedObject(NestedObject),
37 }
38
39 #[derive(Clone, Debug, Deserialize, Serialize)]
40 pub(crate) struct NestedObject {
41   id: Url,
42 }
43
44 impl IdOrNestedObject {
45   pub(crate) fn id(&self) -> &Url {
46     match self {
47       IdOrNestedObject::Id(i) => i,
48       IdOrNestedObject::NestedObject(n) => &n.id,
49     }
50   }
51 }