From 536048928441a00463238c0466b7034dc375d999 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 5 Jul 2024 03:45:16 +0200 Subject: [PATCH] feat(web): super simple unfollow button --- web/src/actors/header.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/web/src/actors/header.rs b/web/src/actors/header.rs index 4865450c..05842c27 100644 --- a/web/src/actors/header.rs +++ b/web/src/actors/header.rs @@ -85,16 +85,19 @@ pub fn ActorHeader() -> impl IntoView {
- {if followed_by_me { - view! { following }.into_view() - } else { - view! { }.into_view() - }} {if following_me { - Some(view! { follows you }) + Some(view! { follows you }) } else { None }} + {if followed_by_me { + view! { + "following" + + }.into_view() + } else { + view! { }.into_view() + }}

@@ -128,3 +131,20 @@ fn send_follow_request(target: String) { } }) } + +fn unfollow(target: String) { + let auth = use_context::().expect("missing auth context"); + spawn_local(async move { + let payload = apb::new() + .set_activity_type(Some(apb::ActivityType::Undo)) + .set_to(apb::Node::links(vec![target.clone()])) + .set_object(apb::Node::object( + apb::new() + .set_activity_type(Some(apb::ActivityType::Follow)) + .set_object(apb::Node::link(target)) + )); + if let Err(e) = Http::post(&auth.outbox(), &payload, auth).await { + tracing::error!("failed sending follow request: {e}"); + } + }) +}