From c3e319d5a93a483f66e80f9e7d65b46c4d50ae16 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 6 Jul 2024 04:09:35 +0200 Subject: [PATCH] fix(web): iter nodes and links not objects --- web/src/objects/item.rs | 92 ++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/web/src/objects/item.rs b/web/src/objects/item.rs index 2a0cbf0e..1238d48c 100644 --- a/web/src/objects/item.rs +++ b/web/src/objects/item.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use leptos::*; -use regex::Regex; use crate::prelude::*; use apb::{field::OptionalString, target::Addressed, ActivityMut, Base, Collection, CollectionMut, Object, ObjectMut}; @@ -49,48 +48,55 @@ pub fn Object( }); - let hashtag_badges = object.tag().filter_map(|x| { - match apb::Link::link_type(&x) { - Ok(apb::LinkType::Hashtag) => { - let name = apb::Link::name(&x).unwrap_or_default().replace('#', ""); - let href = Uri::web(U::Hashtag, &name); - Some(view! { - - - # - - {name} - - - " " - }) - }, - Ok(apb::LinkType::Mention) => { - let uid = apb::Link::href(&x); - let mention = apb::Link::name(&x).unwrap_or_default().replacen('@', "", 1); - let (username, domain) = if let Some((username, server)) = mention.split_once('@') { - (username.to_string(), server.to_string()) - } else { - ( - mention.to_string(), - uid.replace("https://", "").replace("http://", "").split('/').next().unwrap_or_default().to_string(), - ) - }; - let href = Uri::web(U::Actor, uid); - Some(view! { - - - @ - - {username} - - - " " - }) - }, + let tag_badges = object.tag() + .flat() + .into_iter() + .filter_map(|node| match node { + apb::Node::Link(x) => Some(x), _ => None, - } - }).collect_view(); + }) + .map(|link| { + match apb::Link::link_type(link.as_ref()) { + Ok(apb::LinkType::Hashtag) => { + let name = apb::Link::name(link.as_ref()).unwrap_or_default().replace('#', ""); + let href = Uri::web(U::Hashtag, &name); + Some(view! { + + + # + + {name} + + + " " + }) + }, + Ok(apb::LinkType::Mention) => { + let uid = apb::Link::href(link.as_ref()); + let mention = apb::Link::name(link.as_ref()).unwrap_or_default().replacen('@', "", 1); + let (username, domain) = if let Some((username, server)) = mention.split_once('@') { + (username.to_string(), server.to_string()) + } else { + ( + mention.to_string(), + uid.replace("https://", "").replace("http://", "").split('/').next().unwrap_or_default().to_string(), + ) + }; + let href = Uri::web(U::Actor, uid); + Some(view! { + + + @ + + {username} + + + " " + }) + }, + _ => None, + } + }).collect_view(); let post_image = object.image().get().and_then(|x| x.url().id().str()).map(|x| { let (expand, set_expand) = create_signal(false); @@ -157,7 +163,7 @@ pub fn Object( {post}
- {hashtag_badges} + {tag_badges} {audience_badge}