accept / deny friend requests
This commit is contained in:
+1
-1
Submodule iris updated: 1102dc7338...c118bb446b
@@ -2,4 +2,5 @@ use super::*;
|
||||
|
||||
pub const MODAL_BG: UiColor = UiColor::BLACK.brighter(0.05);
|
||||
pub const GREEN: UiColor = UiColor::rgb(0, 150, 0);
|
||||
pub const RED: UiColor = UiColor::rgb(255, 100, 100);
|
||||
pub const DARK: UiColor = UiColor::BLACK.brighter(0.02);
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
use openworm::net::{AddFriend, AddFriendResp, GenerateToken, RequestFriends, ServerPerms};
|
||||
use openworm::net::{
|
||||
AddFriend, AddFriendResp, AnswerFriendRequest, FriendRequestAction, GenerateToken,
|
||||
RequestFriends, ServerPerms, UserId,
|
||||
};
|
||||
|
||||
use crate::net::NetHandle;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -99,13 +104,34 @@ fn friends_list(rsc: &mut Rsc, session: &Session) -> WeakWidget {
|
||||
let mut all = Span::empty(Dir::DOWN);
|
||||
if !resp.incoming.is_empty() {
|
||||
all.push(section_label("incoming").add_strong(rsc));
|
||||
all.push(user_list(&resp.incoming, &session, rsc).add_strong(rsc))
|
||||
all.push(
|
||||
resp.incoming
|
||||
.rsc_map(|id, rsc| {
|
||||
(
|
||||
user_rect(id, &session, rsc),
|
||||
accept_req(id, &con, rsc),
|
||||
deny_req(id, &con, rsc),
|
||||
)
|
||||
.span(Dir::RIGHT)
|
||||
.add(rsc)
|
||||
})
|
||||
.span(Dir::DOWN)
|
||||
.add_strong(rsc),
|
||||
)
|
||||
}
|
||||
all.push(section_label("friends").add_strong(rsc));
|
||||
all.push(user_list(&resp.current, &session, rsc).add_strong(rsc));
|
||||
all.push(
|
||||
user_list(&resp.current, &session)
|
||||
.span(Dir::DOWN)
|
||||
.add_strong(rsc),
|
||||
);
|
||||
if !resp.outgoing.is_empty() {
|
||||
all.push(section_label("outgoing").add_strong(rsc));
|
||||
all.push(user_list(&resp.outgoing, &session, rsc).add_strong(rsc))
|
||||
all.push(
|
||||
user_list(&resp.outgoing, &session)
|
||||
.span(Dir::DOWN)
|
||||
.add_strong(rsc),
|
||||
)
|
||||
}
|
||||
all.set_ptr(ptr, rsc);
|
||||
});
|
||||
@@ -113,3 +139,33 @@ fn friends_list(rsc: &mut Rsc, session: &Session) -> WeakWidget {
|
||||
});
|
||||
ptr
|
||||
}
|
||||
|
||||
pub fn accept_req(id: UserId, con: &NetHandle, rsc: &mut Rsc) -> WeakWidget {
|
||||
let button = Button::submit("", rsc);
|
||||
let con = con.clone();
|
||||
rsc.events.register(button, Submit, move |_, rsc| {
|
||||
let con = con.clone();
|
||||
rsc.tasks.spawn(async move |_| {
|
||||
con.send(AnswerFriendRequest {
|
||||
id,
|
||||
action: FriendRequestAction::Accept,
|
||||
});
|
||||
});
|
||||
});
|
||||
button.width(60).add(rsc)
|
||||
}
|
||||
|
||||
pub fn deny_req(id: UserId, con: &NetHandle, rsc: &mut Rsc) -> WeakWidget {
|
||||
let button = Button::new("X", color::RED, rsc);
|
||||
let con = con.clone();
|
||||
rsc.events.register(button, Submit, move |_, rsc| {
|
||||
let con = con.clone();
|
||||
rsc.tasks.spawn(async move |_| {
|
||||
con.send(AnswerFriendRequest {
|
||||
id,
|
||||
action: FriendRequestAction::Deny,
|
||||
});
|
||||
});
|
||||
});
|
||||
button.width(60).add(rsc)
|
||||
}
|
||||
|
||||
@@ -152,22 +152,6 @@ pub fn section_label(text: impl Into<String>) -> TextBuilder<Rsc> {
|
||||
wtext(text).size(30)
|
||||
}
|
||||
|
||||
pub fn user_list<'a>(
|
||||
ids: impl IntoIterator<Item = &'a UserId>,
|
||||
session: &Session,
|
||||
rsc: &mut Rsc,
|
||||
) -> Span {
|
||||
let mut span = Span::empty(Dir::DOWN);
|
||||
for id in ids {
|
||||
let thing = (session.username(*id, rsc),)
|
||||
.span(Dir::RIGHT)
|
||||
.gap(30)
|
||||
.pad(15);
|
||||
span.push(thing.add_strong(rsc));
|
||||
}
|
||||
span
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn error(&self, text: &str, rsc: &mut Rsc) {
|
||||
rsc[self.notif].inner = Some(werror(text, rsc));
|
||||
|
||||
@@ -47,3 +47,18 @@ impl Session {
|
||||
wid
|
||||
}
|
||||
}
|
||||
|
||||
pub fn user_list<'a>(
|
||||
ids: impl IntoIterator<Item = &'a UserId>,
|
||||
session: &Session,
|
||||
) -> impl IntoIterator<Item = impl FnOnce(&mut Rsc) -> WeakWidget> {
|
||||
ids.rsc_map(|id, rsc: &mut Rsc| user_rect(*id, session, rsc))
|
||||
}
|
||||
|
||||
pub fn user_rect(id: UserId, session: &Session, rsc: &mut Rsc) -> WeakWidget {
|
||||
(session.username(id, rsc),)
|
||||
.span(Dir::RIGHT)
|
||||
.gap(30)
|
||||
.pad(15)
|
||||
.add(rsc) as WeakWidget
|
||||
}
|
||||
|
||||
@@ -164,6 +164,10 @@ impl ClientHandler {
|
||||
if user.friends.outgoing.contains(&other_id) {
|
||||
reply!(AddFriendResp::AlreadySent);
|
||||
}
|
||||
// TODO: just accept in this case?
|
||||
if user.friends.incoming.contains(&other_id) {
|
||||
reply!(AddFriendResp::AlreadySent);
|
||||
}
|
||||
if other_id == user_id {
|
||||
reply!(AddFriendResp::CannotAddSelf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user