Connect notification panel to notification toasts

This commit is contained in:
Max Brunsfeld 2023-10-13 11:21:45 -07:00
parent 034e9935d4
commit 8db86dcebf
15 changed files with 272 additions and 178 deletions

View file

@ -26,11 +26,19 @@ impl Database {
&self,
recipient_id: UserId,
limit: usize,
) -> Result<proto::AddNotifications> {
before_id: Option<NotificationId>,
) -> Result<Vec<proto::Notification>> {
self.transaction(|tx| async move {
let mut result = proto::AddNotifications::default();
let mut result = Vec::new();
let mut condition =
Condition::all().add(notification::Column::RecipientId.eq(recipient_id));
if let Some(before_id) = before_id {
condition = condition.add(notification::Column::Id.lt(before_id));
}
let mut rows = notification::Entity::find()
.filter(notification::Column::RecipientId.eq(recipient_id))
.filter(condition)
.order_by_desc(notification::Column::Id)
.limit(limit as u64)
.stream(&*tx)
@ -40,7 +48,7 @@ impl Database {
let Some(kind) = self.notification_kinds_by_id.get(&row.kind) else {
continue;
};
result.notifications.push(proto::Notification {
result.push(proto::Notification {
id: row.id.to_proto(),
kind: kind.to_string(),
timestamp: row.created_at.assume_utc().unix_timestamp() as u64,
@ -49,7 +57,7 @@ impl Database {
actor_id: row.actor_id.map(|id| id.to_proto()),
});
}
result.notifications.reverse();
result.reverse();
Ok(result)
})
.await

View file

@ -70,7 +70,7 @@ pub const CLEANUP_TIMEOUT: Duration = Duration::from_secs(10);
const MESSAGE_COUNT_PER_PAGE: usize = 100;
const MAX_MESSAGE_LEN: usize = 1024;
const INITIAL_NOTIFICATION_COUNT: usize = 30;
const NOTIFICATION_COUNT_PER_PAGE: usize = 50;
lazy_static! {
static ref METRIC_CONNECTIONS: IntGauge =
@ -269,6 +269,7 @@ impl Server {
.add_request_handler(send_channel_message)
.add_request_handler(remove_channel_message)
.add_request_handler(get_channel_messages)
.add_request_handler(get_notifications)
.add_request_handler(link_channel)
.add_request_handler(unlink_channel)
.add_request_handler(move_channel)
@ -579,17 +580,15 @@ impl Server {
this.app_state.db.set_user_connected_once(user_id, true).await?;
}
let (contacts, channels_for_user, channel_invites, notifications) = future::try_join4(
let (contacts, channels_for_user, channel_invites) = future::try_join3(
this.app_state.db.get_contacts(user_id),
this.app_state.db.get_channels_for_user(user_id),
this.app_state.db.get_channel_invites_for_user(user_id),
this.app_state.db.get_notifications(user_id, INITIAL_NOTIFICATION_COUNT)
).await?;
{
let mut pool = this.connection_pool.lock();
pool.add_connection(connection_id, user_id, user.admin);
this.peer.send(connection_id, notifications)?;
this.peer.send(connection_id, build_initial_contacts_update(contacts, &pool))?;
this.peer.send(connection_id, build_initial_channels_update(
channels_for_user,
@ -2099,8 +2098,8 @@ async fn request_contact(
session.peer.send(connection_id, update.clone())?;
session.peer.send(
connection_id,
proto::AddNotifications {
notifications: vec![notification.clone()],
proto::NewNotification {
notification: Some(notification.clone()),
},
)?;
}
@ -2158,8 +2157,8 @@ async fn respond_to_contact_request(
session.peer.send(connection_id, update.clone())?;
session.peer.send(
connection_id,
proto::AddNotifications {
notifications: vec![notification.clone()],
proto::NewNotification {
notification: Some(notification.clone()),
},
)?;
}
@ -3008,6 +3007,26 @@ async fn get_channel_messages(
Ok(())
}
async fn get_notifications(
request: proto::GetNotifications,
response: Response<proto::GetNotifications>,
session: Session,
) -> Result<()> {
let notifications = session
.db()
.await
.get_notifications(
session.user_id,
NOTIFICATION_COUNT_PER_PAGE,
request
.before_id
.map(|id| db::NotificationId::from_proto(id)),
)
.await?;
response.send(proto::GetNotificationsResponse { notifications })?;
Ok(())
}
async fn update_diff_base(request: proto::UpdateDiffBase, session: Session) -> Result<()> {
let project_id = ProjectId::from_proto(request.project_id);
let project_connection_ids = session

View file

@ -1,6 +1,6 @@
use crate::{rpc::RECONNECT_TIMEOUT, tests::TestServer};
use call::ActiveCall;
use collab_ui::project_shared_notification::ProjectSharedNotification;
use collab_ui::notifications::project_shared_notification::ProjectSharedNotification;
use editor::{Editor, ExcerptRange, MultiBuffer};
use gpui::{executor::Deterministic, geometry::vector::vec2f, TestAppContext, ViewHandle};
use live_kit_client::MacOSDisplay;