forked from alemi/upub
feat(web): add accept/reject buttons under folreqs
they never disappear so there's quite some potential for spam but ehh better than nothing for now
This commit is contained in:
parent
b6cac77bf2
commit
b2717223b3
2 changed files with 61 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
use std::{collections::BTreeSet, pin::Pin, sync::Arc};
|
use std::{collections::BTreeSet, pin::Pin, sync::Arc};
|
||||||
|
|
||||||
use apb::{Activity, Base, Object};
|
use apb::{Activity, ActivityMut, Base, Object, ObjectMut};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
@ -168,7 +168,12 @@ pub fn TimelineFeed(tl: Timeline) -> impl IntoView {
|
||||||
}.into_view()),
|
}.into_view()),
|
||||||
apb::ActivityType::Follow =>
|
apb::ActivityType::Follow =>
|
||||||
CACHE.get(&object_id).map(|obj| {
|
CACHE.get(&object_id).map(|obj| {
|
||||||
view! { <div class="ml-1"><ActorBanner object=obj /></div> }
|
view! {
|
||||||
|
<div class="ml-1">
|
||||||
|
<ActorBanner object=obj />
|
||||||
|
<FollowRequestButtons activity_id=id actor_id=object_id />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
}.into_view()),
|
}.into_view()),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
@ -203,7 +208,6 @@ pub fn TimelineFeed(tl: Timeline) -> impl IntoView {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_activities(activities: Vec<serde_json::Value>, auth: Auth) -> Vec<String> {
|
async fn process_activities(activities: Vec<serde_json::Value>, auth: Auth) -> Vec<String> {
|
||||||
use apb::ActivityMut;
|
|
||||||
let mut sub_tasks : Vec<Pin<Box<dyn futures::Future<Output = ()>>>> = Vec::new();
|
let mut sub_tasks : Vec<Pin<Box<dyn futures::Future<Output = ()>>>> = Vec::new();
|
||||||
let mut gonna_fetch = BTreeSet::new();
|
let mut gonna_fetch = BTreeSet::new();
|
||||||
let mut actors_seen = BTreeSet::new();
|
let mut actors_seen = BTreeSet::new();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use apb::{Actor, Base, Object};
|
use apb::{ActivityMut, Actor, Base, Object, ObjectMut};
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn ActorStrip(object: crate::Object) -> impl IntoView {
|
pub fn ActorStrip(object: crate::Object) -> impl IntoView {
|
||||||
|
@ -48,3 +48,56 @@ pub fn ActorBanner(object: crate::Object) -> impl IntoView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
pub fn FollowRequestButtons(activity_id: String, actor_id: String) -> impl IntoView {
|
||||||
|
let auth = use_context::<Auth>().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();
|
||||||
|
if actor_id == auth.user_id() {
|
||||||
|
Some(view! {
|
||||||
|
<input type="submit" value="accept"
|
||||||
|
on:click=move |_| {
|
||||||
|
let activity_id = _activity_id.clone();
|
||||||
|
let actor_id = _actor_id.clone();
|
||||||
|
spawn_local(async move {
|
||||||
|
send_follow_response(
|
||||||
|
apb::ActivityType::Accept(apb::AcceptType::Accept),
|
||||||
|
activity_id,
|
||||||
|
actor_id,
|
||||||
|
auth
|
||||||
|
).await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span class="ma-1"></span>
|
||||||
|
<input type="submit" value="reject"
|
||||||
|
on:click=move |_| {
|
||||||
|
let activity_id = activity_id.clone();
|
||||||
|
let actor_id = actor_id.clone();
|
||||||
|
spawn_local(async move {
|
||||||
|
send_follow_response(
|
||||||
|
apb::ActivityType::Reject(apb::RejectType::Reject),
|
||||||
|
activity_id,
|
||||||
|
actor_id,
|
||||||
|
auth
|
||||||
|
).await
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
})
|
||||||
|
} 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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue