]> 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 426de96f4cf750281e8bc86c0ea4386d431d852c..1cf55acaa68a94fb4859429996493e43339acafa 100644 (file)
@@ -1,25 +1,29 @@
 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 activitystreams_kinds::link::LinkType;
-use chrono::{DateTime, FixedOffset};
-use itertools::Itertools;
-use lemmy_apub_lib::{
+use activitypub_federation::{
+  core::object_id::ObjectId,
   data::Data,
-  object_id::ObjectId,
+  deser::{
+    helpers::{deserialize_one_or_many, deserialize_skip_error},
+    values::MediaTypeMarkdownOrHtml,
+  },
   traits::{ActivityHandler, ApubObject},
-  values::MediaTypeMarkdownOrHtml,
 };
+use activitystreams_kinds::{link::LinkType, object::ImageType};
+use chrono::{DateTime, FixedOffset};
+use itertools::Itertools;
 use lemmy_db_schema::newtypes::DbUrl;
-use lemmy_utils::LemmyError;
+use lemmy_utils::error::LemmyError;
 use lemmy_websocket::LemmyContext;
 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,
@@ -35,18 +39,18 @@ pub struct Page {
   pub(crate) kind: PageType,
   pub(crate) id: ObjectId<ApubPost>,
   pub(crate) attributed_to: AttributedTo,
-  #[serde(deserialize_with = "crate::deserialize_one_or_many")]
+  #[serde(deserialize_with = "deserialize_one_or_many")]
   pub(crate) to: Vec<Url>,
   pub(crate) name: String,
 
-  #[serde(deserialize_with = "crate::deserialize_one_or_many", default)]
+  #[serde(deserialize_with = "deserialize_one_or_many", default)]
   pub(crate) cc: Vec<Url>,
   pub(crate) content: Option<String>,
   pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>,
-  #[serde(deserialize_with = "crate::deserialize_skip_error", default)]
+  #[serde(deserialize_with = "deserialize_skip_error", default)]
   pub(crate) source: Option<Source>,
   /// deprecated, use attachment field
-  #[serde(deserialize_with = "crate::deserialize_skip_error", default)]
+  #[serde(deserialize_with = "deserialize_skip_error", default)]
   pub(crate) url: Option<Url>,
   /// most software uses array type for attachment field, so we do the same. nevertheless, we only
   /// use the first item
@@ -58,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 {
@@ -135,7 +155,7 @@ impl Page {
           if let Some(cid) = iter.next() {
             let cid = ObjectId::new(cid.clone());
             if let Ok(c) = cid
-              .dereference(context, context.client(), request_counter)
+              .dereference(context, local_instance(context), request_counter)
               .await
             {
               break Ok(c);
@@ -150,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(context, context.client(), request_counter)
+          .dereference(context, local_instance(context), request_counter)
           .await
       }
     }
@@ -170,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(),
-    }
+    })
   }
 }
 
@@ -181,6 +201,13 @@ impl Attachment {
 #[async_trait::async_trait(?Send)]
 impl ActivityHandler for Page {
   type DataType = LemmyContext;
+  type Error = LemmyError;
+  fn id(&self) -> &Url {
+    unimplemented!()
+  }
+  fn actor(&self) -> &Url {
+    unimplemented!()
+  }
   async fn verify(
     &self,
     data: &Data<Self::DataType>,