feat(web): super simple unfollow button

This commit is contained in:
əlemi 2024-07-05 03:45:16 +02:00
parent 1b5ae14b99
commit 5360489284
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -85,16 +85,19 @@ pub fn ActorHeader() -> impl IntoView {
</tr> </tr>
</table> </table>
<div class="rev mr-1" class:hidden=move || !auth.present() || auth.user_id() == uid> <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 { {if following_me {
Some(view! { <code class="ml-1 color">follows you</code> }) Some(view! { <code class="mr-1 color">follows you</code> })
} else { } else {
None 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>
</div> </div>
<p class="mb-2 mt-0 center bio" inner_html={mdhtml::safe_html(actor.summary().unwrap_or_default())}></p> <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}");
}
})
}