Fix more issues with the channels panel
* Put the newest notifications at the top * Have at most 1 notification toast, which is non-interactive, but focuses the notification panel on click, and auto-dismisses on a timer.
This commit is contained in:
parent
52834dbf21
commit
660021f5e5
9 changed files with 328 additions and 342 deletions
|
@ -187,6 +187,7 @@ impl Database {
|
|||
rpc::Notification::ChannelInvitation {
|
||||
channel_id: channel_id.to_proto(),
|
||||
channel_name: channel.name,
|
||||
inviter_id: inviter_id.to_proto(),
|
||||
},
|
||||
true,
|
||||
&*tx,
|
||||
|
@ -276,6 +277,7 @@ impl Database {
|
|||
&rpc::Notification::ChannelInvitation {
|
||||
channel_id: channel_id.to_proto(),
|
||||
channel_name: Default::default(),
|
||||
inviter_id: Default::default(),
|
||||
},
|
||||
accept,
|
||||
&*tx,
|
||||
|
@ -292,7 +294,7 @@ impl Database {
|
|||
channel_id: ChannelId,
|
||||
member_id: UserId,
|
||||
remover_id: UserId,
|
||||
) -> Result<()> {
|
||||
) -> Result<Option<NotificationId>> {
|
||||
self.transaction(|tx| async move {
|
||||
self.check_user_is_channel_admin(channel_id, remover_id, &*tx)
|
||||
.await?;
|
||||
|
@ -310,7 +312,17 @@ impl Database {
|
|||
Err(anyhow!("no such member"))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(self
|
||||
.remove_notification(
|
||||
member_id,
|
||||
rpc::Notification::ChannelInvitation {
|
||||
channel_id: channel_id.to_proto(),
|
||||
channel_name: Default::default(),
|
||||
inviter_id: Default::default(),
|
||||
},
|
||||
&*tx,
|
||||
)
|
||||
.await?)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
|
|
@ -2331,7 +2331,8 @@ async fn remove_channel_member(
|
|||
let channel_id = ChannelId::from_proto(request.channel_id);
|
||||
let member_id = UserId::from_proto(request.user_id);
|
||||
|
||||
db.remove_channel_member(channel_id, member_id, session.user_id)
|
||||
let removed_notification_id = db
|
||||
.remove_channel_member(channel_id, member_id, session.user_id)
|
||||
.await?;
|
||||
|
||||
let mut update = proto::UpdateChannels::default();
|
||||
|
@ -2342,7 +2343,18 @@ async fn remove_channel_member(
|
|||
.await
|
||||
.user_connection_ids(member_id)
|
||||
{
|
||||
session.peer.send(connection_id, update.clone())?;
|
||||
session.peer.send(connection_id, update.clone()).trace_err();
|
||||
if let Some(notification_id) = removed_notification_id {
|
||||
session
|
||||
.peer
|
||||
.send(
|
||||
connection_id,
|
||||
proto::DeleteNotification {
|
||||
notification_id: notification_id.to_proto(),
|
||||
},
|
||||
)
|
||||
.trace_err();
|
||||
}
|
||||
}
|
||||
|
||||
response.send(proto::Ack {})?;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use crate::tests::TestServer;
|
||||
use gpui::{executor::Deterministic, TestAppContext};
|
||||
use notifications::NotificationEvent;
|
||||
use parking_lot::Mutex;
|
||||
use rpc::Notification;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -14,6 +16,23 @@ async fn test_notifications(
|
|||
let client_a = server.create_client(cx_a, "user_a").await;
|
||||
let client_b = server.create_client(cx_b, "user_b").await;
|
||||
|
||||
let notification_events_a = Arc::new(Mutex::new(Vec::new()));
|
||||
let notification_events_b = Arc::new(Mutex::new(Vec::new()));
|
||||
client_a.notification_store().update(cx_a, |_, cx| {
|
||||
let events = notification_events_a.clone();
|
||||
cx.subscribe(&cx.handle(), move |_, _, event, _| {
|
||||
events.lock().push(event.clone());
|
||||
})
|
||||
.detach()
|
||||
});
|
||||
client_b.notification_store().update(cx_b, |_, cx| {
|
||||
let events = notification_events_b.clone();
|
||||
cx.subscribe(&cx.handle(), move |_, _, event, _| {
|
||||
events.lock().push(event.clone());
|
||||
})
|
||||
.detach()
|
||||
});
|
||||
|
||||
// Client A sends a contact request to client B.
|
||||
client_a
|
||||
.user_store()
|
||||
|
@ -36,6 +55,18 @@ async fn test_notifications(
|
|||
}
|
||||
);
|
||||
assert!(!entry.is_read);
|
||||
assert_eq!(
|
||||
¬ification_events_b.lock()[0..],
|
||||
&[
|
||||
NotificationEvent::NewNotification {
|
||||
entry: entry.clone(),
|
||||
},
|
||||
NotificationEvent::NotificationsUpdated {
|
||||
old_range: 0..0,
|
||||
new_count: 1
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
store.respond_to_notification(entry.notification.clone(), true, cx);
|
||||
});
|
||||
|
@ -49,6 +80,18 @@ async fn test_notifications(
|
|||
let entry = store.notification_at(0).unwrap();
|
||||
assert!(entry.is_read);
|
||||
assert_eq!(entry.response, Some(true));
|
||||
assert_eq!(
|
||||
¬ification_events_b.lock()[2..],
|
||||
&[
|
||||
NotificationEvent::NotificationRead {
|
||||
entry: entry.clone(),
|
||||
},
|
||||
NotificationEvent::NotificationsUpdated {
|
||||
old_range: 0..1,
|
||||
new_count: 1
|
||||
}
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
// Client A receives a notification that client B accepted their request.
|
||||
|
@ -89,12 +132,13 @@ async fn test_notifications(
|
|||
assert_eq!(store.notification_count(), 2);
|
||||
assert_eq!(store.unread_notification_count(), 1);
|
||||
|
||||
let entry = store.notification_at(1).unwrap();
|
||||
let entry = store.notification_at(0).unwrap();
|
||||
assert_eq!(
|
||||
entry.notification,
|
||||
Notification::ChannelInvitation {
|
||||
channel_id,
|
||||
channel_name: "the-channel".to_string()
|
||||
channel_name: "the-channel".to_string(),
|
||||
inviter_id: client_a.id()
|
||||
}
|
||||
);
|
||||
assert!(!entry.is_read);
|
||||
|
@ -108,7 +152,7 @@ async fn test_notifications(
|
|||
assert_eq!(store.notification_count(), 2);
|
||||
assert_eq!(store.unread_notification_count(), 0);
|
||||
|
||||
let entry = store.notification_at(1).unwrap();
|
||||
let entry = store.notification_at(0).unwrap();
|
||||
assert!(entry.is_read);
|
||||
assert_eq!(entry.response, Some(true));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue