use leptos::*; use crate::{prelude::*, DEFAULT_AVATAR_URL}; use apb::{field::OptionalString, Activity, ActivityMut, Actor, Base, Object, ObjectMut}; #[component] pub fn ActorStrip(object: crate::Object) -> impl IntoView { let actor_id = object.id().unwrap_or_default().to_string(); let username = object.preferred_username().unwrap_or_default().to_string(); let domain = object.id().unwrap_or_default().replace("https://", "").split('/').next().unwrap_or_default().to_string(); let avatar = object.icon().get().map(|x| x.url().id().str().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); view! { {username}@{domain} } } #[component] pub fn ActorBanner(object: crate::Object) -> impl IntoView { match object.as_ref() { serde_json::Value::String(id) => view! {
?" "{Uri::pretty(id)}
}, serde_json::Value::Object(_) => { let uid = object.id().unwrap_or_default().to_string(); let uri = Uri::web(U::Actor, &uid); let avatar_url = object.icon().get().map(|x| x.url().id().str().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); let display_name = object.name().unwrap_or_default().to_string(); let username = object.preferred_username().unwrap_or_default().to_string(); let domain = object.id().unwrap_or_default().replace("https://", "").split('/').next().unwrap_or_default().to_string(); view! {
{display_name}
{username}@{domain}
} }, _ => view! {
invalid actor
} } } #[component] pub fn FollowRequestButtons(activity_id: String, actor_id: String) -> impl IntoView { let auth = use_context::().expect("missing auth context"); // TODO lmao what is going on with this double move / triple clone ??????????? let _activity_id = activity_id.clone(); let _actor_id = actor_id.clone(); let from_actor = CACHE.get(&activity_id).map(|x| x.actor().id().str().unwrap_or_default()).unwrap_or_default(); let _from_actor = from_actor.clone(); if actor_id == auth.user_id() { Some(view! { }) } else { None } } async fn send_follow_response(kind: apb::ActivityType, target: String, to: String, auth: Auth) { let payload = serde_json::Value::Object(serde_json::Map::default()) .set_activity_type(Some(kind)) .set_object(apb::Node::link(target)) .set_to(apb::Node::links(vec![to])); if let Err(e) = Http::post(&auth.outbox(), &payload, auth).await { tracing::error!("failed posting follow response: {e}"); } } #[component] pub fn ActorHeader(object: crate::Object) -> impl IntoView { let auth = use_context::().expect("missing auth context"); let avatar_url = object.icon().get().map(|x| x.url().id().str().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); let background_url = object.image().get().map(|x| x.url().id().str().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); let display_name = object.name().unwrap_or_default().to_string(); let username = object.preferred_username().unwrap_or_default().to_string(); let created = object.published().ok(); let following = object.following_count().unwrap_or(0); let followers = object.followers_count().unwrap_or(0); let statuses = object.statuses_count().unwrap_or(0); let following_me = object.following_me().unwrap_or(false); let followed_by_me = object.followed_by_me().unwrap_or(false); let domain = object.id().unwrap_or_default().replace("https://", "").split('/').next().unwrap_or_default().to_string(); let actor_type = object.actor_type().unwrap_or(apb::ActorType::Person); let actor_type_tag = if actor_type == apb::ActorType::Person { None } else { Some(view! { "["{actor_type.as_ref().to_lowercase()}"]" } ) }; let uid = object.id().unwrap_or_default().to_string(); let web_path = Uri::web(U::Actor, &uid); let _uid = uid.clone(); view! {
{display_name}{actor_type_tag} {statuses}" ""\u{1f582}"
{username.clone()}@{domain} {following}" ""👥"
{followers}" ""📢"
{if followed_by_me { view! { following }.into_view() } else { view! { }.into_view() }} {if following_me { Some(view! { follows you }) } else { None }}
}.into_view() } fn send_follow_request(target: String) { let auth = use_context::().expect("missing auth context"); spawn_local(async move { let payload = serde_json::Value::Object(serde_json::Map::default()) .set_activity_type(Some(apb::ActivityType::Follow)) .set_object(apb::Node::link(target.clone())) .set_to(apb::Node::links(vec![target])); if let Err(e) = Http::post(&auth.outbox(), &payload, auth).await { tracing::error!("failed sending follow request: {e}"); } }) }