]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/protocol/objects/page.rs
Diesel 2.0.0 upgrade (#2452)
[lemmy.git] / crates / apub / src / protocol / objects / page.rs
index 74db11afef500ba5ff99d2c719a720dd0cc8c86c..1cf55acaa68a94fb4859429996493e43339acafa 100644 (file)
@@ -2,7 +2,7 @@ use crate::{
   fetcher::user_or_community::{PersonOrGroupType, UserOrCommunity},
   local_instance,
   objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost},
-  protocol::{ImageObject, Source},
+  protocol::{objects::LanguageTag, ImageObject, Source},
 };
 use activitypub_federation::{
   core::object_id::ObjectId,
@@ -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;
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
 use serde_with::skip_serializing_none;
 use url::Url;
 
-#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
+#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
 pub enum PageType {
   Page,
   Article,
@@ -62,15 +62,31 @@ pub struct Page {
   pub(crate) stickied: Option<bool>,
   pub(crate) published: Option<DateTime<FixedOffset>>,
   pub(crate) updated: Option<DateTime<FixedOffset>>,
+  pub(crate) language: Option<LanguageTag>,
 }
 
 #[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 {
@@ -93,7 +109,7 @@ impl Page {
   /// Both stickied and locked need to be false on a newly created post (verified in [[CreatePost]].
   pub(crate) async fn is_mod_action(&self, context: &LemmyContext) -> Result<bool, LemmyError> {
     let old_post = ObjectId::<ApubPost>::new(self.id.clone())
-      .dereference_local::<LemmyError>(context)
+      .dereference_local(context)
       .await;
 
     let stickied_changed = Page::is_stickied_changed(&old_post, &self.stickied);
@@ -139,7 +155,7 @@ impl Page {
           if let Some(cid) = iter.next() {
             let cid = ObjectId::new(cid.clone());
             if let Ok(c) = cid
-              .dereference::<LemmyError>(context, local_instance(context), request_counter)
+              .dereference(context, local_instance(context), request_counter)
               .await
             {
               break Ok(c);
@@ -154,7 +170,7 @@ impl Page {
           .find(|a| a.kind == PersonOrGroupType::Group)
           .map(|a| ObjectId::<ApubCommunity>::new(a.id.clone().into_inner()))
           .ok_or_else(|| LemmyError::from_message("page does not specify group"))?
-          .dereference::<LemmyError>(context, local_instance(context), request_counter)
+          .dereference(context, local_instance(context), request_counter)
           .await
       }
     }
@@ -174,10 +190,10 @@ impl Page {
 
 impl Attachment {
   pub(crate) fn new(url: DbUrl) -> Attachment {
-    Attachment {
+    Attachment::Link(Link {
       href: url.into(),
       r#type: Default::default(),
-    }
+    })
   }
 }