]> Untitled Git - lemmy.git/commitdiff
Post thumbnail and user icons federating.
authorDessalines <tyhou13@gmx.com>
Sat, 16 May 2020 00:23:20 +0000 (20:23 -0400)
committerDessalines <tyhou13@gmx.com>
Sat, 16 May 2020 00:23:20 +0000 (20:23 -0400)
server/src/apub/fetcher.rs
server/src/apub/mod.rs
server/src/apub/post.rs
server/src/apub/user.rs

index 994e75f2bbb5a6fcf09730d7d1bccba505ded2cd..ebc6902dc1a61b216245f34e4e835c250b4c2c09 100644 (file)
@@ -130,6 +130,9 @@ pub fn get_or_fetch_and_upsert_remote_user(
       if !u.local
         && u
           .last_refreshed_at
+          // TODO it won't pick up new avatars, summaries etc until a day after.
+          // Both user and community need an "update" action pushed to other servers
+          // to fix this
           .lt(&(naive_now() - chrono::Duration::days(1)))
       {
         debug!("Fetching and updating from remote user: {}", apub_id);
index 9d4a601066d1d1f46ed0b817d70bf404f4d2f25b..51f88df26a13245c0c6e2c9ffc29775761b0f815 100644 (file)
@@ -21,7 +21,7 @@ use activitystreams::{
   endpoint::EndpointProperties,
   ext::{Ext, Extensible},
   link::Mention,
-  object::{properties::ObjectProperties, Note, Page, Tombstone},
+  object::{properties::ObjectProperties, AnyImage, Image, Note, Page, Tombstone},
   public, BaseBox,
 };
 use actix_web::body::Body;
index 3ea2040dce90688c9e09f530703c59a5bde02d02..f2942b84acfd0d9386fa703e1066daa6986c4771 100644 (file)
@@ -53,6 +53,20 @@ impl ToApub for Post {
       oprops.set_url_xsd_any_uri(u.to_owned())?;
     }
 
+    if let Some(thumbnail_url) = &self.thumbnail_url {
+      let full_url = format!(
+        "{}://{}/pictshare/{}",
+        get_apub_protocol_string(),
+        Settings::get().hostname,
+        thumbnail_url
+      );
+
+      let mut image = Image::new();
+      image.object_props.set_url_xsd_any_uri(full_url)?;
+      let any_image = AnyImage::from_concrete(image)?;
+      oprops.set_image_any_image(any_image)?;
+    }
+
     if let Some(u) = self.updated {
       oprops.set_updated(convert_datetime(u))?;
     }
@@ -87,6 +101,16 @@ impl FromApub for PostForm {
     let community_actor_id = &oprops.get_to_xsd_any_uri().unwrap().to_string();
     let community = get_or_fetch_and_upsert_remote_community(&community_actor_id, &conn)?;
 
+    let thumbnail_url = match oprops.get_image_any_image() {
+      Some(any_image) => any_image
+        .to_owned()
+        .into_concrete::<Image>()?
+        .object_props
+        .get_url_xsd_any_uri()
+        .map(|u| u.to_string()),
+      None => None,
+    };
+
     Ok(PostForm {
       name: oprops.get_summary_xsd_string().unwrap().to_string(),
       url: oprops.get_url_xsd_any_uri().map(|u| u.to_string()),
@@ -107,7 +131,7 @@ impl FromApub for PostForm {
       embed_title: None, // -> attachment? or fetch the embed locally
       embed_description: None,
       embed_html: None,
-      thumbnail_url: None,
+      thumbnail_url,
       ap_id: oprops.get_id().unwrap().to_string(),
       local: false,
     })
index 61661de47e2b5a792ebc3496f4d486b930d7f234..395dda9cbd52b1ed093f1a1ef0a725dd6d9559a2 100644 (file)
@@ -27,6 +27,15 @@ impl ToApub for User_ {
       oprops.set_name_xsd_string(i.to_owned())?;
     }
 
+    if let Some(avatar_url) = &self.avatar {
+      let mut image = Image::new();
+      image
+        .object_props
+        .set_url_xsd_any_uri(avatar_url.to_owned())?;
+      let any_image = AnyImage::from_concrete(image)?;
+      oprops.set_icon_any_image(any_image)?;
+    }
+
     let mut endpoint_props = EndpointProperties::default();
 
     endpoint_props.set_shared_inbox(self.get_shared_inbox_url())?;
@@ -152,6 +161,16 @@ impl FromApub for UserForm {
     let aprops = &person.base.extension;
     let public_key: &PublicKey = &person.extension.public_key;
 
+    let avatar = match oprops.get_icon_any_image() {
+      Some(any_image) => any_image
+        .to_owned()
+        .into_concrete::<Image>()?
+        .object_props
+        .get_url_xsd_any_uri()
+        .map(|u| u.to_string()),
+      None => None,
+    };
+
     Ok(UserForm {
       name: oprops.get_name_xsd_string().unwrap().to_string(),
       preferred_username: aprops.get_preferred_username().map(|u| u.to_string()),
@@ -159,7 +178,7 @@ impl FromApub for UserForm {
       admin: false,
       banned: false,
       email: None,
-      avatar: None, // -> icon, image
+      avatar,
       updated: oprops
         .get_updated()
         .map(|u| u.as_ref().to_owned().naive_local()),