Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

notification: Remove unreferenced bits (#66294)

Piotr Osiewicz5882c67dc355
diff --git a/Cargo.lock b/Cargo.lock
index de13e50ff4f..ca85074ed1c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -11335,7 +11335,6 @@ name = "notifications"
version = "0.1.0"
dependencies = [
"anyhow",
- "channel",
"client",
"component",
"futures-lite 2.6.1",
diff --git a/crates/collab/tests/integration/notification_tests.rs b/crates/collab/tests/integration/notification_tests.rs
index 27ad30a36e4..44abed46f2d 100644
--- a/crates/collab/tests/integration/notification_tests.rs
+++ b/crates/collab/tests/integration/notification_tests.rs
@@ -48,9 +48,8 @@ async fn test_notifications(
// Client B receives a contact request notification and responds to the
// request, accepting it.
executor.run_until_parked();
- client_b.notification_store().update(cx_b, |store, cx| {
+ client_b.notification_store().read_with(cx_b, |store, _| {
assert_eq!(store.notification_count(), 1);
- assert_eq!(store.unread_notification_count(), 1);
let entry = store.notification_at(0).unwrap();
assert_eq!(
@@ -72,15 +71,19 @@ async fn test_notifications(
}
]
);
-
- store.respond_to_notification(entry.notification.clone(), true, cx);
});
+ client_b
+ .user_store()
+ .update(cx_b, |store, cx| {
+ store.respond_to_contact_request(client_a.id(), true, cx)
+ })
+ .await
+ .unwrap();
// Client B sees the notification is now read, and that they responded.
executor.run_until_parked();
client_b.notification_store().read_with(cx_b, |store, _| {
assert_eq!(store.notification_count(), 1);
- assert_eq!(store.unread_notification_count(), 0);
let entry = store.notification_at(0).unwrap();
assert!(entry.is_read);
@@ -102,7 +105,6 @@ async fn test_notifications(
// Client A receives a notification that client B accepted their request.
client_a.notification_store().read_with(cx_a, |store, _| {
assert_eq!(store.notification_count(), 1);
- assert_eq!(store.unread_notification_count(), 1);
let entry = store.notification_at(0).unwrap();
assert_eq!(
@@ -133,9 +135,8 @@ async fn test_notifications(
// Client B receives a channel invitation notification and responds to the
// invitation, accepting it.
executor.run_until_parked();
- client_b.notification_store().update(cx_b, |store, cx| {
+ client_b.notification_store().read_with(cx_b, |store, _| {
assert_eq!(store.notification_count(), 2);
- assert_eq!(store.unread_notification_count(), 1);
let entry = store.notification_at(0).unwrap();
assert_eq!(
@@ -147,15 +148,19 @@ async fn test_notifications(
}
);
assert!(!entry.is_read);
-
- store.respond_to_notification(entry.notification.clone(), true, cx);
});
+ client_b
+ .channel_store()
+ .update(cx_b, |store, cx| {
+ store.respond_to_channel_invite(channel_id, true, cx)
+ })
+ .await
+ .unwrap();
// Client B sees the notification is now read, and that they responded.
executor.run_until_parked();
client_b.notification_store().read_with(cx_b, |store, _| {
assert_eq!(store.notification_count(), 2);
- assert_eq!(store.unread_notification_count(), 0);
let entry = store.notification_at(0).unwrap();
assert!(entry.is_read);
diff --git a/crates/notifications/Cargo.toml b/crates/notifications/Cargo.toml
index 4ebef126017..406f6ac93b8 100644
--- a/crates/notifications/Cargo.toml
+++ b/crates/notifications/Cargo.toml
@@ -15,15 +15,12 @@ test = false
[features]
test-support = [
- "channel/test-support",
-
"gpui/test-support",
"rpc/test-support",
]
[dependencies]
anyhow.workspace = true
-channel.workspace = true
client.workspace = true
futures-lite.workspace = true
component.workspace = true
diff --git a/crates/notifications/src/notification_store.rs b/crates/notifications/src/notification_store.rs
index 2e23b945a6f..f99f7c59ce1 100644
--- a/crates/notifications/src/notification_store.rs
+++ b/crates/notifications/src/notification_store.rs
@@ -1,6 +1,5 @@
use anyhow::{Context as _, Result};
-use channel::ChannelStore;
-use client::{ChannelId, Client, UserStore};
+use client::{Client, UserStore};
use futures_lite::stream::StreamExt;
use gpui::{App, AppContext as _, AsyncApp, Context, Entity, EventEmitter, Global, Task};
use rpc::{Notification, TypedEnvelope, proto};
@@ -21,7 +20,6 @@ impl Global for GlobalNotificationStore {}
pub struct NotificationStore {
client: Arc<Client>,
user_store: Entity<UserStore>,
- channel_store: Entity<ChannelStore>,
notifications: SumTree<NotificationEntry>,
loaded_all_notifications: bool,
_watch_connection_status: Task<Option<()>>,
@@ -58,7 +56,6 @@ pub struct NotificationEntry {
pub struct NotificationSummary {
max_id: u64,
count: usize,
- unread_count: usize,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
@@ -92,7 +89,6 @@ impl NotificationStore {
});
Self {
- channel_store: ChannelStore::global(cx),
notifications: Default::default(),
loaded_all_notifications: false,
_watch_connection_status: watch_connection_status,
@@ -109,10 +105,6 @@ impl NotificationStore {
self.notifications.summary().count
}
- pub fn unread_notification_count(&self) -> usize {
- self.notifications.summary().unread_count
- }
-
// Get the nth newest notification.
pub fn notification_at(&self, ix: usize) -> Option<&NotificationEntry> {
let count = self.notifications.summary().count;
@@ -125,19 +117,8 @@ impl NotificationStore {
.find::<Count, _>((), &Count(ix), Bias::Right);
item
}
- pub fn notification_for_id(&self, id: u64) -> Option<&NotificationEntry> {
- let (.., item) =
- self.notifications
- .find::<NotificationId, _>((), &NotificationId(id), Bias::Left);
- if let Some(item) = item
- && item.id == id
- {
- return Some(item);
- }
- None
- }
- pub fn load_more_notifications(
+ fn load_more_notifications(
&self,
clear_old: bool,
cx: &mut Context<Self>,
@@ -347,31 +328,6 @@ impl NotificationStore {
new_count,
});
}
-
- pub fn respond_to_notification(
- &mut self,
- notification: Notification,
- response: bool,
- cx: &mut Context<Self>,
- ) {
- match notification {
- Notification::ContactRequest { sender_id } => {
- self.user_store
- .update(cx, |store, cx| {
- store.respond_to_contact_request(sender_id, response, cx)
- })
- .detach();
- }
- Notification::ChannelInvitation { channel_id, .. } => {
- self.channel_store
- .update(cx, |store, cx| {
- store.respond_to_channel_invite(ChannelId(channel_id), response, cx)
- })
- .detach();
- }
- _ => {}
- }
- }
}
impl EventEmitter<NotificationEvent> for NotificationStore {}
@@ -383,7 +339,6 @@ impl sum_tree::Item for NotificationEntry {
NotificationSummary {
max_id: self.id,
count: 1,
- unread_count: if self.is_read { 0 } else { 1 },
}
}
}
@@ -396,7 +351,6 @@ impl sum_tree::ContextLessSummary for NotificationSummary {
fn add_summary(&mut self, summary: &Self) {
self.max_id = self.max_id.max(summary.max_id);
self.count += summary.count;
- self.unread_count += summary.unread_count;
}
}