Show contacts panel the first time a new user connects to collab
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
d8ee4378c9
commit
0597c662e4
6 changed files with 95 additions and 33 deletions
|
@ -1,5 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::notifications::render_user_notification;
|
||||
use client::{ContactEvent, ContactEventKind, UserStore};
|
||||
use client::{ContactEventKind, User, UserStore};
|
||||
use gpui::{
|
||||
elements::*, impl_internal_actions, Entity, ModelHandle, MutableAppContext, RenderContext,
|
||||
View, ViewContext,
|
||||
|
@ -15,7 +17,8 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
|
||||
pub struct ContactNotification {
|
||||
user_store: ModelHandle<UserStore>,
|
||||
event: ContactEvent,
|
||||
user: Arc<User>,
|
||||
kind: client::ContactEventKind,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -41,27 +44,27 @@ impl View for ContactNotification {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut RenderContext<Self>) -> ElementBox {
|
||||
match self.event.kind {
|
||||
match self.kind {
|
||||
ContactEventKind::Requested => render_user_notification(
|
||||
self.event.user.clone(),
|
||||
self.user.clone(),
|
||||
"wants to add you as a contact",
|
||||
Some("They won't know if you decline."),
|
||||
RespondToContactRequest {
|
||||
user_id: self.event.user.id,
|
||||
user_id: self.user.id,
|
||||
accept: false,
|
||||
},
|
||||
vec![
|
||||
(
|
||||
"Decline",
|
||||
Box::new(RespondToContactRequest {
|
||||
user_id: self.event.user.id,
|
||||
user_id: self.user.id,
|
||||
accept: false,
|
||||
}),
|
||||
),
|
||||
(
|
||||
"Accept",
|
||||
Box::new(RespondToContactRequest {
|
||||
user_id: self.event.user.id,
|
||||
user_id: self.user.id,
|
||||
accept: true,
|
||||
}),
|
||||
),
|
||||
|
@ -69,10 +72,10 @@ impl View for ContactNotification {
|
|||
cx,
|
||||
),
|
||||
ContactEventKind::Accepted => render_user_notification(
|
||||
self.event.user.clone(),
|
||||
self.user.clone(),
|
||||
"accepted your contact request",
|
||||
None,
|
||||
Dismiss(self.event.user.id),
|
||||
Dismiss(self.user.id),
|
||||
vec![],
|
||||
cx,
|
||||
),
|
||||
|
@ -89,30 +92,35 @@ impl Notification for ContactNotification {
|
|||
|
||||
impl ContactNotification {
|
||||
pub fn new(
|
||||
event: ContactEvent,
|
||||
user: Arc<User>,
|
||||
kind: client::ContactEventKind,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
cx.subscribe(&user_store, move |this, _, event, cx| {
|
||||
if let client::ContactEvent {
|
||||
if let client::Event::Contact {
|
||||
kind: ContactEventKind::Cancelled,
|
||||
user,
|
||||
} = event
|
||||
{
|
||||
if user.id == this.event.user.id {
|
||||
if user.id == this.user.id {
|
||||
cx.emit(Event::Dismiss);
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
||||
Self { event, user_store }
|
||||
Self {
|
||||
user,
|
||||
kind,
|
||||
user_store,
|
||||
}
|
||||
}
|
||||
|
||||
fn dismiss(&mut self, _: &Dismiss, cx: &mut ViewContext<Self>) {
|
||||
self.user_store.update(cx, |store, cx| {
|
||||
store
|
||||
.dismiss_contact_request(self.event.user.id, cx)
|
||||
.dismiss_contact_request(self.user.id, cx)
|
||||
.detach_and_log_err(cx);
|
||||
});
|
||||
cx.emit(Event::Dismiss);
|
||||
|
|
|
@ -158,16 +158,28 @@ impl ContactsPanel {
|
|||
if let Some((workspace, user_store)) =
|
||||
workspace.upgrade(cx).zip(user_store.upgrade(cx))
|
||||
{
|
||||
workspace.update(cx, |workspace, cx| match event.kind {
|
||||
ContactEventKind::Requested | ContactEventKind::Accepted => workspace
|
||||
.show_notification(event.user.id as usize, cx, |cx| {
|
||||
cx.add_view(|cx| {
|
||||
ContactNotification::new(event.clone(), user_store, cx)
|
||||
})
|
||||
}),
|
||||
workspace.update(cx, |workspace, cx| match event {
|
||||
client::Event::Contact { user, kind } => match kind {
|
||||
ContactEventKind::Requested | ContactEventKind::Accepted => workspace
|
||||
.show_notification(user.id as usize, cx, |cx| {
|
||||
cx.add_view(|cx| {
|
||||
ContactNotification::new(
|
||||
user.clone(),
|
||||
*kind,
|
||||
user_store,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
}),
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
});
|
||||
}
|
||||
|
||||
if let client::Event::ShowContacts = event {
|
||||
cx.emit(Event::Activate);
|
||||
}
|
||||
}
|
||||
})
|
||||
.detach();
|
||||
|
@ -801,6 +813,10 @@ impl SidebarItem for ContactsPanel {
|
|||
fn contains_focused_view(&self, cx: &AppContext) -> bool {
|
||||
self.filter_editor.is_focused(cx)
|
||||
}
|
||||
|
||||
fn should_activate_item_on_event(&self, event: &Event, _: &AppContext) -> bool {
|
||||
matches!(event, Event::Activate)
|
||||
}
|
||||
}
|
||||
|
||||
fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Element {
|
||||
|
@ -816,7 +832,9 @@ fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Elemen
|
|||
.with_height(style.button_width)
|
||||
}
|
||||
|
||||
pub enum Event {}
|
||||
pub enum Event {
|
||||
Activate,
|
||||
}
|
||||
|
||||
impl Entity for ContactsPanel {
|
||||
type Event = Event;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue