diff --git a/crates/contacts_panel/src/contact_notifications.rs b/crates/contacts_panel/src/contact_notifications.rs index 3b31528b71dfd4a21c56a5172c48bf44a8e332a2..e5fff481b0e8ac8a0b1975401d56ae9640030b09 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(); + } }