BlueGit

ict rusty-teams

fix(notify): count the taskbar badge like Teams

- badge = unread Activity rows + unread unmuted chats, plain unread channels no longer count
- with the adaptive rail on, add one per channel with an unread mention (Teams totalChannelsWithActivityCount)
- read hasUserEnabledAdaptiveRailForDesktop from simpleCollabUserSettings and keep it in meta
- muted chats never count as chats, their mentions count via Activity

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
0a54bb256995c8473731ade14fef62e6e665f5f9
Parent
413e4e58
8 files changed +186 −43
crates/app-state/src/activity/feed.rs +5 −1
@@ -261,7 +261,11 @@ impl Feed {
261 261 }
262 262
263 263 pub fn unread_count(&self) -> usize {
264 self.entries.iter().filter(|entry| !entry.read).count()
264 self.unread_entries().count()
265 }
266
267 pub fn unread_entries(&self) -> impl Iterator<Item = &Entry> {
268 self.entries.iter().filter(|entry| !entry.read)
265 269 }
266 270
267 271 pub fn take_dirty(&mut self) -> Vec<Entry> {
@@ -261,7 +261,11 @@ impl Feed {
261 }
261 }
262
262
263 pub fn unread_count(&self) -> usize {
263 pub fn unread_count(&self) -> usize {
264 self.entries.iter().filter(|entry| !entry.read).count()
264 self.unread_entries().count()
265 }
266
267 pub fn unread_entries(&self) -> impl Iterator<Item = &Entry> {
268 self.entries.iter().filter(|entry| !entry.read)
265 }
269 }
266
270
267 pub fn take_dirty(&mut self) -> Vec<Entry> {
271 pub fn take_dirty(&mut self) -> Vec<Entry> {
crates/app-state/src/notify/mod.rs +2 −0
@@ -3,6 +3,7 @@ pub mod layout;
3 3 pub mod rules;
4 4 pub mod settings;
5 5 pub mod stack;
6 pub mod taskbar;
6 7 pub mod text;
7 8
8 9 pub use app_base::notify::{badge, platform, sound_cache, sounds};
@@ -11,3 +12,4 @@ pub use incoming::{IncomingTracker, LateArrivals, preview_of};
11 12 #[cfg(windows)]
12 13 pub use platform::native_handle;
13 14 pub use rules::{ChatKind, Incoming, Preview, alerts};
15 pub use taskbar::taskbar_badge_count;
@@ -3,6 +3,7 @@ pub mod layout;
3pub mod rules;
3pub mod rules;
4pub mod settings;
4pub mod settings;
5pub mod stack;
5pub mod stack;
6pub mod taskbar;
6pub mod text;
7pub mod text;
7
8
8pub use app_base::notify::{badge, platform, sound_cache, sounds};
9pub use app_base::notify::{badge, platform, sound_cache, sounds};
@@ -11,3 +12,4 @@ pub use incoming::{IncomingTracker, LateArrivals, preview_of};
11#[cfg(windows)]
12#[cfg(windows)]
12pub use platform::native_handle;
13pub use platform::native_handle;
13pub use rules::{ChatKind, Incoming, Preview, alerts};
14pub use rules::{ChatKind, Incoming, Preview, alerts};
15pub use taskbar::taskbar_badge_count;
crates/app-state/src/notify/taskbar.rs added +127 −0
@@ -0,0 +1,127 @@
1 use std::collections::HashSet;
2
3 use store::Sidebar;
4
5 use crate::activity::Kind;
6 use crate::activity::feed::Feed;
7 use crate::sidebar_model::unread_chat_count;
8
9 pub fn taskbar_badge_count(sidebar: &Sidebar, feed: &Feed, adaptive_rail: bool) -> usize {
10 let channel_ids: HashSet<&str> = sidebar
11 .teams
12 .iter()
13 .flat_map(|team| team.channels.iter())
14 .map(|channel| channel.id.as_str())
15 .collect();
16 let is_channel = |conversation_id: &str| channel_ids.contains(conversation_id);
17 let activity = feed
18 .unread_entries()
19 .filter(|entry| entry.kind != Kind::Messages || is_channel(&entry.conversation_id))
20 .count();
21 let channels_with_mentions = if adaptive_rail {
22 feed.unread_entries()
23 .filter(|entry| entry.kind == Kind::Mention && is_channel(&entry.conversation_id))
24 .map(|entry| entry.conversation_id.as_str())
25 .collect::<HashSet<_>>()
26 .len()
27 } else {
28 0
29 };
30 activity + unread_chat_count(&sidebar.chats) as usize + channels_with_mentions
31 }
32
33 #[cfg(test)]
34 mod tests {
35 use chrono::Utc;
36 use store::{ChannelRecord, ChatRecord, SidebarTeam, TeamRecord};
37
38 use super::*;
39 use crate::activity::Entry;
40
41 fn sidebar() -> Sidebar {
42 let chat = |id: &str, unread: bool, muted: bool| ChatRecord {
43 id: id.into(),
44 unread,
45 muted,
46 ..Default::default()
47 };
48 let channel = |id: &str| ChannelRecord {
49 id: id.into(),
50 team_id: "team".into(),
51 name: id.into(),
52 membership_type: None,
53 last_message_at: None,
54 unread: true,
55 };
56 Sidebar {
57 chats: vec![
58 chat("chat-unread", true, false),
59 chat("chat-muted", true, true),
60 chat("chat-read", false, false),
61 ],
62 teams: vec![SidebarTeam {
63 team: TeamRecord {
64 id: "team".into(),
65 name: "Team".into(),
66 },
67 channels: vec![channel("channel-a"), channel("channel-b")],
68 hidden: false,
69 hidden_channel_ids: vec!["channel-b".into()],
70 notifications: Default::default(),
71 }],
72 }
73 }
74
75 fn feed(entries: &[(&str, Kind, bool)]) -> Feed {
76 let mut feed = Feed::load(Vec::new());
77 for (conversation_id, kind, read) in entries {
78 feed.add(Entry {
79 id: 0,
80 conversation_id: (*conversation_id).into(),
81 kind: *kind,
82 message_id: String::new(),
83 actors: Vec::new(),
84 preview: String::new(),
85 glyphs: Vec::new(),
86 count: 1,
87 updated_at: Utc::now(),
88 read: *read,
89 });
90 }
91 feed
92 }
93
94 #[test]
95 fn unread_channel_posts_without_activity_do_not_count() {
96 assert_eq!(taskbar_badge_count(&sidebar(), &feed(&[]), true), 1);
97 }
98
99 #[test]
100 fn muted_chats_never_count_as_chats() {
101 let mentioned = feed(&[("chat-muted", Kind::Mention, false)]);
102 assert_eq!(taskbar_badge_count(&sidebar(), &mentioned, false), 2);
103 }
104
105 #[test]
106 fn chat_message_rows_are_counted_once_by_the_chat() {
107 let rows = feed(&[
108 ("chat-unread", Kind::Messages, false),
109 ("chat-unread", Kind::Reaction, false),
110 ("channel-a", Kind::Messages, false),
111 ("channel-a", Kind::Reaction, true),
112 ]);
113 assert_eq!(taskbar_badge_count(&sidebar(), &rows, false), 3);
114 }
115
116 #[test]
117 fn the_adaptive_rail_adds_one_per_channel_with_an_unread_mention() {
118 let mentions = feed(&[
119 ("channel-a", Kind::Mention, false),
120 ("channel-a", Kind::Mention, false),
121 ("channel-b", Kind::Mention, false),
122 ("chat-unread", Kind::Mention, false),
123 ]);
124 assert_eq!(taskbar_badge_count(&sidebar(), &mentions, false), 5);
125 assert_eq!(taskbar_badge_count(&sidebar(), &mentions, true), 7);
126 }
127 }
@@ -0,0 +1,127 @@
1use std::collections::HashSet;
2
3use store::Sidebar;
4
5use crate::activity::Kind;
6use crate::activity::feed::Feed;
7use crate::sidebar_model::unread_chat_count;
8
9pub fn taskbar_badge_count(sidebar: &Sidebar, feed: &Feed, adaptive_rail: bool) -> usize {
10 let channel_ids: HashSet<&str> = sidebar
11 .teams
12 .iter()
13 .flat_map(|team| team.channels.iter())
14 .map(|channel| channel.id.as_str())
15 .collect();
16 let is_channel = |conversation_id: &str| channel_ids.contains(conversation_id);
17 let activity = feed
18 .unread_entries()
19 .filter(|entry| entry.kind != Kind::Messages || is_channel(&entry.conversation_id))
20 .count();
21 let channels_with_mentions = if adaptive_rail {
22 feed.unread_entries()
23 .filter(|entry| entry.kind == Kind::Mention && is_channel(&entry.conversation_id))
24 .map(|entry| entry.conversation_id.as_str())
25 .collect::<HashSet<_>>()
26 .len()
27 } else {
28 0
29 };
30 activity + unread_chat_count(&sidebar.chats) as usize + channels_with_mentions
31}
32
33#[cfg(test)]
34mod tests {
35 use chrono::Utc;
36 use store::{ChannelRecord, ChatRecord, SidebarTeam, TeamRecord};
37
38 use super::*;
39 use crate::activity::Entry;
40
41 fn sidebar() -> Sidebar {
42 let chat = |id: &str, unread: bool, muted: bool| ChatRecord {
43 id: id.into(),
44 unread,
45 muted,
46 ..Default::default()
47 };
48 let channel = |id: &str| ChannelRecord {
49 id: id.into(),
50 team_id: "team".into(),
51 name: id.into(),
52 membership_type: None,
53 last_message_at: None,
54 unread: true,
55 };
56 Sidebar {
57 chats: vec![
58 chat("chat-unread", true, false),
59 chat("chat-muted", true, true),
60 chat("chat-read", false, false),
61 ],
62 teams: vec![SidebarTeam {
63 team: TeamRecord {
64 id: "team".into(),
65 name: "Team".into(),
66 },
67 channels: vec![channel("channel-a"), channel("channel-b")],
68 hidden: false,
69 hidden_channel_ids: vec!["channel-b".into()],
70 notifications: Default::default(),
71 }],
72 }
73 }
74
75 fn feed(entries: &[(&str, Kind, bool)]) -> Feed {
76 let mut feed = Feed::load(Vec::new());
77 for (conversation_id, kind, read) in entries {
78 feed.add(Entry {
79 id: 0,
80 conversation_id: (*conversation_id).into(),
81 kind: *kind,
82 message_id: String::new(),
83 actors: Vec::new(),
84 preview: String::new(),
85 glyphs: Vec::new(),
86 count: 1,
87 updated_at: Utc::now(),
88 read: *read,
89 });
90 }
91 feed
92 }
93
94 #[test]
95 fn unread_channel_posts_without_activity_do_not_count() {
96 assert_eq!(taskbar_badge_count(&sidebar(), &feed(&[]), true), 1);
97 }
98
99 #[test]
100 fn muted_chats_never_count_as_chats() {
101 let mentioned = feed(&[("chat-muted", Kind::Mention, false)]);
102 assert_eq!(taskbar_badge_count(&sidebar(), &mentioned, false), 2);
103 }
104
105 #[test]
106 fn chat_message_rows_are_counted_once_by_the_chat() {
107 let rows = feed(&[
108 ("chat-unread", Kind::Messages, false),
109 ("chat-unread", Kind::Reaction, false),
110 ("channel-a", Kind::Messages, false),
111 ("channel-a", Kind::Reaction, true),
112 ]);
113 assert_eq!(taskbar_badge_count(&sidebar(), &rows, false), 3);
114 }
115
116 #[test]
117 fn the_adaptive_rail_adds_one_per_channel_with_an_unread_mention() {
118 let mentions = feed(&[
119 ("channel-a", Kind::Mention, false),
120 ("channel-a", Kind::Mention, false),
121 ("channel-b", Kind::Mention, false),
122 ("chat-unread", Kind::Mention, false),
123 ]);
124 assert_eq!(taskbar_badge_count(&sidebar(), &mentions, false), 5);
125 assert_eq!(taskbar_badge_count(&sidebar(), &mentions, true), 7);
126 }
127}
crates/app/src/notify/center.rs +32 −38
@@ -22,8 +22,10 @@ use super::settings_view::{Section, SettingsView};
22 22 use super::stack::{
23 23 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
24 24 };
25 use super::taskbar::taskbar_badge_count;
25 26 use super::text::describe;
26 27 use super::toast::{PillView, ToastView};
28 use crate::activity::ActivityCenter;
27 29 use crate::agents::{AgentRun, AgentRunsEvent, RunState};
28 30 use crate::app_state::{AppEvent, AppState, selection_for};
29 31 use crate::call::DemoScene;
@@ -65,6 +67,7 @@ impl OpenWindow {
65 67
66 68 pub struct NotificationCenter {
67 69 app: Entity<AppState>,
70 activity: Entity<ActivityCenter>,
68 71 main_window: AnyWindowHandle,
69 72 main_native: Option<NativeHandle>,
70 73 settings: Settings,
@@ -90,11 +93,17 @@ pub struct NotificationCenter {
90 93 shown_badge: Option<Badge>,
91 94 animations: bool,
92 95 _subscription: Subscription,
96 _activity_observation: Subscription,
93 97 _agent_subscription: Option<Subscription>,
94 98 }
95 99
96 100 impl NotificationCenter {
97 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
101 pub fn new(
102 app: Entity<AppState>,
103 activity: Entity<ActivityCenter>,
104 window: &mut Window,
105 cx: &mut Context<Self>,
106 ) -> Self {
98 107 let settings = settings::load(&app.read(cx).store);
99 108 let tray = if app.read(cx).mode.demo {
100 109 None
@@ -104,6 +113,7 @@ impl NotificationCenter {
104 113 let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {
105 114 this.on_app_event(event, cx);
106 115 });
116 let activity_observation = cx.observe(&activity, |this, _, cx| this.refresh_badge(cx));
107 117 let agent_subscription = crate::agents::runs_handle(cx).map(|runs| {
108 118 cx.subscribe(&runs, |this, runs, event: &AgentRunsEvent, cx| {
109 119 if let AgentRunsEvent::Finished(run_id) = event
@@ -139,7 +149,9 @@ impl NotificationCenter {
139 149 shown_badge: None,
140 150 animations: platform::animations_enabled(),
141 151 app,
152 activity,
142 153 _subscription: subscription,
154 _activity_observation: activity_observation,
143 155 _agent_subscription: agent_subscription,
144 156 };
145 157 cx.spawn(async move |this, cx| {
@@ -901,10 +913,15 @@ impl NotificationCenter {
901 913 }
902 914
903 915 fn refresh_badge(&mut self, cx: &mut Context<Self>) {
904 let (count, still_unread) =
905 unread_summary(&self.app.read(cx).sidebar, &self.unread_mentions);
916 let state = self.app.read(cx);
917 let count = taskbar_badge_count(
918 &state.sidebar,
919 self.activity.read(cx).feed(),
920 state.directory.section_settings.adaptive_rail(),
921 );
922 let still_unread = unread_conversation_ids(&state.sidebar);
906 923 self.unread_mentions
907 .retain(|conversation_id| still_unread.contains(conversation_id));
924 .retain(|conversation_id| still_unread.contains(conversation_id.as_str()));
908 925 let badge = badge_for(count);
909 926 if badge == self.shown_badge {
910 927 return;
@@ -1268,31 +1285,17 @@ fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
1268 1285 }
1269 1286 }
1270 1287
1271 pub fn unread_summary(
1272 sidebar: &Sidebar,
1273 unread_mentions: &HashSet<String>,
1274 ) -> (usize, HashSet<String>) {
1288 pub fn unread_conversation_ids(sidebar: &Sidebar) -> HashSet<&str> {
1275 1289 let chats = sidebar.chats.iter().filter(|chat| chat.unread);
1276 1290 let channels = sidebar
1277 1291 .teams
1278 1292 .iter()
1279 1293 .flat_map(|team| team.channels.iter())
1280 1294 .filter(|channel| channel.unread);
1281 let silenced_chat_ids: HashSet<&str> = sidebar
1282 .chats
1283 .iter()
1284 .filter(|chat| chat.muted && !unread_mentions.contains(&chat.id))
1295 chats
1285 1296 .map(|chat| chat.id.as_str())
1286 .collect();
1287 let ids: HashSet<String> = chats
1288 .map(|chat| chat.id.clone())
1289 .chain(channels.map(|channel| channel.id.clone()))
1290 .collect();
1291 let counted = ids
1292 .iter()
1293 .filter(|id| !silenced_chat_ids.contains(id.as_str()))
1294 .count();
1295 (counted, ids)
1297 .chain(channels.map(|channel| channel.id.as_str()))
1298 .collect()
1296 1299 }
1297 1300
1298 1301 fn demo_incoming() -> Vec<Incoming> {
@@ -1367,7 +1370,7 @@ mod tests {
1367 1370
1368 1371 use std::collections::HashSet;
1369 1372
1370 use super::{preview_lines, unread_summary};
1373 use super::{preview_lines, unread_conversation_ids};
1371 1374 use store::Sidebar;
1372 1375
1373 1376 fn sidebar() -> Sidebar {
@@ -1405,21 +1408,12 @@ mod tests {
1405 1408 }
1406 1409
1407 1410 #[test]
1408 fn unread_summary_counts_chats_and_channels() {
1409 let (count, ids) = unread_summary(&sidebar(), &HashSet::new());
1410 assert_eq!(count, 2);
1411 assert!(ids.contains("a") && ids.contains("ch"));
1412 }
1413
1414 #[test]
1415 fn muted_chats_only_count_with_an_unread_mention() {
1416 let mut quiet = sidebar();
1417 quiet.chats[0].muted = true;
1418 let (count, ids) = unread_summary(&quiet, &HashSet::new());
1419 assert_eq!(count, 1);
1420 assert!(ids.contains("a"));
1421 let (count, _) = unread_summary(&quiet, &HashSet::from(["a".to_owned()]));
1422 assert_eq!(count, 2);
1411 fn unread_conversation_ids_hold_chats_and_channels() {
1412 let sidebar = sidebar();
1413 assert_eq!(
1414 unread_conversation_ids(&sidebar),
1415 HashSet::from(["a", "ch"])
1416 );
1423 1417 }
1424 1418
1425 1419 #[gpui_kit::test]
@@ -22,8 +22,10 @@ use super::settings_view::{Section, SettingsView};
22use super::stack::{
22use super::stack::{
23 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
23 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
24};
24};
25use super::taskbar::taskbar_badge_count;
25use super::text::describe;
26use super::text::describe;
26use super::toast::{PillView, ToastView};
27use super::toast::{PillView, ToastView};
28use crate::activity::ActivityCenter;
27use crate::agents::{AgentRun, AgentRunsEvent, RunState};
29use crate::agents::{AgentRun, AgentRunsEvent, RunState};
28use crate::app_state::{AppEvent, AppState, selection_for};
30use crate::app_state::{AppEvent, AppState, selection_for};
29use crate::call::DemoScene;
31use crate::call::DemoScene;
@@ -65,6 +67,7 @@ impl OpenWindow {
65
67
66pub struct NotificationCenter {
68pub struct NotificationCenter {
67 app: Entity<AppState>,
69 app: Entity<AppState>,
70 activity: Entity<ActivityCenter>,
68 main_window: AnyWindowHandle,
71 main_window: AnyWindowHandle,
69 main_native: Option<NativeHandle>,
72 main_native: Option<NativeHandle>,
70 settings: Settings,
73 settings: Settings,
@@ -90,11 +93,17 @@ pub struct NotificationCenter {
90 shown_badge: Option<Badge>,
93 shown_badge: Option<Badge>,
91 animations: bool,
94 animations: bool,
92 _subscription: Subscription,
95 _subscription: Subscription,
96 _activity_observation: Subscription,
93 _agent_subscription: Option<Subscription>,
97 _agent_subscription: Option<Subscription>,
94}
98}
95
99
96impl NotificationCenter {
100impl NotificationCenter {
97 pub fn new(app: Entity<AppState>, window: &mut Window, cx: &mut Context<Self>) -> Self {
101 pub fn new(
102 app: Entity<AppState>,
103 activity: Entity<ActivityCenter>,
104 window: &mut Window,
105 cx: &mut Context<Self>,
106 ) -> Self {
98 let settings = settings::load(&app.read(cx).store);
107 let settings = settings::load(&app.read(cx).store);
99 let tray = if app.read(cx).mode.demo {
108 let tray = if app.read(cx).mode.demo {
100 None
109 None
@@ -104,6 +113,7 @@ impl NotificationCenter {
104 let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {
113 let subscription = cx.subscribe(&app, |this, _, event: &AppEvent, cx| {
105 this.on_app_event(event, cx);
114 this.on_app_event(event, cx);
106 });
115 });
116 let activity_observation = cx.observe(&activity, |this, _, cx| this.refresh_badge(cx));
107 let agent_subscription = crate::agents::runs_handle(cx).map(|runs| {
117 let agent_subscription = crate::agents::runs_handle(cx).map(|runs| {
108 cx.subscribe(&runs, |this, runs, event: &AgentRunsEvent, cx| {
118 cx.subscribe(&runs, |this, runs, event: &AgentRunsEvent, cx| {
109 if let AgentRunsEvent::Finished(run_id) = event
119 if let AgentRunsEvent::Finished(run_id) = event
@@ -139,7 +149,9 @@ impl NotificationCenter {
139 shown_badge: None,
149 shown_badge: None,
140 animations: platform::animations_enabled(),
150 animations: platform::animations_enabled(),
141 app,
151 app,
152 activity,
142 _subscription: subscription,
153 _subscription: subscription,
154 _activity_observation: activity_observation,
143 _agent_subscription: agent_subscription,
155 _agent_subscription: agent_subscription,
144 };
156 };
145 cx.spawn(async move |this, cx| {
157 cx.spawn(async move |this, cx| {
@@ -901,10 +913,15 @@ impl NotificationCenter {
901 }
913 }
902
914
903 fn refresh_badge(&mut self, cx: &mut Context<Self>) {
915 fn refresh_badge(&mut self, cx: &mut Context<Self>) {
904 let (count, still_unread) =
916 let state = self.app.read(cx);
905 unread_summary(&self.app.read(cx).sidebar, &self.unread_mentions);
917 let count = taskbar_badge_count(
918 &state.sidebar,
919 self.activity.read(cx).feed(),
920 state.directory.section_settings.adaptive_rail(),
921 );
922 let still_unread = unread_conversation_ids(&state.sidebar);
906 self.unread_mentions
923 self.unread_mentions
907 .retain(|conversation_id| still_unread.contains(conversation_id));
924 .retain(|conversation_id| still_unread.contains(conversation_id.as_str()));
908 let badge = badge_for(count);
925 let badge = badge_for(count);
909 if badge == self.shown_badge {
926 if badge == self.shown_badge {
910 return;
927 return;
@@ -1268,31 +1285,17 @@ fn popup_options(slot: Slot, area: WorkArea) -> WindowOptions {
1268 }
1285 }
1269}
1286}
1270
1287
1271pub fn unread_summary(
1288pub fn unread_conversation_ids(sidebar: &Sidebar) -> HashSet<&str> {
1272 sidebar: &Sidebar,
1273 unread_mentions: &HashSet<String>,
1274) -> (usize, HashSet<String>) {
1275 let chats = sidebar.chats.iter().filter(|chat| chat.unread);
1289 let chats = sidebar.chats.iter().filter(|chat| chat.unread);
1276 let channels = sidebar
1290 let channels = sidebar
1277 .teams
1291 .teams
1278 .iter()
1292 .iter()
1279 .flat_map(|team| team.channels.iter())
1293 .flat_map(|team| team.channels.iter())
1280 .filter(|channel| channel.unread);
1294 .filter(|channel| channel.unread);
1281 let silenced_chat_ids: HashSet<&str> = sidebar
1295 chats
1282 .chats
1283 .iter()
1284 .filter(|chat| chat.muted && !unread_mentions.contains(&chat.id))
1285 .map(|chat| chat.id.as_str())
1296 .map(|chat| chat.id.as_str())
1286 .collect();
1297 .chain(channels.map(|channel| channel.id.as_str()))
1287 let ids: HashSet<String> = chats
1298 .collect()
1288 .map(|chat| chat.id.clone())
1289 .chain(channels.map(|channel| channel.id.clone()))
1290 .collect();
1291 let counted = ids
1292 .iter()
1293 .filter(|id| !silenced_chat_ids.contains(id.as_str()))
1294 .count();
1295 (counted, ids)
1296}
1299}
1297
1300
1298fn demo_incoming() -> Vec<Incoming> {
1301fn demo_incoming() -> Vec<Incoming> {
@@ -1367,7 +1370,7 @@ mod tests {
1367
1370
1368 use std::collections::HashSet;
1371 use std::collections::HashSet;
1369
1372
1370 use super::{preview_lines, unread_summary};
1373 use super::{preview_lines, unread_conversation_ids};
1371 use store::Sidebar;
1374 use store::Sidebar;
1372
1375
1373 fn sidebar() -> Sidebar {
1376 fn sidebar() -> Sidebar {
@@ -1405,21 +1408,12 @@ mod tests {
1405 }
1408 }
1406
1409
1407 #[test]
1410 #[test]
1408 fn unread_summary_counts_chats_and_channels() {
1411 fn unread_conversation_ids_hold_chats_and_channels() {
1409 let (count, ids) = unread_summary(&sidebar(), &HashSet::new());
1412 let sidebar = sidebar();
1410 assert_eq!(count, 2);
1413 assert_eq!(
1411 assert!(ids.contains("a") && ids.contains("ch"));
1414 unread_conversation_ids(&sidebar),
1412 }
1415 HashSet::from(["a", "ch"])
1413
1416 );
1414 #[test]
1415 fn muted_chats_only_count_with_an_unread_mention() {
1416 let mut quiet = sidebar();
1417 quiet.chats[0].muted = true;
1418 let (count, ids) = unread_summary(&quiet, &HashSet::new());
1419 assert_eq!(count, 1);
1420 assert!(ids.contains("a"));
1421 let (count, _) = unread_summary(&quiet, &HashSet::from(["a".to_owned()]));
1422 assert_eq!(count, 2);
1423 }
1417 }
1424
1418
1425 #[gpui_kit::test]
1419 #[gpui_kit::test]
crates/app/src/views/shell.rs +2 −1
@@ -264,7 +264,8 @@ impl AppShell {
264 264 });
265 265 let focus_handle = cx.focus_handle();
266 266 window.focus(&focus_handle, cx);
267 let notifications = cx.new(|cx| NotificationCenter::new(state.clone(), window, cx));
267 let notifications =
268 cx.new(|cx| NotificationCenter::new(state.clone(), activity.clone(), window, cx));
268 269 let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx));
269 270 let user_input = cx.global::<UserInputHandle>().0.clone();
270 271 let escape_observation = cx.observe_keystrokes(|this, event, _, cx| {
@@ -264,7 +264,8 @@ impl AppShell {
264 });
264 });
265 let focus_handle = cx.focus_handle();
265 let focus_handle = cx.focus_handle();
266 window.focus(&focus_handle, cx);
266 window.focus(&focus_handle, cx);
267 let notifications = cx.new(|cx| NotificationCenter::new(state.clone(), window, cx));
267 let notifications =
268 cx.new(|cx| NotificationCenter::new(state.clone(), activity.clone(), window, cx));
268 let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx));
269 let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx));
269 let user_input = cx.global::<UserInputHandle>().0.clone();
270 let user_input = cx.global::<UserInputHandle>().0.clone();
270 let escape_observation = cx.observe_keystrokes(|this, event, _, cx| {
271 let escape_observation = cx.observe_keystrokes(|this, event, _, cx| {
crates/chatsvc/src/settings.rs +13 −3
@@ -12,6 +12,7 @@ const SKIN_TONE_KEY: &str = "preferredSkinToneIndex";
12 12 const MAX_SKIN_TONE: u8 = 5;
13 13 const MUTED_FIELD: &str = "hasUserEnabledMutedChatSection";
14 14 const MEETING_FIELD: &str = "hasUserEnabledMeetingChatSection";
15 const ADAPTIVE_RAIL_FIELD: &str = "hasUserEnabledAdaptiveRailForDesktop";
15 16 const MUTED_DEFAULT: bool = false;
16 17 const MEETING_DEFAULT: bool = false;
17 18
@@ -34,6 +35,7 @@ impl ChatSection {
34 35 pub struct ChatSectionSettings {
35 36 pub muted: Option<bool>,
36 37 pub meeting: Option<bool>,
38 pub adaptive_rail: Option<bool>,
37 39 }
38 40
39 41 impl ChatSectionSettings {
@@ -44,6 +46,10 @@ impl ChatSectionSettings {
44 46 }
45 47 }
46 48
49 pub fn adaptive_rail(&self) -> bool {
50 self.adaptive_rail.unwrap_or(false)
51 }
52
47 53 pub fn set(&mut self, section: ChatSection, enabled: bool) {
48 54 match section {
49 55 ChatSection::Muted => self.muted = Some(enabled),
@@ -128,6 +134,7 @@ pub fn parse_chat_sections(properties: &Value) -> ChatSectionSettings {
128 134 ChatSectionSettings {
129 135 muted: settings.get(MUTED_FIELD).and_then(Value::as_bool),
130 136 meeting: settings.get(MEETING_FIELD).and_then(Value::as_bool),
137 adaptive_rail: settings.get(ADAPTIVE_RAIL_FIELD).and_then(Value::as_bool),
131 138 }
132 139 }
133 140
@@ -221,15 +228,17 @@ mod tests {
221 228 assert_eq!(parsed, ChatSectionSettings::default());
222 229 assert!(!parsed.enabled(ChatSection::Muted));
223 230 assert!(!parsed.enabled(ChatSection::Meeting));
231 assert!(!parsed.adaptive_rail());
224 232 }
225 233
226 234 #[test]
227 fn reads_both_flags_from_the_json_string() {
235 fn reads_every_flag_from_the_json_string() {
228 236 let parsed = parse_chat_sections(&properties(
229 r#"{"id":"simpleCollabUserSettingsId","hasUserEnabledMutedChatSection":false,"hasUserEnabledMeetingChatSection":true}"#,
237 r#"{"id":"simpleCollabUserSettingsId","hasUserEnabledMutedChatSection":false,"hasUserEnabledMeetingChatSection":true,"hasUserEnabledAdaptiveRailForDesktop":true}"#,
230 238 ));
231 239 assert!(!parsed.enabled(ChatSection::Muted));
232 240 assert!(parsed.enabled(ChatSection::Meeting));
241 assert!(parsed.adaptive_rail());
233 242 }
234 243
235 244 #[test]
@@ -275,7 +284,8 @@ mod tests {
275 284 parse_chat_sections(&json!({SETTINGS_KEY: merged})),
276 285 ChatSectionSettings {
277 286 muted: Some(false),
278 meeting: Some(true)
287 meeting: Some(true),
288 adaptive_rail: None,
279 289 }
280 290 );
281 291 }
@@ -12,6 +12,7 @@ const SKIN_TONE_KEY: &str = "preferredSkinToneIndex";
12const MAX_SKIN_TONE: u8 = 5;
12const MAX_SKIN_TONE: u8 = 5;
13const MUTED_FIELD: &str = "hasUserEnabledMutedChatSection";
13const MUTED_FIELD: &str = "hasUserEnabledMutedChatSection";
14const MEETING_FIELD: &str = "hasUserEnabledMeetingChatSection";
14const MEETING_FIELD: &str = "hasUserEnabledMeetingChatSection";
15const ADAPTIVE_RAIL_FIELD: &str = "hasUserEnabledAdaptiveRailForDesktop";
15const MUTED_DEFAULT: bool = false;
16const MUTED_DEFAULT: bool = false;
16const MEETING_DEFAULT: bool = false;
17const MEETING_DEFAULT: bool = false;
17
18
@@ -34,6 +35,7 @@ impl ChatSection {
34pub struct ChatSectionSettings {
35pub struct ChatSectionSettings {
35 pub muted: Option<bool>,
36 pub muted: Option<bool>,
36 pub meeting: Option<bool>,
37 pub meeting: Option<bool>,
38 pub adaptive_rail: Option<bool>,
37}
39}
38
40
39impl ChatSectionSettings {
41impl ChatSectionSettings {
@@ -44,6 +46,10 @@ impl ChatSectionSettings {
44 }
46 }
45 }
47 }
46
48
49 pub fn adaptive_rail(&self) -> bool {
50 self.adaptive_rail.unwrap_or(false)
51 }
52
47 pub fn set(&mut self, section: ChatSection, enabled: bool) {
53 pub fn set(&mut self, section: ChatSection, enabled: bool) {
48 match section {
54 match section {
49 ChatSection::Muted => self.muted = Some(enabled),
55 ChatSection::Muted => self.muted = Some(enabled),
@@ -128,6 +134,7 @@ pub fn parse_chat_sections(properties: &Value) -> ChatSectionSettings {
128 ChatSectionSettings {
134 ChatSectionSettings {
129 muted: settings.get(MUTED_FIELD).and_then(Value::as_bool),
135 muted: settings.get(MUTED_FIELD).and_then(Value::as_bool),
130 meeting: settings.get(MEETING_FIELD).and_then(Value::as_bool),
136 meeting: settings.get(MEETING_FIELD).and_then(Value::as_bool),
137 adaptive_rail: settings.get(ADAPTIVE_RAIL_FIELD).and_then(Value::as_bool),
131 }
138 }
132}
139}
133
140
@@ -221,15 +228,17 @@ mod tests {
221 assert_eq!(parsed, ChatSectionSettings::default());
228 assert_eq!(parsed, ChatSectionSettings::default());
222 assert!(!parsed.enabled(ChatSection::Muted));
229 assert!(!parsed.enabled(ChatSection::Muted));
223 assert!(!parsed.enabled(ChatSection::Meeting));
230 assert!(!parsed.enabled(ChatSection::Meeting));
231 assert!(!parsed.adaptive_rail());
224 }
232 }
225
233
226 #[test]
234 #[test]
227 fn reads_both_flags_from_the_json_string() {
235 fn reads_every_flag_from_the_json_string() {
228 let parsed = parse_chat_sections(&properties(
236 let parsed = parse_chat_sections(&properties(
229 r#"{"id":"simpleCollabUserSettingsId","hasUserEnabledMutedChatSection":false,"hasUserEnabledMeetingChatSection":true}"#,
237 r#"{"id":"simpleCollabUserSettingsId","hasUserEnabledMutedChatSection":false,"hasUserEnabledMeetingChatSection":true,"hasUserEnabledAdaptiveRailForDesktop":true}"#,
230 ));
238 ));
231 assert!(!parsed.enabled(ChatSection::Muted));
239 assert!(!parsed.enabled(ChatSection::Muted));
232 assert!(parsed.enabled(ChatSection::Meeting));
240 assert!(parsed.enabled(ChatSection::Meeting));
241 assert!(parsed.adaptive_rail());
233 }
242 }
234
243
235 #[test]
244 #[test]
@@ -275,7 +284,8 @@ mod tests {
275 parse_chat_sections(&json!({SETTINGS_KEY: merged})),
284 parse_chat_sections(&json!({SETTINGS_KEY: merged})),
276 ChatSectionSettings {
285 ChatSectionSettings {
277 muted: Some(false),
286 muted: Some(false),
278 meeting: Some(true)
287 meeting: Some(true),
288 adaptive_rail: None,
279 }
289 }
280 );
290 );
281 }
291 }
crates/core/src/folders.rs +3 −0
@@ -383,6 +383,7 @@ const KIND_MEETING: &str = "MeetingChats";
383 383 const KIND_MUTED: &str = "MutedChats";
384 384 const META_MUTED_SECTION: &str = "chat_section_muted";
385 385 const META_MEETING_SECTION: &str = "chat_section_meeting";
386 const META_ADAPTIVE_RAIL: &str = "adaptive_rail";
386 387
387 388 fn to_record(folder: &ChatFolder) -> FolderRecord {
388 389 FolderRecord {
@@ -428,6 +429,7 @@ pub fn stored_section_settings(store: &Store) -> ChatSectionSettings {
428 429 ChatSectionSettings {
429 430 muted: read(META_MUTED_SECTION),
430 431 meeting: read(META_MEETING_SECTION),
432 adaptive_rail: read(META_ADAPTIVE_RAIL),
431 433 }
432 434 }
433 435
@@ -435,6 +437,7 @@ pub fn store_section_settings(store: &Store, settings: &ChatSectionSettings) ->
435 437 for (key, value) in [
436 438 (META_MUTED_SECTION, settings.muted),
437 439 (META_MEETING_SECTION, settings.meeting),
440 (META_ADAPTIVE_RAIL, settings.adaptive_rail),
438 441 ] {
439 442 let text = value.map(|enabled| enabled.to_string()).unwrap_or_default();
440 443 store.set_meta(key, &text)?;
@@ -383,6 +383,7 @@ const KIND_MEETING: &str = "MeetingChats";
383const KIND_MUTED: &str = "MutedChats";
383const KIND_MUTED: &str = "MutedChats";
384const META_MUTED_SECTION: &str = "chat_section_muted";
384const META_MUTED_SECTION: &str = "chat_section_muted";
385const META_MEETING_SECTION: &str = "chat_section_meeting";
385const META_MEETING_SECTION: &str = "chat_section_meeting";
386const META_ADAPTIVE_RAIL: &str = "adaptive_rail";
386
387
387fn to_record(folder: &ChatFolder) -> FolderRecord {
388fn to_record(folder: &ChatFolder) -> FolderRecord {
388 FolderRecord {
389 FolderRecord {
@@ -428,6 +429,7 @@ pub fn stored_section_settings(store: &Store) -> ChatSectionSettings {
428 ChatSectionSettings {
429 ChatSectionSettings {
429 muted: read(META_MUTED_SECTION),
430 muted: read(META_MUTED_SECTION),
430 meeting: read(META_MEETING_SECTION),
431 meeting: read(META_MEETING_SECTION),
432 adaptive_rail: read(META_ADAPTIVE_RAIL),
431 }
433 }
432}
434}
433
435
@@ -435,6 +437,7 @@ pub fn store_section_settings(store: &Store, settings: &ChatSectionSettings) ->
435 for (key, value) in [
437 for (key, value) in [
436 (META_MUTED_SECTION, settings.muted),
438 (META_MUTED_SECTION, settings.muted),
437 (META_MEETING_SECTION, settings.meeting),
439 (META_MEETING_SECTION, settings.meeting),
440 (META_ADAPTIVE_RAIL, settings.adaptive_rail),
438 ] {
441 ] {
439 let text = value.map(|enabled| enabled.to_string()).unwrap_or_default();
442 let text = value.map(|enabled| enabled.to_string()).unwrap_or_default();
440 store.set_meta(key, &text)?;
443 store.set_meta(key, &text)?;
crates/core/tests/engine.rs +2 −0
@@ -3106,6 +3106,7 @@ async fn collapse_and_section_settings_go_through_the_source() {
3106 3106 Arc::get_mut(&mut source).unwrap().settings = ChatSectionSettings {
3107 3107 muted: Some(false),
3108 3108 meeting: Some(true),
3109 adaptive_rail: Some(true),
3109 3110 };
3110 3111 let engine = engine_with(&fake, SyncConfig::default()).with_folder_source(source.clone());
3111 3112 let mut events = engine.subscribe();
@@ -3117,6 +3118,7 @@ async fn collapse_and_section_settings_go_through_the_source() {
3117 3118 ChatSectionSettings {
3118 3119 muted: Some(false),
3119 3120 meeting: Some(true),
3121 adaptive_rail: Some(true),
3120 3122 }
3121 3123 );
3122 3124
@@ -3106,6 +3106,7 @@ async fn collapse_and_section_settings_go_through_the_source() {
3106 Arc::get_mut(&mut source).unwrap().settings = ChatSectionSettings {
3106 Arc::get_mut(&mut source).unwrap().settings = ChatSectionSettings {
3107 muted: Some(false),
3107 muted: Some(false),
3108 meeting: Some(true),
3108 meeting: Some(true),
3109 adaptive_rail: Some(true),
3109 };
3110 };
3110 let engine = engine_with(&fake, SyncConfig::default()).with_folder_source(source.clone());
3111 let engine = engine_with(&fake, SyncConfig::default()).with_folder_source(source.clone());
3111 let mut events = engine.subscribe();
3112 let mut events = engine.subscribe();
@@ -3117,6 +3118,7 @@ async fn collapse_and_section_settings_go_through_the_source() {
3117 ChatSectionSettings {
3118 ChatSectionSettings {
3118 muted: Some(false),
3119 muted: Some(false),
3119 meeting: Some(true),
3120 meeting: Some(true),
3121 adaptive_rail: Some(true),
3120 }
3122 }
3121 );
3123 );
3122
3124