diff --git a/crates/kitsune-core/src/activitypub/mod.rs b/crates/kitsune-core/src/activitypub/mod.rs index be7892f9b..c6a155f38 100644 --- a/crates/kitsune-core/src/activitypub/mod.rs +++ b/crates/kitsune-core/src/activitypub/mod.rs @@ -5,7 +5,7 @@ use crate::{ }; use diesel::{ExpressionMethods, SelectableHelper}; use diesel_async::{AsyncPgConnection, RunQueryDsl}; -use futures_util::future::join_all; +use futures_util::{future::try_join_all, TryFutureExt}; use http::Uri; use iso8601_timestamp::Timestamp; use kitsune_db::{ @@ -81,24 +81,19 @@ async fn handle_custom_emojis( } let futures = emoji_iter.clone().filter_map(|emoji| { - emoji - .id - .as_ref() - .map(|remote_id| fetcher.fetch_emoji(remote_id)) + let remote_id = emoji.id.as_ref()?; + Some(fetcher.fetch_emoji(remote_id).map_ok(move |f| (f, emoji))) }); - let emojis = join_all(futures) - .await - .into_iter() - .collect::, _>>()? + let emojis = try_join_all(futures) + .await? .iter() - .zip(emoji_iter) .map(|(resolved_emoji, emoji_tag)| PostCustomEmoji { post_id, custom_emoji_id: resolved_emoji.id, emoji_text: emoji_tag.name.to_string(), }) - .collect::>(); + .collect::>(); diesel::insert_into(posts_custom_emojis::table) .values(emojis) diff --git a/crates/kitsune-core/src/mapping/activitypub/object.rs b/crates/kitsune-core/src/mapping/activitypub/object.rs index 98305e879..b2fb3c102 100644 --- a/crates/kitsune-core/src/mapping/activitypub/object.rs +++ b/crates/kitsune-core/src/mapping/activitypub/object.rs @@ -275,21 +275,18 @@ impl IntoObject for CustomEmoji { // Officially we don't have any info about remote emojis as we're not the origin // Let's pretend we're not home and do not answer let name = match self.domain { - None => Ok::(format!(":{}:", self.shortcode)), + None => Ok(format!(":{}:", self.shortcode)), Some(_) => Err(ApiError::NotFound), }?; let icon = state .db_pool .with_connection(|db_conn| { - async move { - media_attachments::table - .find(self.media_attachment_id) - .get_result::(db_conn) - .map_err(Error::from) - .and_then(|media_attachment| media_attachment.into_object(state)) - .await - } - .scoped() + media_attachments::table + .find(self.media_attachment_id) + .get_result::(db_conn) + .map_err(Error::from) + .and_then(|media_attachment| media_attachment.into_object(state)) + .scoped() }) .await?; diff --git a/crates/kitsune-core/src/mapping/mastodon/sealed.rs b/crates/kitsune-core/src/mapping/mastodon/sealed.rs index bc1f87e84..c2f60b653 100644 --- a/crates/kitsune-core/src/mapping/mastodon/sealed.rs +++ b/crates/kitsune-core/src/mapping/mastodon/sealed.rs @@ -623,20 +623,21 @@ impl IntoMastodon for (DbCustomEmoji, DbMediaAttachment, Option) { } async fn into_mastodon(self, state: MapperState<'_>) -> Result { - let shortcode = if let Some(ref domain) = self.0.domain { - format!(":{}@{}:", self.0.shortcode, domain) + let (emoji, attachment, last_used) = self; + let shortcode = if let Some(ref domain) = emoji.domain { + format!(":{}@{}:", emoji.shortcode, domain) } else { - format!(":{}:", self.0.shortcode) + format!(":{}:", emoji.shortcode) }; - let url = state.url_service.media_url(self.1.id); - let category = if self.2.is_some() { + let url = state.url_service.media_url(attachment.id); + let category = if last_used.is_some() { Some(String::from("recently used")) - } else if self.0.endorsed { + } else if emoji.endorsed { Some(String::from("endorsed")) - } else if self.0.domain.is_none() { + } else if emoji.domain.is_none() { Some(String::from("local")) } else { - Some(self.0.domain.unwrap()) + Some(emoji.domain.unwrap()) }; Ok(CustomEmoji { shortcode, diff --git a/crates/kitsune-core/src/service/custom_emoji.rs b/crates/kitsune-core/src/service/custom_emoji.rs index eae41dca6..d5731737e 100644 --- a/crates/kitsune-core/src/service/custom_emoji.rs +++ b/crates/kitsune-core/src/service/custom_emoji.rs @@ -97,8 +97,7 @@ impl CustomEmojiService { pub async fn get_by_id(&self, id: Uuid) -> Result { let query = custom_emojis::table .find(id) - .select(CustomEmoji::as_select()) - .into_boxed(); + .select(CustomEmoji::as_select()); self.db_pool .with_connection(|db_conn| async move { query.get_result(db_conn).await }.scoped()) @@ -137,8 +136,7 @@ impl CustomEmojiService { MediaAttachment::as_select(), posts::created_at.nullable(), )) - .limit(get_emoji_list.limit) - .into_boxed(); + .limit(get_emoji_list.limit); self.db_pool .with_connection(|db_conn| { diff --git a/lib/post-process/src/lib.rs b/lib/post-process/src/lib.rs index 2719db8d4..00e967226 100644 --- a/lib/post-process/src/lib.rs +++ b/lib/post-process/src/lib.rs @@ -42,13 +42,8 @@ fn enforce_prefix<'a>(lexer: &Lexer<'a, PostElement<'a>>) -> bool { } #[inline] -fn emoji_split<'a>(lexer: &Lexer<'a, PostElement<'a>>) -> Option<(&'a str, Option<&'a str>)> { - if !enforce_prefix(lexer) || !enforce_postfix(lexer) { - return None; - } - - let slice = lexer.slice(); - let slice = slice.trim_matches(':'); +fn emoji_split<'a>(lexer: &Lexer<'a, PostElement<'a>>) -> (&'a str, Option<&'a str>) { + let slice = lexer.slice().trim_matches(':'); let emoji_data = if let Some((shortcode, domain)) = slice.split_once('@') { (shortcode, Some(domain)) @@ -56,7 +51,7 @@ fn emoji_split<'a>(lexer: &Lexer<'a, PostElement<'a>>) -> Option<(&'a str, Optio (slice, None) }; - Some(emoji_data) + emoji_data } #[inline]