From 41f97b01f05ef7b82a53002afca65cc014c5b551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Mon, 25 May 2020 20:00:28 +0200 Subject: [PATCH] unroll filter_map() to easier .await --- src/routes/posts.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 9fc0ad51..265522b1 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -1,3 +1,4 @@ +use activitypub::link; use chrono::Utc; use heck::{CamelCase, KebabCase}; use rocket::request::LenientForm; @@ -303,14 +304,16 @@ pub async fn update( .expect("post::update: update error"); if post.published { - post.update_mentions( - &conn, - mentions - .into_iter() - .filter_map(|m| Mention::build_activity(&rockets, &m).await.ok()) - .collect(), - ) - .expect("post::update: mentions error"); + // NOTE: here we unroll a filter_map(), so we can use .await painlessly + let mut filtered_mentions: Vec = vec![]; + for m in mentions.into_iter() { + match Mention::build_activity(&rockets, &m).await { + Ok(m) => filtered_mentions.push(m), + Err(_) => {} + } + } + post.update_mentions(&conn, filtered_mentions) + .expect("post::update: mentions error"); } let tags = form