From c71b26478624a3e187fef8687148da17a7c759ba Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 11 May 2022 15:25:33 +0200 Subject: [PATCH] Allow accepting/rejecting incoming requests via notification --- .../src/contact_notifications.rs | 65 ++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/crates/contacts_panel/src/contact_notifications.rs b/crates/contacts_panel/src/contact_notifications.rs index 3b31528b71..e5fff481b0 100644 --- a/crates/contacts_panel/src/contact_notifications.rs +++ b/crates/contacts_panel/src/contact_notifications.rs @@ -7,10 +7,11 @@ use settings::Settings; use std::sync::Arc; use workspace::Notification; -impl_internal_actions!(contact_notifications, [Dismiss]); +impl_internal_actions!(contact_notifications, [Dismiss, RespondToContactRequest]); pub fn init(cx: &mut MutableAppContext) { cx.add_action(IncomingRequestNotification::dismiss); + cx.add_action(IncomingRequestNotification::respond_to_contact_request); } pub struct IncomingRequestNotification { @@ -21,6 +22,12 @@ pub struct IncomingRequestNotification { #[derive(Clone)] struct Dismiss(u64); +#[derive(Clone)] +pub struct RespondToContactRequest { + pub user_id: u64, + pub accept: bool, +} + pub enum Event { Dismiss, } @@ -103,16 +110,44 @@ impl View for IncomingRequestNotification { .with_child( Flex::row() .with_child( - Label::new("Decline".to_string(), theme.button.text.clone()) - .contained() - .with_style(theme.button.container) - .boxed(), + MouseEventHandler::new::( + self.user.id as usize, + cx, + |_, _| { + Label::new("Reject".to_string(), theme.button.text.clone()) + .contained() + .with_style(theme.button.container) + .boxed() + }, + ) + .with_cursor_style(CursorStyle::PointingHand) + .on_click(move |_, cx| { + cx.dispatch_action(RespondToContactRequest { + user_id, + accept: false, + }); + }) + .boxed(), ) .with_child( - Label::new("Accept".to_string(), theme.button.text.clone()) - .contained() - .with_style(theme.button.container) - .boxed(), + MouseEventHandler::new::( + self.user.id as usize, + cx, + |_, _| { + Label::new("Accept".to_string(), theme.button.text.clone()) + .contained() + .with_style(theme.button.container) + .boxed() + }, + ) + .with_cursor_style(CursorStyle::PointingHand) + .on_click(move |_, cx| { + cx.dispatch_action(RespondToContactRequest { + user_id, + accept: true, + }); + }) + .boxed(), ) .aligned() .right() @@ -156,4 +191,16 @@ impl IncomingRequestNotification { }); cx.emit(Event::Dismiss); } + + fn respond_to_contact_request( + &mut self, + action: &RespondToContactRequest, + cx: &mut ViewContext, + ) { + self.user_store + .update(cx, |store, cx| { + store.respond_to_contact_request(action.user_id, action.accept, cx) + }) + .detach(); + } }