]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/protocol/objects/page.rs
Accept Image objects in attachments (#2394)
[lemmy.git] / crates / apub / src / protocol / objects / page.rs
index 8aa5a49a03c9702d789bd63098341bf5638f11d0..9a47324ef586541c4a3b21eb88f73226c5f65bcd 100644 (file)
@@ -13,7 +13,7 @@ use activitypub_federation::{
   },
   traits::{ActivityHandler, ApubObject},
 };
-use activitystreams_kinds::link::LinkType;
+use activitystreams_kinds::{link::LinkType, object::ImageType};
 use chrono::{DateTime, FixedOffset};
 use itertools::Itertools;
 use lemmy_db_schema::newtypes::DbUrl;
@@ -66,11 +66,26 @@ pub struct Page {
 
 #[derive(Clone, Debug, Deserialize, Serialize)]
 #[serde(rename_all = "camelCase")]
-pub(crate) struct Attachment {
+pub(crate) struct Link {
   pub(crate) href: Url,
   pub(crate) r#type: LinkType,
 }
 
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub(crate) struct Image {
+  #[serde(rename = "type")]
+  pub(crate) kind: ImageType,
+  pub(crate) url: Url,
+}
+
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(untagged)]
+pub(crate) enum Attachment {
+  Link(Link),
+  Image(Image),
+}
+
 #[derive(Clone, Debug, Deserialize, Serialize)]
 #[serde(untagged)]
 pub(crate) enum AttributedTo {
@@ -174,10 +189,10 @@ impl Page {
 
 impl Attachment {
   pub(crate) fn new(url: DbUrl) -> Attachment {
-    Attachment {
+    Attachment::Link(Link {
       href: url.into(),
       r#type: Default::default(),
-    }
+    })
   }
 }