]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/activities/deletion/delete.rs
Make delete activities backwards compatible with 0.15 (#2114)
[lemmy.git] / crates / apub / src / protocol / activities / deletion / delete.rs
1 use crate::{objects::person::ApubPerson, protocol::Unparsed};
2 use activitystreams_kinds::{activity::DeleteType, object::TombstoneType};
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(rename = "type")]
17   pub(crate) kind: DeleteType,
18   pub(crate) id: Url,
19
20   #[serde(deserialize_with = "crate::deserialize_one_or_many")]
21   #[serde(default)]
22   #[serde(skip_serializing_if = "Vec::is_empty")]
23   pub(crate) cc: Vec<Url>,
24   /// If summary is present, this is a mod action (Remove in Lemmy terms). Otherwise, its a user
25   /// deleting their own content.
26   pub(crate) summary: Option<String>,
27   #[serde(flatten)]
28   pub(crate) unparsed: Unparsed,
29 }
30
31 /// Instead of a simple ID string as object, Mastodon sends a nested tombstone for some reason,
32 /// so we need to handle that as well.
33 #[derive(Clone, Debug, Deserialize, Serialize)]
34 #[serde(untagged)]
35 pub(crate) enum IdOrNestedObject {
36   Id(Url),
37   NestedObject(NestedObject),
38 }
39
40 #[derive(Clone, Debug, Deserialize, Serialize)]
41 pub(crate) struct NestedObject {
42   pub(crate) id: Url,
43   // Backwards compatibility with Lemmy 0.15
44   #[serde(rename = "type")]
45   pub(crate) kind: TombstoneType,
46 }
47
48 impl IdOrNestedObject {
49   pub(crate) fn id(&self) -> &Url {
50     match self {
51       IdOrNestedObject::Id(i) => i,
52       IdOrNestedObject::NestedObject(n) => &n.id,
53     }
54   }
55 }