fix(web): iter nodes and links not objects

This commit is contained in:
əlemi 2024-07-06 04:09:35 +02:00
parent 141946444f
commit c3e319d5a9
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,7 +1,6 @@
use std::sync::Arc; use std::sync::Arc;
use leptos::*; use leptos::*;
use regex::Regex;
use crate::prelude::*; use crate::prelude::*;
use apb::{field::OptionalString, target::Addressed, ActivityMut, Base, Collection, CollectionMut, Object, ObjectMut}; use apb::{field::OptionalString, target::Addressed, ActivityMut, Base, Collection, CollectionMut, Object, ObjectMut};
@ -49,10 +48,17 @@ pub fn Object(
</a> </a>
}); });
let hashtag_badges = object.tag().filter_map(|x| { let tag_badges = object.tag()
match apb::Link::link_type(&x) { .flat()
.into_iter()
.filter_map(|node| match node {
apb::Node::Link(x) => Some(x),
_ => None,
})
.map(|link| {
match apb::Link::link_type(link.as_ref()) {
Ok(apb::LinkType::Hashtag) => { Ok(apb::LinkType::Hashtag) => {
let name = apb::Link::name(&x).unwrap_or_default().replace('#', ""); let name = apb::Link::name(link.as_ref()).unwrap_or_default().replace('#', "");
let href = Uri::web(U::Hashtag, &name); let href = Uri::web(U::Hashtag, &name);
Some(view! { Some(view! {
<a class="clean dim" href={href}> <a class="clean dim" href={href}>
@ -66,8 +72,8 @@ pub fn Object(
}) })
}, },
Ok(apb::LinkType::Mention) => { Ok(apb::LinkType::Mention) => {
let uid = apb::Link::href(&x); let uid = apb::Link::href(link.as_ref());
let mention = apb::Link::name(&x).unwrap_or_default().replacen('@', "", 1); let mention = apb::Link::name(link.as_ref()).unwrap_or_default().replacen('@', "", 1);
let (username, domain) = if let Some((username, server)) = mention.split_once('@') { let (username, domain) = if let Some((username, server)) = mention.split_once('@') {
(username.to_string(), server.to_string()) (username.to_string(), server.to_string())
} else { } else {
@ -157,7 +163,7 @@ pub fn Object(
</table> </table>
{post} {post}
<div class="mt-s ml-1 rev"> <div class="mt-s ml-1 rev">
{hashtag_badges} {tag_badges}
{audience_badge} {audience_badge}
<span style="white-space:nowrap"> <span style="white-space:nowrap">
<ReplyButton n=comments target=oid.clone() /> <ReplyButton n=comments target=oid.clone() />