forked from alemi/upub
feat(web): super simple unfollow button
This commit is contained in:
parent
1b5ae14b99
commit
5360489284
1 changed files with 26 additions and 6 deletions
|
@ -85,16 +85,19 @@ pub fn ActorHeader() -> impl IntoView {
|
|||
</tr>
|
||||
</table>
|
||||
<div class="rev mr-1" class:hidden=move || !auth.present() || auth.user_id() == uid>
|
||||
{if followed_by_me {
|
||||
view! { <code class="color">following</code> }.into_view()
|
||||
} else {
|
||||
view! { <input type="submit" value="follow" on:click=move |_| send_follow_request(_uid.clone()) /> }.into_view()
|
||||
}}
|
||||
{if following_me {
|
||||
Some(view! { <code class="ml-1 color">follows you</code> })
|
||||
Some(view! { <code class="mr-1 color">follows you</code> })
|
||||
} else {
|
||||
None
|
||||
}}
|
||||
{if followed_by_me {
|
||||
view! {
|
||||
<code class="color">"following"</code>
|
||||
<input type="submit" value="x" on:click=move |_| unfollow(_uid.clone()) />
|
||||
}.into_view()
|
||||
} else {
|
||||
view! { <input type="submit" value="follow" on:click=move |_| send_follow_request(_uid.clone()) /> }.into_view()
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-2 mt-0 center bio" inner_html={mdhtml::safe_html(actor.summary().unwrap_or_default())}></p>
|
||||
|
@ -128,3 +131,20 @@ fn send_follow_request(target: String) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn unfollow(target: String) {
|
||||
let auth = use_context::<Auth>().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}");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue