use leptos::*; use crate::prelude::*; use apb::{target::Addressed, Base, Activity, Object}; #[component] pub fn ActivityLine(activity: crate::Object) -> impl IntoView { let object_id = activity.object().id().unwrap_or_default(); let activity_url = activity.id().map(|x| view! { "↗" }); let actor_id = activity.actor().id().unwrap_or_default(); let actor = CACHE.get_or(&actor_id, serde_json::Value::String(actor_id.clone()).into()); let kind = activity.activity_type().unwrap_or(apb::ActivityType::Activity); let href = match kind { apb::ActivityType::Follow => Uri::web(U::User, &object_id), // TODO for update check what's being updated _ => Uri::web(U::Object, &object_id), }; view! {
{kind.as_ref().to_string()} {activity_url}
} } #[component] pub fn Item( item: crate::Object, #[prop(optional)] sep: bool, #[prop(optional)] replies: bool, ) -> impl IntoView { let config = use_context::>().expect("missing config context"); let id = item.id().unwrap_or_default().to_string(); let sep = if sep { Some(view! {
}) } else { None }; match item.object_type() { // special case for placeholder activities Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) => (move || { if !config.get().filters.replies && item.in_reply_to().id().is_some() { None } else if config.get().filters.orphans { Some(view! { {sep.clone()} }) } else { None } }).into_view(), // everything else Some(apb::ObjectType::Activity(t)) => (move || { if config.get().filters.visible(apb::ObjectType::Activity(t)) { let object_id = item.object().id().unwrap_or_default(); if !replies && !config.get().filters.replies && CACHE.get(&object_id).map(|x| x.in_reply_to().id().is_some()).unwrap_or(false) { None } else { let object = match t { apb::ActivityType::Create | apb::ActivityType::Announce => CACHE.get(&object_id).map(|obj| { view! { } }.into_view()), apb::ActivityType::Follow => CACHE.get(&object_id).map(|obj| { view! {
} }.into_view()), _ => None, }; Some(view! { {object} {sep.clone()} }) } } else { None } }).into_view(), // should never happen _ => view! {

type not implemented

}.into_view(), } }