Connect notification panel to notification toasts
This commit is contained in:
parent
034e9935d4
commit
8db86dcebf
15 changed files with 272 additions and 178 deletions
|
@ -1,10 +1,10 @@
|
|||
use crate::{
|
||||
contact_notification::ContactNotification, face_pile::FacePile, toggle_deafen, toggle_mute,
|
||||
toggle_screen_sharing, LeaveCall, ToggleDeafen, ToggleMute, ToggleScreenSharing,
|
||||
face_pile::FacePile, toggle_deafen, toggle_mute, toggle_screen_sharing, LeaveCall,
|
||||
ToggleDeafen, ToggleMute, ToggleScreenSharing,
|
||||
};
|
||||
use auto_update::AutoUpdateStatus;
|
||||
use call::{ActiveCall, ParticipantLocation, Room};
|
||||
use client::{proto::PeerId, Client, ContactEventKind, SignIn, SignOut, User, UserStore};
|
||||
use client::{proto::PeerId, Client, SignIn, SignOut, User, UserStore};
|
||||
use clock::ReplicaId;
|
||||
use context_menu::{ContextMenu, ContextMenuItem};
|
||||
use gpui::{
|
||||
|
@ -151,28 +151,6 @@ impl CollabTitlebarItem {
|
|||
this.window_activation_changed(active, cx)
|
||||
}));
|
||||
subscriptions.push(cx.observe(&user_store, |_, _, cx| cx.notify()));
|
||||
subscriptions.push(
|
||||
cx.subscribe(&user_store, move |this, user_store, event, cx| {
|
||||
if let Some(workspace) = this.workspace.upgrade(cx) {
|
||||
workspace.update(cx, |workspace, cx| {
|
||||
if let client::Event::Contact { user, kind } = event {
|
||||
if let ContactEventKind::Requested | ContactEventKind::Accepted = kind {
|
||||
workspace.show_notification(user.id as usize, cx, |cx| {
|
||||
cx.add_view(|cx| {
|
||||
ContactNotification::new(
|
||||
user.clone(),
|
||||
*kind,
|
||||
user_store,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
Self {
|
||||
workspace: workspace.weak_handle(),
|
||||
|
|
|
@ -2,13 +2,10 @@ pub mod channel_view;
|
|||
pub mod chat_panel;
|
||||
pub mod collab_panel;
|
||||
mod collab_titlebar_item;
|
||||
mod contact_notification;
|
||||
mod face_pile;
|
||||
mod incoming_call_notification;
|
||||
pub mod notification_panel;
|
||||
mod notifications;
|
||||
pub mod notifications;
|
||||
mod panel_settings;
|
||||
pub mod project_shared_notification;
|
||||
mod sharing_status_indicator;
|
||||
|
||||
use call::{report_call_event_for_room, ActiveCall, Room};
|
||||
|
@ -48,8 +45,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
|||
collab_titlebar_item::init(cx);
|
||||
collab_panel::init(cx);
|
||||
chat_panel::init(cx);
|
||||
incoming_call_notification::init(&app_state, cx);
|
||||
project_shared_notification::init(&app_state, cx);
|
||||
notifications::init(&app_state, cx);
|
||||
sharing_status_indicator::init(cx);
|
||||
|
||||
cx.add_global_action(toggle_screen_sharing);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use crate::{
|
||||
format_timestamp, is_channels_feature_enabled, render_avatar, NotificationPanelSettings,
|
||||
format_timestamp, is_channels_feature_enabled,
|
||||
notifications::contact_notification::ContactNotification, render_avatar,
|
||||
NotificationPanelSettings,
|
||||
};
|
||||
use anyhow::Result;
|
||||
use channel::ChannelStore;
|
||||
|
@ -39,6 +41,7 @@ pub struct NotificationPanel {
|
|||
notification_list: ListState<Self>,
|
||||
pending_serialization: Task<Option<()>>,
|
||||
subscriptions: Vec<gpui::Subscription>,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
local_timezone: UtcOffset,
|
||||
has_focus: bool,
|
||||
}
|
||||
|
@ -64,6 +67,7 @@ impl NotificationPanel {
|
|||
let fs = workspace.app_state().fs.clone();
|
||||
let client = workspace.app_state().client.clone();
|
||||
let user_store = workspace.app_state().user_store.clone();
|
||||
let workspace_handle = workspace.weak_handle();
|
||||
|
||||
let notification_list =
|
||||
ListState::<Self>::new(0, Orientation::Top, 1000., move |this, ix, cx| {
|
||||
|
@ -96,6 +100,7 @@ impl NotificationPanel {
|
|||
notification_store: NotificationStore::global(cx),
|
||||
notification_list,
|
||||
pending_serialization: Task::ready(None),
|
||||
workspace: workspace_handle,
|
||||
has_focus: false,
|
||||
subscriptions: Vec::new(),
|
||||
active: false,
|
||||
|
@ -177,7 +182,7 @@ impl NotificationPanel {
|
|||
let notification_store = self.notification_store.read(cx);
|
||||
let user_store = self.user_store.read(cx);
|
||||
let channel_store = self.channel_store.read(cx);
|
||||
let entry = notification_store.notification_at(ix).unwrap();
|
||||
let entry = notification_store.notification_at(ix)?;
|
||||
let now = OffsetDateTime::now_utc();
|
||||
let timestamp = entry.timestamp;
|
||||
|
||||
|
@ -293,7 +298,7 @@ impl NotificationPanel {
|
|||
&mut self,
|
||||
_: ModelHandle<NotificationStore>,
|
||||
event: &NotificationEvent,
|
||||
_: &mut ViewContext<Self>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
match event {
|
||||
NotificationEvent::NotificationsUpdated {
|
||||
|
@ -301,7 +306,33 @@ impl NotificationPanel {
|
|||
new_count,
|
||||
} => {
|
||||
self.notification_list.splice(old_range.clone(), *new_count);
|
||||
cx.notify();
|
||||
}
|
||||
NotificationEvent::NewNotification { entry } => match entry.notification {
|
||||
Notification::ContactRequest { actor_id }
|
||||
| Notification::ContactRequestAccepted { actor_id } => {
|
||||
let user_store = self.user_store.clone();
|
||||
let Some(user) = user_store.read(cx).get_cached_user(actor_id) else {
|
||||
return;
|
||||
};
|
||||
self.workspace
|
||||
.update(cx, |workspace, cx| {
|
||||
workspace.show_notification(actor_id as usize, cx, |cx| {
|
||||
cx.add_view(|cx| {
|
||||
ContactNotification::new(
|
||||
user.clone(),
|
||||
entry.notification.clone(),
|
||||
user_store,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
Notification::ChannelInvitation { .. } => {}
|
||||
Notification::ChannelMessageMention { .. } => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,23 @@ use client::User;
|
|||
use gpui::{
|
||||
elements::*,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
AnyElement, Element, ViewContext,
|
||||
AnyElement, AppContext, Element, ViewContext,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
use workspace::AppState;
|
||||
|
||||
pub mod contact_notification;
|
||||
pub mod incoming_call_notification;
|
||||
pub mod project_shared_notification;
|
||||
|
||||
enum Dismiss {}
|
||||
enum Button {}
|
||||
|
||||
pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||
incoming_call_notification::init(app_state, cx);
|
||||
project_shared_notification::init(app_state, cx);
|
||||
}
|
||||
|
||||
pub fn render_user_notification<F, V: 'static>(
|
||||
user: Arc<User>,
|
||||
title: &'static str,
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::notifications::render_user_notification;
|
||||
use client::{ContactEventKind, User, UserStore};
|
||||
use gpui::{elements::*, Entity, ModelHandle, View, ViewContext};
|
||||
use std::sync::Arc;
|
||||
use workspace::notifications::Notification;
|
||||
|
||||
pub struct ContactNotification {
|
||||
user_store: ModelHandle<UserStore>,
|
||||
user: Arc<User>,
|
||||
kind: client::ContactEventKind,
|
||||
notification: rpc::Notification,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
|
@ -34,8 +33,8 @@ impl View for ContactNotification {
|
|||
}
|
||||
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
match self.kind {
|
||||
ContactEventKind::Requested => render_user_notification(
|
||||
match self.notification {
|
||||
rpc::Notification::ContactRequest { .. } => render_user_notification(
|
||||
self.user.clone(),
|
||||
"wants to add you as a contact",
|
||||
Some("They won't be alerted if you decline."),
|
||||
|
@ -56,7 +55,7 @@ impl View for ContactNotification {
|
|||
],
|
||||
cx,
|
||||
),
|
||||
ContactEventKind::Accepted => render_user_notification(
|
||||
rpc::Notification::ContactRequestAccepted { .. } => render_user_notification(
|
||||
self.user.clone(),
|
||||
"accepted your contact request",
|
||||
None,
|
||||
|
@ -78,7 +77,7 @@ impl Notification for ContactNotification {
|
|||
impl ContactNotification {
|
||||
pub fn new(
|
||||
user: Arc<User>,
|
||||
kind: client::ContactEventKind,
|
||||
notification: rpc::Notification,
|
||||
user_store: ModelHandle<UserStore>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Self {
|
||||
|
@ -97,7 +96,7 @@ impl ContactNotification {
|
|||
|
||||
Self {
|
||||
user,
|
||||
kind,
|
||||
notification,
|
||||
user_store,
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue