From 82088596a8c4904a291e550676bca335b39603b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 13 Feb 2020 17:54:44 +0100 Subject: [PATCH] asyncify from_activity calls (i.e.: block_on()) --- plume-models/src/posts.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 73c0c915..b562fe4b 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -21,6 +21,7 @@ use plume_common::{ }; use serde_json; use std::collections::HashSet; +use tokio::runtime::Runtime; pub type LicensedArticle = CustomObject; @@ -579,11 +580,14 @@ impl FromId for Post { } }); - let cover = article + let image = article .object_props .icon_object::() .ok() - .and_then(|img| Media::from_activity(&c, &img).ok().map(|m| m.id)); + .unwrap(); + + let mut r = Runtime::new().unwrap(); + let cover = Some(r.block_on(async {Media::from_activity(&c, &image).await.ok().unwrap().id})); let title = article.object_props.name_string()?; let post = Post::insert( @@ -699,17 +703,21 @@ impl FromId for PostUpdate { } fn from_activity(c: &PlumeRocket, updated: LicensedArticle) -> Result { + let image = updated + .object + .object_props + .icon_object::() + .ok() + .unwrap(); + let mut r = Runtime::new().unwrap(); + let cover = Some(r.block_on(async {Media::from_activity(&c, &image).await.ok().unwrap().id})); + Ok(PostUpdate { ap_url: updated.object.object_props.id_string()?, title: updated.object.object_props.name_string().ok(), subtitle: updated.object.object_props.summary_string().ok(), content: updated.object.object_props.content_string().ok(), - cover: updated - .object - .object_props - .icon_object::() - .ok() - .and_then(|img| Media::from_activity(&c, &img).ok().map(|m| m.id)), + cover: cover, source: updated .object .ap_object_props