BlueGit

ict rusty-teams

feat(settings): honour chat and notification account settings

- read receipts off hides read state, compact density tightens message rows
- Enter or Ctrl+Enter to send, Up arrow per setting, local markdown mode
- toast decision follows chat, mention, preset, meeting chat and per chat desktop settings
- Manage notifications submenu in the chat menu

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
8a1b4521c6bb572c095bb29f66a37ae6cd1f27c5
Parent
032e85d5
17 files changed +661 −110
crates/app-state/src/activity/feed.rs +1 −0
@@ -575,6 +575,7 @@ mod tests {
575 575 mentions_me: false,
576 576 muted: false,
577 577 signals: Default::default(),
578 chat: Default::default(),
578 579 created_at: at(9, minute),
579 580 }
580 581 }
@@ -575,6 +575,7 @@ mod tests {
575 mentions_me: false,
575 mentions_me: false,
576 muted: false,
576 muted: false,
577 signals: Default::default(),
577 signals: Default::default(),
578 chat: Default::default(),
578 created_at: at(9, minute),
579 created_at: at(9, minute),
579 }
580 }
580 }
581 }
crates/app-state/src/app_state.rs +10 −0
@@ -73,6 +73,7 @@ pub enum AppEvent {
73 73 MeetingChime,
74 74 CallTone(chatsvc::sounds::CallTone),
75 75 SoundSettings,
76 ChatSettings,
76 77 }
77 78
78 79 #[derive(Debug, Clone, Copy, Default)]
@@ -140,6 +141,9 @@ pub struct AppState {
140 141 pub call_share_sound: bool,
141 142 pub recording_policy: teams_core::RecordingPolicy,
142 143 pub account_sounds: Option<chatsvc::sound_settings::SoundSettings>,
144 pub chat_settings: teams_core::ChatSettingsDocument,
145 pub markdown_mode: bool,
146 pub demo_chat_desktop: HashMap<String, teams_core::DesktopNotifications>,
143 147 pub own_tenant: Option<String>,
144 148 pub call_share_motion: bool,
145 149 pub call_share_standout: bool,
@@ -231,6 +235,8 @@ pub fn selection_title(sidebar: &Sidebar, selection: &Selection) -> String {
231 235 impl AppState {
232 236 pub fn new(store: Arc<Store>, mode: Mode) -> Self {
233 237 let sidebar = store.sidebar().unwrap_or_default();
238 let chat_settings = teams_core::stored_chat_settings(&store);
239 let markdown_mode = crate::chat_settings_actions::stored_markdown_mode(&store);
234 240 let mut state = AppState {
235 241 store,
236 242 engine: None,
@@ -293,6 +299,9 @@ impl AppState {
293 299 call_share_sound: false,
294 300 recording_policy: teams_core::RecordingPolicy::default(),
295 301 account_sounds: None,
302 chat_settings,
303 markdown_mode,
304 demo_chat_desktop: HashMap::new(),
296 305 own_tenant: None,
297 306 call_share_motion: false,
298 307 call_share_standout: false,
@@ -994,6 +1003,7 @@ impl AppState {
994 1003 self.refresh_translation_settings(cx);
995 1004 self.refresh_recording_policy(cx);
996 1005 self.refresh_sound_settings(cx);
1006 self.refresh_chat_settings(cx);
997 1007 let waiting = self.directory.waiting_presence_ids();
998 1008 self.request_presence(waiting, cx);
999 1009 self.refresh_own_status(cx);
@@ -73,6 +73,7 @@ pub enum AppEvent {
73 MeetingChime,
73 MeetingChime,
74 CallTone(chatsvc::sounds::CallTone),
74 CallTone(chatsvc::sounds::CallTone),
75 SoundSettings,
75 SoundSettings,
76 ChatSettings,
76}
77}
77
78
78#[derive(Debug, Clone, Copy, Default)]
79#[derive(Debug, Clone, Copy, Default)]
@@ -140,6 +141,9 @@ pub struct AppState {
140 pub call_share_sound: bool,
141 pub call_share_sound: bool,
141 pub recording_policy: teams_core::RecordingPolicy,
142 pub recording_policy: teams_core::RecordingPolicy,
142 pub account_sounds: Option<chatsvc::sound_settings::SoundSettings>,
143 pub account_sounds: Option<chatsvc::sound_settings::SoundSettings>,
144 pub chat_settings: teams_core::ChatSettingsDocument,
145 pub markdown_mode: bool,
146 pub demo_chat_desktop: HashMap<String, teams_core::DesktopNotifications>,
143 pub own_tenant: Option<String>,
147 pub own_tenant: Option<String>,
144 pub call_share_motion: bool,
148 pub call_share_motion: bool,
145 pub call_share_standout: bool,
149 pub call_share_standout: bool,
@@ -231,6 +235,8 @@ pub fn selection_title(sidebar: &Sidebar, selection: &Selection) -> String {
231impl AppState {
235impl AppState {
232 pub fn new(store: Arc<Store>, mode: Mode) -> Self {
236 pub fn new(store: Arc<Store>, mode: Mode) -> Self {
233 let sidebar = store.sidebar().unwrap_or_default();
237 let sidebar = store.sidebar().unwrap_or_default();
238 let chat_settings = teams_core::stored_chat_settings(&store);
239 let markdown_mode = crate::chat_settings_actions::stored_markdown_mode(&store);
234 let mut state = AppState {
240 let mut state = AppState {
235 store,
241 store,
236 engine: None,
242 engine: None,
@@ -293,6 +299,9 @@ impl AppState {
293 call_share_sound: false,
299 call_share_sound: false,
294 recording_policy: teams_core::RecordingPolicy::default(),
300 recording_policy: teams_core::RecordingPolicy::default(),
295 account_sounds: None,
301 account_sounds: None,
302 chat_settings,
303 markdown_mode,
304 demo_chat_desktop: HashMap::new(),
296 own_tenant: None,
305 own_tenant: None,
297 call_share_motion: false,
306 call_share_motion: false,
298 call_share_standout: false,
307 call_share_standout: false,
@@ -994,6 +1003,7 @@ impl AppState {
994 self.refresh_translation_settings(cx);
1003 self.refresh_translation_settings(cx);
995 self.refresh_recording_policy(cx);
1004 self.refresh_recording_policy(cx);
996 self.refresh_sound_settings(cx);
1005 self.refresh_sound_settings(cx);
1006 self.refresh_chat_settings(cx);
997 let waiting = self.directory.waiting_presence_ids();
1007 let waiting = self.directory.waiting_presence_ids();
998 self.request_presence(waiting, cx);
1008 self.request_presence(waiting, cx);
999 self.refresh_own_status(cx);
1009 self.refresh_own_status(cx);
crates/app-state/src/chat_actions.rs +1 −1
@@ -321,7 +321,7 @@ impl AppState {
321 321 self.start_new_chat(cx);
322 322 }
323 323
324 fn chat_record(&self, chat_id: &str) -> Option<ChatRecord> {
324 pub(crate) fn chat_record(&self, chat_id: &str) -> Option<ChatRecord> {
325 325 self.sidebar
326 326 .chats
327 327 .iter()
@@ -321,7 +321,7 @@ impl AppState {
321 self.start_new_chat(cx);
321 self.start_new_chat(cx);
322 }
322 }
323
323
324 fn chat_record(&self, chat_id: &str) -> Option<ChatRecord> {
324 pub(crate) fn chat_record(&self, chat_id: &str) -> Option<ChatRecord> {
325 self.sidebar
325 self.sidebar
326 .chats
326 .chats
327 .iter()
327 .iter()
crates/app-state/src/chat_settings_actions.rs added +162 −0
@@ -0,0 +1,162 @@
1 use gpui_kit::Context;
2 use store::Store;
3 use teams_core::{
4 ChatAccountSettings, ChatNotificationMode, ChatSettingChange, ChatSettingsDocument,
5 DesktopNotifications,
6 };
7
8 use crate::app_state::{AppEvent, AppState};
9 use crate::rows::Receipt;
10 use crate::runtime;
11
12 const META_MARKDOWN_MODE: &str = "compose.markdown_mode";
13
14 pub fn stored_markdown_mode(store: &Store) -> bool {
15 store.meta(META_MARKDOWN_MODE).ok().flatten().as_deref() == Some("true")
16 }
17
18 /// Teams shows no read state at all while the own read receipts setting is off.
19 pub fn shown_receipt(settings: &ChatAccountSettings, receipt: Receipt) -> Receipt {
20 if settings.read_receipts {
21 receipt
22 } else {
23 Receipt::Hidden
24 }
25 }
26
27 impl AppState {
28 pub fn account_chat_settings(&self) -> ChatAccountSettings {
29 self.chat_settings.settings()
30 }
31
32 pub fn refresh_chat_settings(&mut self, cx: &mut Context<Self>) {
33 let Some(engine) = self.engine.clone() else {
34 return;
35 };
36 let read = runtime::spawn(async move { engine.refresh_chat_settings().await });
37 cx.spawn(async move |this, cx| {
38 let document = match read.await {
39 Ok(Ok(document)) => document,
40 Ok(Err(error)) => {
41 log::warn!("chat settings not read: {error}");
42 return;
43 }
44 Err(_) => return,
45 };
46 this.update(cx, |state, cx| state.apply_chat_settings(document, cx))
47 .ok();
48 })
49 .detach();
50 }
51
52 pub fn save_chat_setting(&mut self, change: ChatSettingChange, cx: &mut Context<Self>) {
53 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
54 return;
55 };
56 let previous = self.chat_settings.clone();
57 let mut updated = previous.clone();
58 updated.apply(change);
59 self.apply_chat_settings(updated, cx);
60 let Some(engine) = engine_or_demo else {
61 return;
62 };
63 self.run_chat_action(
64 "Setting",
65 async move { engine.save_chat_setting(change).await.map(|_| ()) },
66 move |state, cx| state.apply_chat_settings(previous, cx),
67 |_, _| {},
68 cx,
69 );
70 }
71
72 fn apply_chat_settings(&mut self, document: ChatSettingsDocument, cx: &mut Context<Self>) {
73 if self.chat_settings == document {
74 return;
75 }
76 let _ = teams_core::store_chat_settings(&self.store, &document);
77 self.chat_settings = document;
78 cx.emit(AppEvent::ChatSettings);
79 cx.notify();
80 }
81
82 pub fn set_markdown_mode(&mut self, enabled: bool, cx: &mut Context<Self>) {
83 self.markdown_mode = enabled;
84 let _ = self
85 .store
86 .set_meta(META_MARKDOWN_MODE, if enabled { "true" } else { "false" });
87 cx.emit(AppEvent::ChatSettings);
88 cx.notify();
89 }
90
91 pub fn chat_desktop_notifications(&self, chat_id: &str) -> DesktopNotifications {
92 match &self.engine {
93 Some(engine) => engine.chat_desktop_notifications(chat_id),
94 None => self
95 .demo_chat_desktop
96 .get(chat_id)
97 .copied()
98 .unwrap_or_default(),
99 }
100 }
101
102 pub fn set_chat_notifications(
103 &mut self,
104 chat_id: &str,
105 mode: ChatNotificationMode,
106 desktop: DesktopNotifications,
107 cx: &mut Context<Self>,
108 ) {
109 let Some(previous_muted) = self.chat_record(chat_id).map(|chat| chat.muted) else {
110 return;
111 };
112 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
113 return;
114 };
115 let muted = mode == ChatNotificationMode::Mute;
116 let _ = self.store.set_chat_muted(chat_id, muted);
117 self.reload_sidebar(cx);
118 let Some(engine) = engine_or_demo else {
119 self.demo_chat_desktop.insert(chat_id.to_owned(), desktop);
120 return;
121 };
122 let owned_id = chat_id.to_owned();
123 let revert_id = owned_id.clone();
124 self.run_chat_action(
125 "Chat notifications",
126 async move {
127 engine
128 .set_chat_notifications(&owned_id, mode, desktop)
129 .await
130 },
131 move |state, cx| {
132 let _ = state.store.set_chat_muted(&revert_id, previous_muted);
133 state.reload_sidebar(cx);
134 },
135 |_, _| {},
136 cx,
137 );
138 }
139 }
140
141 #[cfg(test)]
142 mod tests {
143 use super::*;
144
145 #[test]
146 fn receipts_disappear_while_the_own_setting_is_off() {
147 let mut settings = ChatAccountSettings::default();
148 assert_eq!(shown_receipt(&settings, Receipt::Read), Receipt::Read);
149 assert_eq!(shown_receipt(&settings, Receipt::Sent), Receipt::Sent);
150 settings.read_receipts = false;
151 assert_eq!(shown_receipt(&settings, Receipt::Read), Receipt::Hidden);
152 assert_eq!(shown_receipt(&settings, Receipt::Sent), Receipt::Hidden);
153 }
154
155 #[test]
156 fn markdown_mode_is_a_local_setting_that_starts_off() {
157 let store = Store::open_in_memory().unwrap();
158 assert!(!stored_markdown_mode(&store));
159 store.set_meta(META_MARKDOWN_MODE, "true").unwrap();
160 assert!(stored_markdown_mode(&store));
161 }
162 }
@@ -0,0 +1,162 @@
1use gpui_kit::Context;
2use store::Store;
3use teams_core::{
4 ChatAccountSettings, ChatNotificationMode, ChatSettingChange, ChatSettingsDocument,
5 DesktopNotifications,
6};
7
8use crate::app_state::{AppEvent, AppState};
9use crate::rows::Receipt;
10use crate::runtime;
11
12const META_MARKDOWN_MODE: &str = "compose.markdown_mode";
13
14pub fn stored_markdown_mode(store: &Store) -> bool {
15 store.meta(META_MARKDOWN_MODE).ok().flatten().as_deref() == Some("true")
16}
17
18/// Teams shows no read state at all while the own read receipts setting is off.
19pub fn shown_receipt(settings: &ChatAccountSettings, receipt: Receipt) -> Receipt {
20 if settings.read_receipts {
21 receipt
22 } else {
23 Receipt::Hidden
24 }
25}
26
27impl AppState {
28 pub fn account_chat_settings(&self) -> ChatAccountSettings {
29 self.chat_settings.settings()
30 }
31
32 pub fn refresh_chat_settings(&mut self, cx: &mut Context<Self>) {
33 let Some(engine) = self.engine.clone() else {
34 return;
35 };
36 let read = runtime::spawn(async move { engine.refresh_chat_settings().await });
37 cx.spawn(async move |this, cx| {
38 let document = match read.await {
39 Ok(Ok(document)) => document,
40 Ok(Err(error)) => {
41 log::warn!("chat settings not read: {error}");
42 return;
43 }
44 Err(_) => return,
45 };
46 this.update(cx, |state, cx| state.apply_chat_settings(document, cx))
47 .ok();
48 })
49 .detach();
50 }
51
52 pub fn save_chat_setting(&mut self, change: ChatSettingChange, cx: &mut Context<Self>) {
53 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
54 return;
55 };
56 let previous = self.chat_settings.clone();
57 let mut updated = previous.clone();
58 updated.apply(change);
59 self.apply_chat_settings(updated, cx);
60 let Some(engine) = engine_or_demo else {
61 return;
62 };
63 self.run_chat_action(
64 "Setting",
65 async move { engine.save_chat_setting(change).await.map(|_| ()) },
66 move |state, cx| state.apply_chat_settings(previous, cx),
67 |_, _| {},
68 cx,
69 );
70 }
71
72 fn apply_chat_settings(&mut self, document: ChatSettingsDocument, cx: &mut Context<Self>) {
73 if self.chat_settings == document {
74 return;
75 }
76 let _ = teams_core::store_chat_settings(&self.store, &document);
77 self.chat_settings = document;
78 cx.emit(AppEvent::ChatSettings);
79 cx.notify();
80 }
81
82 pub fn set_markdown_mode(&mut self, enabled: bool, cx: &mut Context<Self>) {
83 self.markdown_mode = enabled;
84 let _ = self
85 .store
86 .set_meta(META_MARKDOWN_MODE, if enabled { "true" } else { "false" });
87 cx.emit(AppEvent::ChatSettings);
88 cx.notify();
89 }
90
91 pub fn chat_desktop_notifications(&self, chat_id: &str) -> DesktopNotifications {
92 match &self.engine {
93 Some(engine) => engine.chat_desktop_notifications(chat_id),
94 None => self
95 .demo_chat_desktop
96 .get(chat_id)
97 .copied()
98 .unwrap_or_default(),
99 }
100 }
101
102 pub fn set_chat_notifications(
103 &mut self,
104 chat_id: &str,
105 mode: ChatNotificationMode,
106 desktop: DesktopNotifications,
107 cx: &mut Context<Self>,
108 ) {
109 let Some(previous_muted) = self.chat_record(chat_id).map(|chat| chat.muted) else {
110 return;
111 };
112 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
113 return;
114 };
115 let muted = mode == ChatNotificationMode::Mute;
116 let _ = self.store.set_chat_muted(chat_id, muted);
117 self.reload_sidebar(cx);
118 let Some(engine) = engine_or_demo else {
119 self.demo_chat_desktop.insert(chat_id.to_owned(), desktop);
120 return;
121 };
122 let owned_id = chat_id.to_owned();
123 let revert_id = owned_id.clone();
124 self.run_chat_action(
125 "Chat notifications",
126 async move {
127 engine
128 .set_chat_notifications(&owned_id, mode, desktop)
129 .await
130 },
131 move |state, cx| {
132 let _ = state.store.set_chat_muted(&revert_id, previous_muted);
133 state.reload_sidebar(cx);
134 },
135 |_, _| {},
136 cx,
137 );
138 }
139}
140
141#[cfg(test)]
142mod tests {
143 use super::*;
144
145 #[test]
146 fn receipts_disappear_while_the_own_setting_is_off() {
147 let mut settings = ChatAccountSettings::default();
148 assert_eq!(shown_receipt(&settings, Receipt::Read), Receipt::Read);
149 assert_eq!(shown_receipt(&settings, Receipt::Sent), Receipt::Sent);
150 settings.read_receipts = false;
151 assert_eq!(shown_receipt(&settings, Receipt::Read), Receipt::Hidden);
152 assert_eq!(shown_receipt(&settings, Receipt::Sent), Receipt::Hidden);
153 }
154
155 #[test]
156 fn markdown_mode_is_a_local_setting_that_starts_off() {
157 let store = Store::open_in_memory().unwrap();
158 assert!(!stored_markdown_mode(&store));
159 store.set_meta(META_MARKDOWN_MODE, "true").unwrap();
160 assert!(stored_markdown_mode(&store));
161 }
162}
crates/app-state/src/lib.rs +1 −0
@@ -11,6 +11,7 @@ pub mod card_refresh;
11 11 pub mod card_state;
12 12 pub mod chat_actions;
13 13 pub mod chat_members;
14 pub mod chat_settings_actions;
14 15 pub mod connection_banner;
15 16 pub mod data;
16 17 pub mod demo;
@@ -11,6 +11,7 @@ pub mod card_refresh;
11pub mod card_state;
11pub mod card_state;
12pub mod chat_actions;
12pub mod chat_actions;
13pub mod chat_members;
13pub mod chat_members;
14pub mod chat_settings_actions;
14pub mod connection_banner;
15pub mod connection_banner;
15pub mod data;
16pub mod data;
16pub mod demo;
17pub mod demo;
crates/app-state/src/notify/incoming.rs +45 −1
@@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet, VecDeque};
3 3 use chrono::{DateTime, Utc};
4 4 use store::{ChannelNotifications, MessageRecord, Sidebar, Store};
5 5
6 use super::rules::{ChannelSignals, ChatKind, Incoming, Preview};
6 use super::rules::{ChannelSignals, ChatKind, ChatSignals, Incoming, Preview};
7 7 use crate::app_state::chat_title;
8 8
9 9 const RECENT_WINDOW: usize = 20;
@@ -160,6 +160,7 @@ pub fn build_incoming(
160 160 ChatKind::Channel { .. } => channel_signals(record, store, sidebar, my_user_id),
161 161 _ => ChannelSignals::default(),
162 162 };
163 let chat = chat_signals(store, sidebar, &record.conversation_id, my_user_id);
163 164 Some(Incoming {
164 165 conversation_id: record.conversation_id.clone(),
165 166 message_id: record.message_id.clone(),
@@ -171,10 +172,32 @@ pub fn build_incoming(
171 172 mentions_me: mentions_me(record, my_user_id),
172 173 muted: is_muted_chat(sidebar, &record.conversation_id),
173 174 signals,
175 chat,
174 176 created_at: record.created_at,
175 177 })
176 178 }
177 179
180 fn chat_signals(
181 store: &Store,
182 sidebar: &Sidebar,
183 conversation_id: &str,
184 my_user_id: Option<&str>,
185 ) -> ChatSignals {
186 let meeting = sidebar
187 .chats
188 .iter()
189 .any(|chat| chat.id == conversation_id && chat.kind.eq_ignore_ascii_case("meeting"));
190 let participated = meeting
191 && store
192 .messages(conversation_id, None, RECENT_WINDOW)
193 .is_ok_and(|records| records.iter().any(|record| is_own(record, my_user_id)));
194 ChatSignals {
195 meeting,
196 participated,
197 ..ChatSignals::default()
198 }
199 }
200
178 201 fn is_muted_chat(sidebar: &Sidebar, conversation_id: &str) -> bool {
179 202 sidebar
180 203 .chats
@@ -388,6 +411,27 @@ mod tests {
388 411 assert!(!build(&sidebar()).muted);
389 412 }
390 413
414 #[test]
415 fn meeting_chats_know_whether_i_took_part() {
416 let mut with_meeting = sidebar();
417 with_meeting.chats[1].kind = "meeting".into();
418 let store = Store::open_in_memory().unwrap();
419 let message = record("group", "u1", Utc::now(), "hi");
420 let first = build_incoming(&message, &store, &with_meeting, Some("me")).unwrap();
421 assert!(first.chat.meeting);
422 assert!(!first.chat.participated);
423 let own = record("group", "me", Utc::now() - Duration::minutes(1), "hello");
424 store.upsert_messages(&[own]).unwrap();
425 let later = build_incoming(&message, &store, &with_meeting, Some("me")).unwrap();
426 assert!(later.chat.participated);
427 assert!(
428 !build_incoming(&message, &store, &sidebar(), Some("me"))
429 .unwrap()
430 .chat
431 .meeting
432 );
433 }
434
391 435 #[test]
392 436 fn history_before_start_is_ignored() {
393 437 let start = Utc::now();
@@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet, VecDeque};
3use chrono::{DateTime, Utc};
3use chrono::{DateTime, Utc};
4use store::{ChannelNotifications, MessageRecord, Sidebar, Store};
4use store::{ChannelNotifications, MessageRecord, Sidebar, Store};
5
5
6use super::rules::{ChannelSignals, ChatKind, Incoming, Preview};
6use super::rules::{ChannelSignals, ChatKind, ChatSignals, Incoming, Preview};
7use crate::app_state::chat_title;
7use crate::app_state::chat_title;
8
8
9const RECENT_WINDOW: usize = 20;
9const RECENT_WINDOW: usize = 20;
@@ -160,6 +160,7 @@ pub fn build_incoming(
160 ChatKind::Channel { .. } => channel_signals(record, store, sidebar, my_user_id),
160 ChatKind::Channel { .. } => channel_signals(record, store, sidebar, my_user_id),
161 _ => ChannelSignals::default(),
161 _ => ChannelSignals::default(),
162 };
162 };
163 let chat = chat_signals(store, sidebar, &record.conversation_id, my_user_id);
163 Some(Incoming {
164 Some(Incoming {
164 conversation_id: record.conversation_id.clone(),
165 conversation_id: record.conversation_id.clone(),
165 message_id: record.message_id.clone(),
166 message_id: record.message_id.clone(),
@@ -171,10 +172,32 @@ pub fn build_incoming(
171 mentions_me: mentions_me(record, my_user_id),
172 mentions_me: mentions_me(record, my_user_id),
172 muted: is_muted_chat(sidebar, &record.conversation_id),
173 muted: is_muted_chat(sidebar, &record.conversation_id),
173 signals,
174 signals,
175 chat,
174 created_at: record.created_at,
176 created_at: record.created_at,
175 })
177 })
176}
178}
177
179
180fn chat_signals(
181 store: &Store,
182 sidebar: &Sidebar,
183 conversation_id: &str,
184 my_user_id: Option<&str>,
185) -> ChatSignals {
186 let meeting = sidebar
187 .chats
188 .iter()
189 .any(|chat| chat.id == conversation_id && chat.kind.eq_ignore_ascii_case("meeting"));
190 let participated = meeting
191 && store
192 .messages(conversation_id, None, RECENT_WINDOW)
193 .is_ok_and(|records| records.iter().any(|record| is_own(record, my_user_id)));
194 ChatSignals {
195 meeting,
196 participated,
197 ..ChatSignals::default()
198 }
199}
200
178fn is_muted_chat(sidebar: &Sidebar, conversation_id: &str) -> bool {
201fn is_muted_chat(sidebar: &Sidebar, conversation_id: &str) -> bool {
179 sidebar
202 sidebar
180 .chats
203 .chats
@@ -388,6 +411,27 @@ mod tests {
388 assert!(!build(&sidebar()).muted);
411 assert!(!build(&sidebar()).muted);
389 }
412 }
390
413
414 #[test]
415 fn meeting_chats_know_whether_i_took_part() {
416 let mut with_meeting = sidebar();
417 with_meeting.chats[1].kind = "meeting".into();
418 let store = Store::open_in_memory().unwrap();
419 let message = record("group", "u1", Utc::now(), "hi");
420 let first = build_incoming(&message, &store, &with_meeting, Some("me")).unwrap();
421 assert!(first.chat.meeting);
422 assert!(!first.chat.participated);
423 let own = record("group", "me", Utc::now() - Duration::minutes(1), "hello");
424 store.upsert_messages(&[own]).unwrap();
425 let later = build_incoming(&message, &store, &with_meeting, Some("me")).unwrap();
426 assert!(later.chat.participated);
427 assert!(
428 !build_incoming(&message, &store, &sidebar(), Some("me"))
429 .unwrap()
430 .chat
431 .meeting
432 );
433 }
434
391 #[test]
435 #[test]
392 fn history_before_start_is_ignored() {
436 fn history_before_start_is_ignored() {
393 let start = Utc::now();
437 let start = Utc::now();
crates/app-state/src/notify/rules.rs +123 −22
@@ -4,6 +4,9 @@ use std::time::{Duration, Instant};
4 4 use calling::Progress;
5 5 use chrono::{DateTime, Utc};
6 6 use store::{ChannelNotificationLevel, ChannelNotifications};
7 use teams_core::{
8 DesktopNotifications, MeetingChatNotifications, NotificationAccountSettings, NotificationPreset,
9 };
7 10
8 11 use super::sound_settings::SoundSettings;
9 12 use super::sounds::Ringtone;
@@ -69,8 +72,7 @@ impl Corner {
69 72
70 73 #[derive(Debug, Clone, PartialEq, Eq)]
71 74 pub struct Settings {
72 pub mentions_only: bool,
73 pub preview: bool,
75 pub account: NotificationAccountSettings,
74 76 pub corner: Corner,
75 77 pub flash: bool,
76 78 pub close_to_tray: bool,
@@ -82,8 +84,7 @@ pub struct Settings {
82 84 impl Default for Settings {
83 85 fn default() -> Self {
84 86 Settings {
85 mentions_only: false,
86 preview: true,
87 account: NotificationAccountSettings::default(),
87 88 corner: Corner::BottomRight,
88 89 flash: true,
89 90 close_to_tray: true,
@@ -116,6 +117,13 @@ pub struct ChannelSignals {
116 117 pub notifications: ChannelNotifications,
117 118 }
118 119
120 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
121 pub struct ChatSignals {
122 pub meeting: bool,
123 pub participated: bool,
124 pub desktop: DesktopNotifications,
125 }
126
119 127 #[derive(Debug, Clone, PartialEq, Eq)]
120 128 pub struct Incoming {
121 129 pub conversation_id: String,
@@ -128,6 +136,7 @@ pub struct Incoming {
128 136 pub mentions_me: bool,
129 137 pub muted: bool,
130 138 pub signals: ChannelSignals,
139 pub chat: ChatSignals,
131 140 pub created_at: DateTime<Utc>,
132 141 }
133 142
@@ -201,6 +210,36 @@ fn channel_toasts(incoming: &Incoming) -> bool {
201 210 || signals.notifications.level == ChannelNotificationLevel::BannerAndFeed
202 211 }
203 212
213 fn account_toasts(account: &NotificationAccountSettings, incoming: &Incoming) -> bool {
214 if matches!(incoming.kind, ChatKind::Channel { .. }) {
215 return if incoming.mentions_me {
216 account.personal_mentions.shows_banner()
217 } else {
218 account.preset != NotificationPreset::MentionsAndReplies
219 || incoming.signals.in_my_thread
220 };
221 }
222 let chat = incoming.chat;
223 if chat.desktop == DesktopNotifications::Off {
224 return false;
225 }
226 if incoming.mentions_me {
227 return account.personal_mentions.shows_banner();
228 }
229 let meeting_muted = chat.meeting
230 && match account.meeting_chats {
231 MeetingChatNotifications::Mute => true,
232 MeetingChatNotifications::MuteUntilJoin => !chat.participated,
233 MeetingChatNotifications::Unmute => false,
234 };
235 !meeting_muted
236 && (chat.desktop == DesktopNotifications::On || account.chat_messages.shows_banner())
237 }
238
239 pub fn shows_preview(settings: &Settings) -> bool {
240 settings.account.show_preview
241 }
242
204 243 const SILENT: Decision = Decision {
205 244 toast: false,
206 245 sound: false,
@@ -214,7 +253,7 @@ pub fn decide(settings: &Settings, incoming: &Incoming, environment: Environment
214 253 || environment.own_do_not_disturb
215 254 || settings.do_not_disturb
216 255 || (settings.mute_in_calls && environment.in_call)
217 || (settings.mentions_only && !incoming.mentions_me && !incoming.is_direct());
256 || !account_toasts(&settings.account, incoming);
218 257 if suppressed {
219 258 return SILENT;
220 259 }
@@ -267,6 +306,7 @@ pub fn should_flash(settings: &Settings, toast_shown: bool, window_active: bool)
267 306 #[cfg(test)]
268 307 mod tests {
269 308 use calling::{CallState, EndReason};
309 use teams_core::ActivityAlert;
270 310
271 311 use super::*;
272 312
@@ -282,6 +322,7 @@ mod tests {
282 322 mentions_me: false,
283 323 muted: false,
284 324 signals: ChannelSignals::default(),
325 chat: ChatSignals::default(),
285 326 created_at: Utc::now(),
286 327 }
287 328 }
@@ -489,24 +530,84 @@ mod tests {
489 530 assert!(decide(&Settings::default(), &muted, Environment::default()).toast);
490 531 }
491 532
533 fn with_account(change: impl FnOnce(&mut NotificationAccountSettings)) -> Settings {
534 let mut settings = Settings::default();
535 change(&mut settings.account);
536 settings
537 }
538
539 fn toasts(settings: &Settings, incoming: &Incoming) -> bool {
540 decide(settings, incoming, Environment::default()).toast
541 }
542
543 fn mention(mut incoming: Incoming) -> Incoming {
544 incoming.mentions_me = true;
545 incoming
546 }
547
492 548 #[test]
493 fn mentions_only_keeps_direct_and_mentions() {
494 let settings = Settings {
495 mentions_only: true,
496 ..Default::default()
497 };
498 assert_eq!(decide(&settings, &group(), Environment::default()), SILENT);
499 assert!(
500 decide(
501 &settings,
502 &incoming(ChatKind::Direct),
503 Environment::default()
504 )
505 .toast
506 );
507 let mut mention = group();
508 mention.mentions_me = true;
509 assert!(decide(&settings, &mention, Environment::default()).toast);
549 fn chat_message_notifications_off_keeps_personal_mentions() {
550 let settings = with_account(|account| account.chat_messages = ActivityAlert::Off);
551 assert!(!toasts(&settings, &group()));
552 assert!(!toasts(&settings, &incoming(ChatKind::Direct)));
553 assert!(toasts(&settings, &mention(group())));
554 }
555
556 #[test]
557 fn personal_mentions_only_in_activity_give_no_banner() {
558 let settings = with_account(|account| account.personal_mentions = ActivityAlert::OnlyFeed);
559 assert!(!toasts(&settings, &mention(group())));
560 assert!(!toasts(&settings, &mention(channel())));
561 assert!(toasts(&settings, &group()));
562 }
563
564 #[test]
565 fn mentions_and_replies_preset_drops_plain_channel_posts() {
566 let settings =
567 with_account(|account| account.preset = NotificationPreset::MentionsAndReplies);
568 let mut post = channel_with(ChannelNotificationLevel::BannerAndFeed, true);
569 assert!(!toasts(&settings, &post));
570 post.signals.in_my_thread = true;
571 assert!(toasts(&settings, &post));
572 assert!(toasts(&settings, &mention(channel())));
573 assert!(toasts(&settings, &group()));
574 }
575
576 fn meeting_chat(participated: bool) -> Incoming {
577 let mut message = group();
578 message.chat.meeting = true;
579 message.chat.participated = participated;
580 message
581 }
582
583 #[test]
584 fn meeting_chats_stay_quiet_until_i_take_part() {
585 let settings = Settings::default();
586 assert!(!toasts(&settings, &meeting_chat(false)));
587 assert!(toasts(&settings, &meeting_chat(true)));
588 assert!(toasts(&settings, &mention(meeting_chat(false))));
589 }
590
591 #[test]
592 fn meeting_chat_mute_and_unmute() {
593 let muted = with_account(|account| account.meeting_chats = MeetingChatNotifications::Mute);
594 assert!(!toasts(&muted, &meeting_chat(true)));
595 assert!(toasts(&muted, &mention(meeting_chat(true))));
596 let unmuted =
597 with_account(|account| account.meeting_chats = MeetingChatNotifications::Unmute);
598 assert!(toasts(&unmuted, &meeting_chat(false)));
599 }
600
601 #[test]
602 fn per_chat_desktop_preference_overrides_the_account() {
603 let mut silenced = group();
604 silenced.chat.desktop = DesktopNotifications::Off;
605 assert!(!toasts(&Settings::default(), &silenced));
606 assert!(!toasts(&Settings::default(), &mention(silenced)));
607 let settings = with_account(|account| account.chat_messages = ActivityAlert::Off);
608 let mut selected = group();
609 selected.chat.desktop = DesktopNotifications::On;
610 assert!(toasts(&settings, &selected));
510 611 }
511 612
512 613 fn channel_with(level: ChannelNotificationLevel, include_replies: bool) -> Incoming {
@@ -4,6 +4,9 @@ use std::time::{Duration, Instant};
4use calling::Progress;
4use calling::Progress;
5use chrono::{DateTime, Utc};
5use chrono::{DateTime, Utc};
6use store::{ChannelNotificationLevel, ChannelNotifications};
6use store::{ChannelNotificationLevel, ChannelNotifications};
7use teams_core::{
8 DesktopNotifications, MeetingChatNotifications, NotificationAccountSettings, NotificationPreset,
9};
7
10
8use super::sound_settings::SoundSettings;
11use super::sound_settings::SoundSettings;
9use super::sounds::Ringtone;
12use super::sounds::Ringtone;
@@ -69,8 +72,7 @@ impl Corner {
69
72
70#[derive(Debug, Clone, PartialEq, Eq)]
73#[derive(Debug, Clone, PartialEq, Eq)]
71pub struct Settings {
74pub struct Settings {
72 pub mentions_only: bool,
75 pub account: NotificationAccountSettings,
73 pub preview: bool,
74 pub corner: Corner,
76 pub corner: Corner,
75 pub flash: bool,
77 pub flash: bool,
76 pub close_to_tray: bool,
78 pub close_to_tray: bool,
@@ -82,8 +84,7 @@ pub struct Settings {
82impl Default for Settings {
84impl Default for Settings {
83 fn default() -> Self {
85 fn default() -> Self {
84 Settings {
86 Settings {
85 mentions_only: false,
87 account: NotificationAccountSettings::default(),
86 preview: true,
87 corner: Corner::BottomRight,
88 corner: Corner::BottomRight,
88 flash: true,
89 flash: true,
89 close_to_tray: true,
90 close_to_tray: true,
@@ -116,6 +117,13 @@ pub struct ChannelSignals {
116 pub notifications: ChannelNotifications,
117 pub notifications: ChannelNotifications,
117}
118}
118
119
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
121pub struct ChatSignals {
122 pub meeting: bool,
123 pub participated: bool,
124 pub desktop: DesktopNotifications,
125}
126
119#[derive(Debug, Clone, PartialEq, Eq)]
127#[derive(Debug, Clone, PartialEq, Eq)]
120pub struct Incoming {
128pub struct Incoming {
121 pub conversation_id: String,
129 pub conversation_id: String,
@@ -128,6 +136,7 @@ pub struct Incoming {
128 pub mentions_me: bool,
136 pub mentions_me: bool,
129 pub muted: bool,
137 pub muted: bool,
130 pub signals: ChannelSignals,
138 pub signals: ChannelSignals,
139 pub chat: ChatSignals,
131 pub created_at: DateTime<Utc>,
140 pub created_at: DateTime<Utc>,
132}
141}
133
142
@@ -201,6 +210,36 @@ fn channel_toasts(incoming: &Incoming) -> bool {
201 || signals.notifications.level == ChannelNotificationLevel::BannerAndFeed
210 || signals.notifications.level == ChannelNotificationLevel::BannerAndFeed
202}
211}
203
212
213fn account_toasts(account: &NotificationAccountSettings, incoming: &Incoming) -> bool {
214 if matches!(incoming.kind, ChatKind::Channel { .. }) {
215 return if incoming.mentions_me {
216 account.personal_mentions.shows_banner()
217 } else {
218 account.preset != NotificationPreset::MentionsAndReplies
219 || incoming.signals.in_my_thread
220 };
221 }
222 let chat = incoming.chat;
223 if chat.desktop == DesktopNotifications::Off {
224 return false;
225 }
226 if incoming.mentions_me {
227 return account.personal_mentions.shows_banner();
228 }
229 let meeting_muted = chat.meeting
230 && match account.meeting_chats {
231 MeetingChatNotifications::Mute => true,
232 MeetingChatNotifications::MuteUntilJoin => !chat.participated,
233 MeetingChatNotifications::Unmute => false,
234 };
235 !meeting_muted
236 && (chat.desktop == DesktopNotifications::On || account.chat_messages.shows_banner())
237}
238
239pub fn shows_preview(settings: &Settings) -> bool {
240 settings.account.show_preview
241}
242
204const SILENT: Decision = Decision {
243const SILENT: Decision = Decision {
205 toast: false,
244 toast: false,
206 sound: false,
245 sound: false,
@@ -214,7 +253,7 @@ pub fn decide(settings: &Settings, incoming: &Incoming, environment: Environment
214 || environment.own_do_not_disturb
253 || environment.own_do_not_disturb
215 || settings.do_not_disturb
254 || settings.do_not_disturb
216 || (settings.mute_in_calls && environment.in_call)
255 || (settings.mute_in_calls && environment.in_call)
217 || (settings.mentions_only && !incoming.mentions_me && !incoming.is_direct());
256 || !account_toasts(&settings.account, incoming);
218 if suppressed {
257 if suppressed {
219 return SILENT;
258 return SILENT;
220 }
259 }
@@ -267,6 +306,7 @@ pub fn should_flash(settings: &Settings, toast_shown: bool, window_active: bool)
267#[cfg(test)]
306#[cfg(test)]
268mod tests {
307mod tests {
269 use calling::{CallState, EndReason};
308 use calling::{CallState, EndReason};
309 use teams_core::ActivityAlert;
270
310
271 use super::*;
311 use super::*;
272
312
@@ -282,6 +322,7 @@ mod tests {
282 mentions_me: false,
322 mentions_me: false,
283 muted: false,
323 muted: false,
284 signals: ChannelSignals::default(),
324 signals: ChannelSignals::default(),
325 chat: ChatSignals::default(),
285 created_at: Utc::now(),
326 created_at: Utc::now(),
286 }
327 }
287 }
328 }
@@ -489,24 +530,84 @@ mod tests {
489 assert!(decide(&Settings::default(), &muted, Environment::default()).toast);
530 assert!(decide(&Settings::default(), &muted, Environment::default()).toast);
490 }
531 }
491
532
533 fn with_account(change: impl FnOnce(&mut NotificationAccountSettings)) -> Settings {
534 let mut settings = Settings::default();
535 change(&mut settings.account);
536 settings
537 }
538
539 fn toasts(settings: &Settings, incoming: &Incoming) -> bool {
540 decide(settings, incoming, Environment::default()).toast
541 }
542
543 fn mention(mut incoming: Incoming) -> Incoming {
544 incoming.mentions_me = true;
545 incoming
546 }
547
492 #[test]
548 #[test]
493 fn mentions_only_keeps_direct_and_mentions() {
549 fn chat_message_notifications_off_keeps_personal_mentions() {
494 let settings = Settings {
550 let settings = with_account(|account| account.chat_messages = ActivityAlert::Off);
495 mentions_only: true,
551 assert!(!toasts(&settings, &group()));
496 ..Default::default()
552 assert!(!toasts(&settings, &incoming(ChatKind::Direct)));
497 };
553 assert!(toasts(&settings, &mention(group())));
498 assert_eq!(decide(&settings, &group(), Environment::default()), SILENT);
554 }
499 assert!(
555
500 decide(
556 #[test]
501 &settings,
557 fn personal_mentions_only_in_activity_give_no_banner() {
502 &incoming(ChatKind::Direct),
558 let settings = with_account(|account| account.personal_mentions = ActivityAlert::OnlyFeed);
503 Environment::default()
559 assert!(!toasts(&settings, &mention(group())));
504 )
560 assert!(!toasts(&settings, &mention(channel())));
505 .toast
561 assert!(toasts(&settings, &group()));
506 );
562 }
507 let mut mention = group();
563
508 mention.mentions_me = true;
564 #[test]
509 assert!(decide(&settings, &mention, Environment::default()).toast);
565 fn mentions_and_replies_preset_drops_plain_channel_posts() {
566 let settings =
567 with_account(|account| account.preset = NotificationPreset::MentionsAndReplies);
568 let mut post = channel_with(ChannelNotificationLevel::BannerAndFeed, true);
569 assert!(!toasts(&settings, &post));
570 post.signals.in_my_thread = true;
571 assert!(toasts(&settings, &post));
572 assert!(toasts(&settings, &mention(channel())));
573 assert!(toasts(&settings, &group()));
574 }
575
576 fn meeting_chat(participated: bool) -> Incoming {
577 let mut message = group();
578 message.chat.meeting = true;
579 message.chat.participated = participated;
580 message
581 }
582
583 #[test]
584 fn meeting_chats_stay_quiet_until_i_take_part() {
585 let settings = Settings::default();
586 assert!(!toasts(&settings, &meeting_chat(false)));
587 assert!(toasts(&settings, &meeting_chat(true)));
588 assert!(toasts(&settings, &mention(meeting_chat(false))));
589 }
590
591 #[test]
592 fn meeting_chat_mute_and_unmute() {
593 let muted = with_account(|account| account.meeting_chats = MeetingChatNotifications::Mute);
594 assert!(!toasts(&muted, &meeting_chat(true)));
595 assert!(toasts(&muted, &mention(meeting_chat(true))));
596 let unmuted =
597 with_account(|account| account.meeting_chats = MeetingChatNotifications::Unmute);
598 assert!(toasts(&unmuted, &meeting_chat(false)));
599 }
600
601 #[test]
602 fn per_chat_desktop_preference_overrides_the_account() {
603 let mut silenced = group();
604 silenced.chat.desktop = DesktopNotifications::Off;
605 assert!(!toasts(&Settings::default(), &silenced));
606 assert!(!toasts(&Settings::default(), &mention(silenced)));
607 let settings = with_account(|account| account.chat_messages = ActivityAlert::Off);
608 let mut selected = group();
609 selected.chat.desktop = DesktopNotifications::On;
610 assert!(toasts(&settings, &selected));
510 }
611 }
511
612
512 fn channel_with(level: ChannelNotificationLevel, include_replies: bool) -> Incoming {
613 fn channel_with(level: ChannelNotificationLevel, include_replies: bool) -> Incoming {
crates/app-state/src/notify/settings.rs +34 −14
@@ -1,7 +1,7 @@
1 1 use store::Store;
2 2
3 use super::sounds::{AlertSound, Ringtone, RingtoneAssignments, RingtoneCallType};
4 3 use super::rules::{Corner, Settings};
4 use super::sounds::{AlertSound, Ringtone, RingtoneAssignments, RingtoneCallType};
5 5
6 6 const META_KEY: &str = "notifications.settings";
7 7 const RINGTONE_PREFIX: &str = "ringtone.";
@@ -29,18 +29,37 @@ fn serialize(settings: &Settings) -> String {
29 29 });
30 30 [
31 31 ("sound".to_owned(), sounds.notification_sound.to_string()),
32 ("sound_type".to_owned(), sounds.notification_sound_type.name().to_owned()),
32 (
33 "sound_type".to_owned(),
34 sounds.notification_sound_type.name().to_owned(),
35 ),
33 36 ("urgent_sound".to_owned(), sounds.urgent_sound.to_string()),
34 ("urgent_sound_type".to_owned(), sounds.urgent_sound_type.name().to_owned()),
35 ("call_sound".to_owned(), sounds.call_and_meeting_sound.to_string()),
36 ("sound_when_busy".to_owned(), sounds.sound_when_busy.to_string()),
37 ("mentions_only".to_owned(), settings.mentions_only.to_string()),
38 ("preview".to_owned(), settings.preview.to_string()),
37 (
38 "urgent_sound_type".to_owned(),
39 sounds.urgent_sound_type.name().to_owned(),
40 ),
41 (
42 "call_sound".to_owned(),
43 sounds.call_and_meeting_sound.to_string(),
44 ),
45 (
46 "sound_when_busy".to_owned(),
47 sounds.sound_when_busy.to_string(),
48 ),
39 49 ("corner".to_owned(), settings.corner.key().to_owned()),
40 50 ("taskbar_flash".to_owned(), settings.flash.to_string()),
41 ("close_to_tray".to_owned(), settings.close_to_tray.to_string()),
42 ("do_not_disturb".to_owned(), settings.do_not_disturb.to_string()),
43 ("mute_in_calls".to_owned(), settings.mute_in_calls.to_string()),
51 (
52 "close_to_tray".to_owned(),
53 settings.close_to_tray.to_string(),
54 ),
55 (
56 "do_not_disturb".to_owned(),
57 settings.do_not_disturb.to_string(),
58 ),
59 (
60 "mute_in_calls".to_owned(),
61 settings.mute_in_calls.to_string(),
62 ),
44 63 ]
45 64 .into_iter()
46 65 .chain(ringtones)
@@ -64,8 +83,6 @@ fn parse(text: &str) -> Settings {
64 83 "urgent_sound_type" => set_alert_sound(&mut sounds.urgent_sound_type, value),
65 84 "call_sound" => sounds.call_and_meeting_sound = flag,
66 85 "sound_when_busy" => sounds.sound_when_busy = flag,
67 "mentions_only" => settings.mentions_only = flag,
68 "preview" => settings.preview = flag,
69 86 "corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),
70 87 "taskbar_flash" => settings.flash = flag,
71 88 "close_to_tray" => settings.close_to_tray = flag,
@@ -100,8 +117,7 @@ mod tests {
100 117 #[test]
101 118 fn round_trips_every_field() {
102 119 let settings = Settings {
103 mentions_only: true,
104 preview: false,
120 account: Default::default(),
105 121 corner: Corner::TopLeft,
106 122 flash: false,
107 123 close_to_tray: false,
@@ -133,6 +149,10 @@ mod tests {
133 149 #[test]
134 150 fn the_old_synthesized_ringtone_key_is_ignored() {
135 151 assert_eq!(parse("ringtone=chime"), Settings::default());
152 assert_eq!(
153 parse("mentions_only=true\npreview=false"),
154 Settings::default()
155 );
136 156 }
137 157
138 158 #[test]
@@ -1,7 +1,7 @@
1use store::Store;
1use store::Store;
2
2
3use super::sounds::{AlertSound, Ringtone, RingtoneAssignments, RingtoneCallType};
4use super::rules::{Corner, Settings};
3use super::rules::{Corner, Settings};
4use super::sounds::{AlertSound, Ringtone, RingtoneAssignments, RingtoneCallType};
5
5
6const META_KEY: &str = "notifications.settings";
6const META_KEY: &str = "notifications.settings";
7const RINGTONE_PREFIX: &str = "ringtone.";
7const RINGTONE_PREFIX: &str = "ringtone.";
@@ -29,18 +29,37 @@ fn serialize(settings: &Settings) -> String {
29 });
29 });
30 [
30 [
31 ("sound".to_owned(), sounds.notification_sound.to_string()),
31 ("sound".to_owned(), sounds.notification_sound.to_string()),
32 ("sound_type".to_owned(), sounds.notification_sound_type.name().to_owned()),
32 (
33 "sound_type".to_owned(),
34 sounds.notification_sound_type.name().to_owned(),
35 ),
33 ("urgent_sound".to_owned(), sounds.urgent_sound.to_string()),
36 ("urgent_sound".to_owned(), sounds.urgent_sound.to_string()),
34 ("urgent_sound_type".to_owned(), sounds.urgent_sound_type.name().to_owned()),
37 (
35 ("call_sound".to_owned(), sounds.call_and_meeting_sound.to_string()),
38 "urgent_sound_type".to_owned(),
36 ("sound_when_busy".to_owned(), sounds.sound_when_busy.to_string()),
39 sounds.urgent_sound_type.name().to_owned(),
37 ("mentions_only".to_owned(), settings.mentions_only.to_string()),
40 ),
38 ("preview".to_owned(), settings.preview.to_string()),
41 (
42 "call_sound".to_owned(),
43 sounds.call_and_meeting_sound.to_string(),
44 ),
45 (
46 "sound_when_busy".to_owned(),
47 sounds.sound_when_busy.to_string(),
48 ),
39 ("corner".to_owned(), settings.corner.key().to_owned()),
49 ("corner".to_owned(), settings.corner.key().to_owned()),
40 ("taskbar_flash".to_owned(), settings.flash.to_string()),
50 ("taskbar_flash".to_owned(), settings.flash.to_string()),
41 ("close_to_tray".to_owned(), settings.close_to_tray.to_string()),
51 (
42 ("do_not_disturb".to_owned(), settings.do_not_disturb.to_string()),
52 "close_to_tray".to_owned(),
43 ("mute_in_calls".to_owned(), settings.mute_in_calls.to_string()),
53 settings.close_to_tray.to_string(),
54 ),
55 (
56 "do_not_disturb".to_owned(),
57 settings.do_not_disturb.to_string(),
58 ),
59 (
60 "mute_in_calls".to_owned(),
61 settings.mute_in_calls.to_string(),
62 ),
44 ]
63 ]
45 .into_iter()
64 .into_iter()
46 .chain(ringtones)
65 .chain(ringtones)
@@ -64,8 +83,6 @@ fn parse(text: &str) -> Settings {
64 "urgent_sound_type" => set_alert_sound(&mut sounds.urgent_sound_type, value),
83 "urgent_sound_type" => set_alert_sound(&mut sounds.urgent_sound_type, value),
65 "call_sound" => sounds.call_and_meeting_sound = flag,
84 "call_sound" => sounds.call_and_meeting_sound = flag,
66 "sound_when_busy" => sounds.sound_when_busy = flag,
85 "sound_when_busy" => sounds.sound_when_busy = flag,
67 "mentions_only" => settings.mentions_only = flag,
68 "preview" => settings.preview = flag,
69 "corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),
86 "corner" => settings.corner = Corner::from_key(value).unwrap_or_default(),
70 "taskbar_flash" => settings.flash = flag,
87 "taskbar_flash" => settings.flash = flag,
71 "close_to_tray" => settings.close_to_tray = flag,
88 "close_to_tray" => settings.close_to_tray = flag,
@@ -100,8 +117,7 @@ mod tests {
100 #[test]
117 #[test]
101 fn round_trips_every_field() {
118 fn round_trips_every_field() {
102 let settings = Settings {
119 let settings = Settings {
103 mentions_only: true,
120 account: Default::default(),
104 preview: false,
105 corner: Corner::TopLeft,
121 corner: Corner::TopLeft,
106 flash: false,
122 flash: false,
107 close_to_tray: false,
123 close_to_tray: false,
@@ -133,6 +149,10 @@ mod tests {
133 #[test]
149 #[test]
134 fn the_old_synthesized_ringtone_key_is_ignored() {
150 fn the_old_synthesized_ringtone_key_is_ignored() {
135 assert_eq!(parse("ringtone=chime"), Settings::default());
151 assert_eq!(parse("ringtone=chime"), Settings::default());
152 assert_eq!(
153 parse("mentions_only=true\npreview=false"),
154 Settings::default()
155 );
136 }
156 }
137
157
138 #[test]
158 #[test]
crates/app-state/src/notify/stack.rs +1 −0
@@ -422,6 +422,7 @@ mod tests {
422 422 mentions_me: mention,
423 423 muted: false,
424 424 signals: Default::default(),
425 chat: Default::default(),
425 426 created_at: chrono::Utc::now(),
426 427 }
427 428 }
@@ -422,6 +422,7 @@ mod tests {
422 mentions_me: mention,
422 mentions_me: mention,
423 muted: false,
423 muted: false,
424 signals: Default::default(),
424 signals: Default::default(),
425 chat: Default::default(),
425 created_at: chrono::Utc::now(),
426 created_at: chrono::Utc::now(),
426 }
427 }
427 }
428 }
crates/app/src/notify/center.rs +32 −8
@@ -13,7 +13,7 @@ use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};
13 13 use super::ring_view::RingView;
14 14 use super::rules::{
15 15 ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide, in_call,
16 meeting_start_sound, ringtone_for, should_flash, should_ringback,
16 meeting_start_sound, ringtone_for, should_flash, should_ringback, shows_preview,
17 17 };
18 18 use super::settings;
19 19 use super::sound_cache::{self, SoundHandle};
@@ -106,7 +106,8 @@ impl NotificationCenter {
106 106 window: &mut Window,
107 107 cx: &mut Context<Self>,
108 108 ) -> Self {
109 let settings = settings::load(&app.read(cx).store);
109 let mut settings = settings::load(&app.read(cx).store);
110 settings.account = app.read(cx).account_chat_settings().notifications;
110 111 let app_icon = active_appearance::current(cx).app_icon;
111 112 let tray = if app.read(cx).mode.demo {
112 113 None
@@ -272,13 +273,19 @@ impl NotificationCenter {
272 273 self.sync_tray();
273 274 if self.settings.sounds != previous {
274 275 let updated = self.settings.sounds.clone();
275 self.app
276 .update(cx, |state, cx| state.save_sound_settings(previous, updated, cx));
276 self.app.update(cx, |state, cx| {
277 state.save_sound_settings(previous, updated, cx)
278 });
277 279 self.prefetch_sounds(cx);
278 280 }
279 281 cx.notify();
280 282 }
281 283
284 fn on_account_notifications(&mut self, cx: &mut Context<Self>) {
285 self.settings.account = self.app.read(cx).account_chat_settings().notifications;
286 cx.notify();
287 }
288
282 289 fn on_account_sounds(&mut self, cx: &mut Context<Self>) {
283 290 let Some(account) = self.app.read(cx).account_sounds.clone() else {
284 291 return;
@@ -328,6 +335,7 @@ impl NotificationCenter {
328 335 AppEvent::CallTone(tone) => self.on_call_tone(*tone, cx),
329 336 AppEvent::Call => self.sync_call_sounds(cx),
330 337 AppEvent::SoundSettings => self.on_account_sounds(cx),
338 AppEvent::ChatSettings => self.on_account_notifications(cx),
331 339 _ => {}
332 340 }
333 341 }
@@ -390,7 +398,11 @@ impl NotificationCenter {
390 398 .unwrap_or(false)
391 399 }
392 400
393 pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {
401 pub fn handle_incoming(&mut self, mut incoming: Incoming, cx: &mut Context<Self>) {
402 incoming.chat.desktop = self
403 .app
404 .read(cx)
405 .chat_desktop_notifications(&incoming.conversation_id);
394 406 let bubble_text = match &incoming.preview {
395 407 Preview::Text(text) => text.replace('\n', " "),
396 408 Preview::Image => "Sent a picture".to_owned(),
@@ -558,7 +570,9 @@ impl NotificationCenter {
558 570 .map(|toast| {
559 571 let lines = match &toast.agent {
560 572 Some(agent) => wrapped_lines(&agent.body, layout::AGENT_BODY_WIDTH, cx),
561 None => preview_lines(&describe(toast, self.settings.preview).preview, cx),
573 None => {
574 preview_lines(&describe(toast, shows_preview(&self.settings)).preview, cx)
575 }
562 576 };
563 577 layout::toast_height(toast, lines)
564 578 })
@@ -708,7 +722,12 @@ impl NotificationCenter {
708 722 let reconnecting =
709 723 model.is_some_and(|model| model.is_reconnecting() && !model.lobby) && !self.demo_mode;
710 724 sync_loop(&mut self.ringback, ringback, CallTone::OutgoingRinging, cx);
711 sync_loop(&mut self.reconnecting, reconnecting, CallTone::Reconnecting, cx);
725 sync_loop(
726 &mut self.reconnecting,
727 reconnecting,
728 CallTone::Reconnecting,
729 cx,
730 );
712 731 }
713 732
714 733 fn slide_offset(&self, opened: Instant, area: WorkArea) -> i32 {
@@ -1118,6 +1137,7 @@ impl NotificationCenter {
1118 1137 mentions_me: false,
1119 1138 muted: false,
1120 1139 signals: Default::default(),
1140 chat: Default::default(),
1121 1141 created_at: Utc::now(),
1122 1142 };
1123 1143 let decision = Decision {
@@ -1287,6 +1307,7 @@ fn demo_incoming() -> Vec<Incoming> {
1287 1307 mentions_me: mention,
1288 1308 muted: false,
1289 1309 signals: Default::default(),
1310 chat: Default::default(),
1290 1311 created_at: Utc::now(),
1291 1312 };
1292 1313 vec![
@@ -1363,7 +1384,10 @@ mod tests {
1363 1384 scale: 1.,
1364 1385 };
1365 1386 let options = popup_options(slot, area);
1366 assert_eq!(options.window_background, WindowBackgroundAppearance::Transparent);
1387 assert_eq!(
1388 options.window_background,
1389 WindowBackgroundAppearance::Transparent
1390 );
1367 1391 assert_eq!(options.kind, WindowKind::PopUp);
1368 1392 }
1369 1393
@@ -13,7 +13,7 @@ use super::platform::{self, NativeHandle, Tray, TrayCommand, WorkArea};
13use super::ring_view::RingView;
13use super::ring_view::RingView;
14use super::rules::{
14use super::rules::{
15 ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide, in_call,
15 ChatKind, Decision, Environment, Incoming, Preview, Settings, SoundThrottle, decide, in_call,
16 meeting_start_sound, ringtone_for, should_flash, should_ringback,
16 meeting_start_sound, ringtone_for, should_flash, should_ringback, shows_preview,
17};
17};
18use super::settings;
18use super::settings;
19use super::sound_cache::{self, SoundHandle};
19use super::sound_cache::{self, SoundHandle};
@@ -106,7 +106,8 @@ impl NotificationCenter {
106 window: &mut Window,
106 window: &mut Window,
107 cx: &mut Context<Self>,
107 cx: &mut Context<Self>,
108 ) -> Self {
108 ) -> Self {
109 let settings = settings::load(&app.read(cx).store);
109 let mut settings = settings::load(&app.read(cx).store);
110 settings.account = app.read(cx).account_chat_settings().notifications;
110 let app_icon = active_appearance::current(cx).app_icon;
111 let app_icon = active_appearance::current(cx).app_icon;
111 let tray = if app.read(cx).mode.demo {
112 let tray = if app.read(cx).mode.demo {
112 None
113 None
@@ -272,13 +273,19 @@ impl NotificationCenter {
272 self.sync_tray();
273 self.sync_tray();
273 if self.settings.sounds != previous {
274 if self.settings.sounds != previous {
274 let updated = self.settings.sounds.clone();
275 let updated = self.settings.sounds.clone();
275 self.app
276 self.app.update(cx, |state, cx| {
276 .update(cx, |state, cx| state.save_sound_settings(previous, updated, cx));
277 state.save_sound_settings(previous, updated, cx)
278 });
277 self.prefetch_sounds(cx);
279 self.prefetch_sounds(cx);
278 }
280 }
279 cx.notify();
281 cx.notify();
280 }
282 }
281
283
284 fn on_account_notifications(&mut self, cx: &mut Context<Self>) {
285 self.settings.account = self.app.read(cx).account_chat_settings().notifications;
286 cx.notify();
287 }
288
282 fn on_account_sounds(&mut self, cx: &mut Context<Self>) {
289 fn on_account_sounds(&mut self, cx: &mut Context<Self>) {
283 let Some(account) = self.app.read(cx).account_sounds.clone() else {
290 let Some(account) = self.app.read(cx).account_sounds.clone() else {
284 return;
291 return;
@@ -328,6 +335,7 @@ impl NotificationCenter {
328 AppEvent::CallTone(tone) => self.on_call_tone(*tone, cx),
335 AppEvent::CallTone(tone) => self.on_call_tone(*tone, cx),
329 AppEvent::Call => self.sync_call_sounds(cx),
336 AppEvent::Call => self.sync_call_sounds(cx),
330 AppEvent::SoundSettings => self.on_account_sounds(cx),
337 AppEvent::SoundSettings => self.on_account_sounds(cx),
338 AppEvent::ChatSettings => self.on_account_notifications(cx),
331 _ => {}
339 _ => {}
332 }
340 }
333 }
341 }
@@ -390,7 +398,11 @@ impl NotificationCenter {
390 .unwrap_or(false)
398 .unwrap_or(false)
391 }
399 }
392
400
393 pub fn handle_incoming(&mut self, incoming: Incoming, cx: &mut Context<Self>) {
401 pub fn handle_incoming(&mut self, mut incoming: Incoming, cx: &mut Context<Self>) {
402 incoming.chat.desktop = self
403 .app
404 .read(cx)
405 .chat_desktop_notifications(&incoming.conversation_id);
394 let bubble_text = match &incoming.preview {
406 let bubble_text = match &incoming.preview {
395 Preview::Text(text) => text.replace('\n', " "),
407 Preview::Text(text) => text.replace('\n', " "),
396 Preview::Image => "Sent a picture".to_owned(),
408 Preview::Image => "Sent a picture".to_owned(),
@@ -558,7 +570,9 @@ impl NotificationCenter {
558 .map(|toast| {
570 .map(|toast| {
559 let lines = match &toast.agent {
571 let lines = match &toast.agent {
560 Some(agent) => wrapped_lines(&agent.body, layout::AGENT_BODY_WIDTH, cx),
572 Some(agent) => wrapped_lines(&agent.body, layout::AGENT_BODY_WIDTH, cx),
561 None => preview_lines(&describe(toast, self.settings.preview).preview, cx),
573 None => {
574 preview_lines(&describe(toast, shows_preview(&self.settings)).preview, cx)
575 }
562 };
576 };
563 layout::toast_height(toast, lines)
577 layout::toast_height(toast, lines)
564 })
578 })
@@ -708,7 +722,12 @@ impl NotificationCenter {
708 let reconnecting =
722 let reconnecting =
709 model.is_some_and(|model| model.is_reconnecting() && !model.lobby) && !self.demo_mode;
723 model.is_some_and(|model| model.is_reconnecting() && !model.lobby) && !self.demo_mode;
710 sync_loop(&mut self.ringback, ringback, CallTone::OutgoingRinging, cx);
724 sync_loop(&mut self.ringback, ringback, CallTone::OutgoingRinging, cx);
711 sync_loop(&mut self.reconnecting, reconnecting, CallTone::Reconnecting, cx);
725 sync_loop(
726 &mut self.reconnecting,
727 reconnecting,
728 CallTone::Reconnecting,
729 cx,
730 );
712 }
731 }
713
732
714 fn slide_offset(&self, opened: Instant, area: WorkArea) -> i32 {
733 fn slide_offset(&self, opened: Instant, area: WorkArea) -> i32 {
@@ -1118,6 +1137,7 @@ impl NotificationCenter {
1118 mentions_me: false,
1137 mentions_me: false,
1119 muted: false,
1138 muted: false,
1120 signals: Default::default(),
1139 signals: Default::default(),
1140 chat: Default::default(),
1121 created_at: Utc::now(),
1141 created_at: Utc::now(),
1122 };
1142 };
1123 let decision = Decision {
1143 let decision = Decision {
@@ -1287,6 +1307,7 @@ fn demo_incoming() -> Vec<Incoming> {
1287 mentions_me: mention,
1307 mentions_me: mention,
1288 muted: false,
1308 muted: false,
1289 signals: Default::default(),
1309 signals: Default::default(),
1310 chat: Default::default(),
1290 created_at: Utc::now(),
1311 created_at: Utc::now(),
1291 };
1312 };
1292 vec![
1313 vec![
@@ -1363,7 +1384,10 @@ mod tests {
1363 scale: 1.,
1384 scale: 1.,
1364 };
1385 };
1365 let options = popup_options(slot, area);
1386 let options = popup_options(slot, area);
1366 assert_eq!(options.window_background, WindowBackgroundAppearance::Transparent);
1387 assert_eq!(
1388 options.window_background,
1389 WindowBackgroundAppearance::Transparent
1390 );
1367 assert_eq!(options.kind, WindowKind::PopUp);
1391 assert_eq!(options.kind, WindowKind::PopUp);
1368 }
1392 }
1369
1393
crates/app/src/notify/toast.rs +1 −1
@@ -485,7 +485,7 @@ impl Render for ToastView {
485 485 let id = self.id;
486 486 let (model, preview_on) = {
487 487 let center = self.center.read(cx);
488 (center.model(id).cloned(), center.settings().preview)
488 (center.model(id).cloned(), center.settings().account.show_preview)
489 489 };
490 490 let Some(model) = model else {
491 491 return div().size_full().bg(theme::popup()).into_any_element();
@@ -485,7 +485,7 @@ impl Render for ToastView {
485 let id = self.id;
485 let id = self.id;
486 let (model, preview_on) = {
486 let (model, preview_on) = {
487 let center = self.center.read(cx);
487 let center = self.center.read(cx);
488 (center.model(id).cloned(), center.settings().preview)
488 (center.model(id).cloned(), center.settings().account.show_preview)
489 };
489 };
490 let Some(model) = model else {
490 let Some(model) = model else {
491 return div().size_full().bg(theme::popup()).into_any_element();
491 return div().size_full().bg(theme::popup()).into_any_element();
crates/app/src/views/composer.rs +108 −40
@@ -24,9 +24,10 @@ use gpui_kit::component::{
24 24 use gpui_kit::prelude::FluentBuilder as _;
25 25 use gpui_kit::*;
26 26 use teams_core::{
27 Draft, DraftLine, Edit, FileReference, FormatState, LineKind, LinkPreview, MarkKind,
28 MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TABLE_MARK, TableEdit, TypingStyle,
29 UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,
27 Draft, DraftLine, Edit, EnterKeyBehavior, FileReference, FormatState, LineKind, LinkPreview,
28 MarkKind, MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TABLE_MARK, TableEdit,
29 TypingStyle, UpArrowBehavior, UploadedFile, changed_span, has_markdown, link_url, map_offset,
30 reverse_edits,
30 31 };
31 32
32 33 mod drafts;
@@ -120,6 +121,7 @@ pub enum ComposerEvent {
120 121 send_at: DateTime<Utc>,
121 122 },
122 123 EditLast,
124 FocusMessages,
123 125 Typing(bool),
124 126 }
125 127
@@ -230,6 +232,19 @@ pub struct Composer {
230 232
231 233 impl EventEmitter<ComposerEvent> for Composer {}
232 234
235 /// With "Start a new line", plain Enter breaks the line and only Ctrl+Enter sends.
236 pub fn enter_starts_line(behavior: EnterKeyBehavior, shift: bool, secondary: bool) -> bool {
237 behavior == EnterKeyBehavior::NewLine && !shift && !secondary
238 }
239
240 pub fn up_arrow_event(behavior: UpArrowBehavior) -> Option<ComposerEvent> {
241 match behavior {
242 UpArrowBehavior::EditLastMessage => Some(ComposerEvent::EditLast),
243 UpArrowBehavior::NavigateToMessages => Some(ComposerEvent::FocusMessages),
244 UpArrowBehavior::StayInCompose => None,
245 }
246 }
247
233 248 pub fn is_plain_enter(event: &InputEvent) -> bool {
234 249 matches!(event, InputEvent::PressEnter { shift: false, .. })
235 250 }
@@ -536,7 +551,10 @@ impl Composer {
536 551 return;
537 552 }
538 553 let typed = emoji::typed_char(&previous, self.draft.text(), cursor);
539 if typed.is_some() && self.convert_markdown(cursor, window, cx) {
554 if typed.is_some()
555 && !self.app.read(cx).markdown_mode
556 && self.convert_markdown(cursor, window, cx)
557 {
540 558 return;
541 559 }
542 560 if matches!(typed, Some(' ' | '\n')) && self.convert_link(cursor, window, cx) {
@@ -1706,12 +1724,15 @@ impl Composer {
1706 1724 draft.replace(range, glyph);
1707 1725 draft.take_edits();
1708 1726 }
1709 let mentions = state
1727 let mentions: Vec<MentionInput> = state
1710 1728 .tokens()
1711 1729 .iter()
1712 1730 .filter_map(|span| self.mention_inputs.get(span.token().id().as_ref()))
1713 1731 .cloned()
1714 1732 .collect();
1733 if self.app.read(cx).markdown_mode && mentions.is_empty() && image_ids.is_empty() {
1734 draft = Draft::from_markdown(draft.text());
1735 }
1715 1736 Outgoing {
1716 1737 draft,
1717 1738 subject: None,
@@ -2426,7 +2447,10 @@ impl Composer {
2426 2447
2427 2448 fn render_toolbar(&self, focused: bool, cx: &mut Context<Self>) -> Option<AnyElement> {
2428 2449 let composer = cx.entity().downgrade();
2429 let floating = focused && self.toolbar_requested(cx) && !self.format_bar_open();
2450 let floating = focused
2451 && self.toolbar_requested(cx)
2452 && !self.format_bar_open()
2453 && !self.app.read(cx).markdown_mode;
2430 2454 if self.link_editor.is_none() && !floating {
2431 2455 return None;
2432 2456 }
@@ -2729,36 +2753,39 @@ impl Render for Composer {
2729 2753 ))
2730 2754 .on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))
2731 2755 });
2732 let format_open = self.format_bar_open();
2733 let format_toggle = div()
2734 .id("composer-format")
2735 .debug_selector(|| COMPOSER_FORMAT_TAG.into())
2736 .size(px(COMPOSER_BUTTON_SIZE))
2737 .flex_none()
2738 .flex()
2739 .items_center()
2740 .justify_center()
2741 .rounded(px(8.))
2742 .cursor_pointer()
2743 .when(format_open, |button| button.bg(theme::popup_hover()))
2744 .hover(|button| button.bg(theme::popup_hover()))
2745 .tooltip(move |window, cx| {
2746 Tooltip::new(format_toolbar::toggle_tooltip(format_open)).build(window, cx)
2747 })
2748 .child(symbol(
2749 format_toolbar::toggle_symbol(format_open),
2750 COMPOSER_ICON_SIZE,
2751 if format_open {
2752 theme::accent_soft()
2753 } else {
2754 theme::text_muted()
2755 },
2756 ))
2757 .on_mouse_down(MouseButton::Left, |_, window, cx| {
2758 window.prevent_default();
2759 cx.stop_propagation();
2760 })
2761 .on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)));
2756 let markdown_mode = self.app.read(cx).markdown_mode;
2757 let format_open = self.format_bar_open() && !markdown_mode;
2758 let format_toggle = (!markdown_mode).then(|| {
2759 div()
2760 .id("composer-format")
2761 .debug_selector(|| COMPOSER_FORMAT_TAG.into())
2762 .size(px(COMPOSER_BUTTON_SIZE))
2763 .flex_none()
2764 .flex()
2765 .items_center()
2766 .justify_center()
2767 .rounded(px(8.))
2768 .cursor_pointer()
2769 .when(format_open, |button| button.bg(theme::popup_hover()))
2770 .hover(|button| button.bg(theme::popup_hover()))
2771 .tooltip(move |window, cx| {
2772 Tooltip::new(format_toolbar::toggle_tooltip(format_open)).build(window, cx)
2773 })
2774 .child(symbol(
2775 format_toolbar::toggle_symbol(format_open),
2776 COMPOSER_ICON_SIZE,
2777 if format_open {
2778 theme::accent_soft()
2779 } else {
2780 theme::text_muted()
2781 },
2782 ))
2783 .on_mouse_down(MouseButton::Left, |_, window, cx| {
2784 window.prevent_default();
2785 cx.stop_propagation();
2786 })
2787 .on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)))
2788 });
2762 2789 let format_bar = format_open.then(|| self.render_format_bar(window, cx));
2763 2790 let composer = cx.weak_entity();
2764 2791 let tokens_composer = composer.clone();
@@ -2979,8 +3006,12 @@ impl Render for Composer {
2979 3006 } else if this.popup_is_open() {
2980 3007 this.move_highlight(-1, cx);
2981 3008 cx.stop_propagation();
2982 } else if this.editing.is_none() && this.is_empty(cx) {
2983 cx.emit(ComposerEvent::EditLast);
3009 } else if this.editing.is_none()
3010 && this.is_empty(cx)
3011 && let Some(event) =
3012 up_arrow_event(this.app.read(cx).account_chat_settings().up_arrow)
3013 {
3014 cx.emit(event);
2984 3015 cx.stop_propagation();
2985 3016 }
2986 3017 }))
@@ -3026,6 +3057,19 @@ impl Render for Composer {
3026 3057 } else if this.popup_is_open() {
3027 3058 this.accept_popup(window, cx);
3028 3059 cx.stop_propagation();
3060 } else if enter_starts_line(
3061 this.app.read(cx).account_chat_settings().enter_key,
3062 action.shift,
3063 action.secondary,
3064 ) {
3065 cx.stop_propagation();
3066 window.dispatch_action(
3067 Box::new(Enter {
3068 secondary: false,
3069 shift: true,
3070 }),
3071 cx,
3072 );
3029 3073 } else if this.break_line(action.shift, window, cx) {
3030 3074 cx.stop_propagation();
3031 3075 }
@@ -3154,7 +3198,7 @@ impl Render for Composer {
3154 3198 .debug_selector(|| COMPOSER_LEADING_TAG.into())
3155 3199 .flex_none()
3156 3200 .gap(px(COMPOSER_BUTTON_INSET))
3157 .child(format_toggle)
3201 .children(format_toggle)
3158 3202 .children(fun)
3159 3203 .children(attach),
3160 3204 )
@@ -3194,7 +3238,31 @@ impl Render for Composer {
3194 3238
3195 3239 #[cfg(test)]
3196 3240 mod tests {
3197 use super::{active_mention, submitted_text};
3241 use super::{
3242 ComposerEvent, EnterKeyBehavior, UpArrowBehavior, active_mention, enter_starts_line,
3243 submitted_text, up_arrow_event,
3244 };
3245
3246 #[test]
3247 fn new_line_mode_keeps_plain_enter_and_sends_on_ctrl_enter() {
3248 assert!(enter_starts_line(EnterKeyBehavior::NewLine, false, false));
3249 assert!(!enter_starts_line(EnterKeyBehavior::NewLine, false, true));
3250 assert!(!enter_starts_line(EnterKeyBehavior::NewLine, true, false));
3251 assert!(!enter_starts_line(EnterKeyBehavior::Send, false, false));
3252 }
3253
3254 #[test]
3255 fn up_arrow_follows_the_account_setting() {
3256 assert!(matches!(
3257 up_arrow_event(UpArrowBehavior::EditLastMessage),
3258 Some(ComposerEvent::EditLast)
3259 ));
3260 assert!(matches!(
3261 up_arrow_event(UpArrowBehavior::NavigateToMessages),
3262 Some(ComposerEvent::FocusMessages)
3263 ));
3264 assert!(up_arrow_event(UpArrowBehavior::StayInCompose).is_none());
3265 }
3198 3266 use gpui_kit::component::input::InputEvent;
3199 3267
3200 3268 fn press(shift: bool) -> InputEvent {
@@ -24,9 +24,10 @@ use gpui_kit::component::{
24use gpui_kit::prelude::FluentBuilder as _;
24use gpui_kit::prelude::FluentBuilder as _;
25use gpui_kit::*;
25use gpui_kit::*;
26use teams_core::{
26use teams_core::{
27 Draft, DraftLine, Edit, FileReference, FormatState, LineKind, LinkPreview, MarkKind,
27 Draft, DraftLine, Edit, EnterKeyBehavior, FileReference, FormatState, LineKind, LinkPreview,
28 MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TABLE_MARK, TableEdit, TypingStyle,
28 MarkKind, MentionCandidate, MentionInput, OBJECT_MARK, SizeStep, TABLE_MARK, TableEdit,
29 UploadedFile, changed_span, has_markdown, link_url, map_offset, reverse_edits,
29 TypingStyle, UpArrowBehavior, UploadedFile, changed_span, has_markdown, link_url, map_offset,
30 reverse_edits,
30};
31};
31
32
32mod drafts;
33mod drafts;
@@ -120,6 +121,7 @@ pub enum ComposerEvent {
120 send_at: DateTime<Utc>,
121 send_at: DateTime<Utc>,
121 },
122 },
122 EditLast,
123 EditLast,
124 FocusMessages,
123 Typing(bool),
125 Typing(bool),
124}
126}
125
127
@@ -230,6 +232,19 @@ pub struct Composer {
230
232
231impl EventEmitter<ComposerEvent> for Composer {}
233impl EventEmitter<ComposerEvent> for Composer {}
232
234
235/// With "Start a new line", plain Enter breaks the line and only Ctrl+Enter sends.
236pub fn enter_starts_line(behavior: EnterKeyBehavior, shift: bool, secondary: bool) -> bool {
237 behavior == EnterKeyBehavior::NewLine && !shift && !secondary
238}
239
240pub fn up_arrow_event(behavior: UpArrowBehavior) -> Option<ComposerEvent> {
241 match behavior {
242 UpArrowBehavior::EditLastMessage => Some(ComposerEvent::EditLast),
243 UpArrowBehavior::NavigateToMessages => Some(ComposerEvent::FocusMessages),
244 UpArrowBehavior::StayInCompose => None,
245 }
246}
247
233pub fn is_plain_enter(event: &InputEvent) -> bool {
248pub fn is_plain_enter(event: &InputEvent) -> bool {
234 matches!(event, InputEvent::PressEnter { shift: false, .. })
249 matches!(event, InputEvent::PressEnter { shift: false, .. })
235}
250}
@@ -536,7 +551,10 @@ impl Composer {
536 return;
551 return;
537 }
552 }
538 let typed = emoji::typed_char(&previous, self.draft.text(), cursor);
553 let typed = emoji::typed_char(&previous, self.draft.text(), cursor);
539 if typed.is_some() && self.convert_markdown(cursor, window, cx) {
554 if typed.is_some()
555 && !self.app.read(cx).markdown_mode
556 && self.convert_markdown(cursor, window, cx)
557 {
540 return;
558 return;
541 }
559 }
542 if matches!(typed, Some(' ' | '\n')) && self.convert_link(cursor, window, cx) {
560 if matches!(typed, Some(' ' | '\n')) && self.convert_link(cursor, window, cx) {
@@ -1706,12 +1724,15 @@ impl Composer {
1706 draft.replace(range, glyph);
1724 draft.replace(range, glyph);
1707 draft.take_edits();
1725 draft.take_edits();
1708 }
1726 }
1709 let mentions = state
1727 let mentions: Vec<MentionInput> = state
1710 .tokens()
1728 .tokens()
1711 .iter()
1729 .iter()
1712 .filter_map(|span| self.mention_inputs.get(span.token().id().as_ref()))
1730 .filter_map(|span| self.mention_inputs.get(span.token().id().as_ref()))
1713 .cloned()
1731 .cloned()
1714 .collect();
1732 .collect();
1733 if self.app.read(cx).markdown_mode && mentions.is_empty() && image_ids.is_empty() {
1734 draft = Draft::from_markdown(draft.text());
1735 }
1715 Outgoing {
1736 Outgoing {
1716 draft,
1737 draft,
1717 subject: None,
1738 subject: None,
@@ -2426,7 +2447,10 @@ impl Composer {
2426
2447
2427 fn render_toolbar(&self, focused: bool, cx: &mut Context<Self>) -> Option<AnyElement> {
2448 fn render_toolbar(&self, focused: bool, cx: &mut Context<Self>) -> Option<AnyElement> {
2428 let composer = cx.entity().downgrade();
2449 let composer = cx.entity().downgrade();
2429 let floating = focused && self.toolbar_requested(cx) && !self.format_bar_open();
2450 let floating = focused
2451 && self.toolbar_requested(cx)
2452 && !self.format_bar_open()
2453 && !self.app.read(cx).markdown_mode;
2430 if self.link_editor.is_none() && !floating {
2454 if self.link_editor.is_none() && !floating {
2431 return None;
2455 return None;
2432 }
2456 }
@@ -2729,36 +2753,39 @@ impl Render for Composer {
2729 ))
2753 ))
2730 .on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))
2754 .on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))
2731 });
2755 });
2732 let format_open = self.format_bar_open();
2756 let markdown_mode = self.app.read(cx).markdown_mode;
2733 let format_toggle = div()
2757 let format_open = self.format_bar_open() && !markdown_mode;
2734 .id("composer-format")
2758 let format_toggle = (!markdown_mode).then(|| {
2735 .debug_selector(|| COMPOSER_FORMAT_TAG.into())
2759 div()
2736 .size(px(COMPOSER_BUTTON_SIZE))
2760 .id("composer-format")
2737 .flex_none()
2761 .debug_selector(|| COMPOSER_FORMAT_TAG.into())
2738 .flex()
2762 .size(px(COMPOSER_BUTTON_SIZE))
2739 .items_center()
2763 .flex_none()
2740 .justify_center()
2764 .flex()
2741 .rounded(px(8.))
2765 .items_center()
2742 .cursor_pointer()
2766 .justify_center()
2743 .when(format_open, |button| button.bg(theme::popup_hover()))
2767 .rounded(px(8.))
2744 .hover(|button| button.bg(theme::popup_hover()))
2768 .cursor_pointer()
2745 .tooltip(move |window, cx| {
2769 .when(format_open, |button| button.bg(theme::popup_hover()))
2746 Tooltip::new(format_toolbar::toggle_tooltip(format_open)).build(window, cx)
2770 .hover(|button| button.bg(theme::popup_hover()))
2747 })
2771 .tooltip(move |window, cx| {
2748 .child(symbol(
2772 Tooltip::new(format_toolbar::toggle_tooltip(format_open)).build(window, cx)
2749 format_toolbar::toggle_symbol(format_open),
2773 })
2750 COMPOSER_ICON_SIZE,
2774 .child(symbol(
2751 if format_open {
2775 format_toolbar::toggle_symbol(format_open),
2752 theme::accent_soft()
2776 COMPOSER_ICON_SIZE,
2753 } else {
2777 if format_open {
2754 theme::text_muted()
2778 theme::accent_soft()
2755 },
2779 } else {
2756 ))
2780 theme::text_muted()
2757 .on_mouse_down(MouseButton::Left, |_, window, cx| {
2781 },
2758 window.prevent_default();
2782 ))
2759 cx.stop_propagation();
2783 .on_mouse_down(MouseButton::Left, |_, window, cx| {
2760 })
2784 window.prevent_default();
2761 .on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)));
2785 cx.stop_propagation();
2786 })
2787 .on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)))
2788 });
2762 let format_bar = format_open.then(|| self.render_format_bar(window, cx));
2789 let format_bar = format_open.then(|| self.render_format_bar(window, cx));
2763 let composer = cx.weak_entity();
2790 let composer = cx.weak_entity();
2764 let tokens_composer = composer.clone();
2791 let tokens_composer = composer.clone();
@@ -2979,8 +3006,12 @@ impl Render for Composer {
2979 } else if this.popup_is_open() {
3006 } else if this.popup_is_open() {
2980 this.move_highlight(-1, cx);
3007 this.move_highlight(-1, cx);
2981 cx.stop_propagation();
3008 cx.stop_propagation();
2982 } else if this.editing.is_none() && this.is_empty(cx) {
3009 } else if this.editing.is_none()
2983 cx.emit(ComposerEvent::EditLast);
3010 && this.is_empty(cx)
3011 && let Some(event) =
3012 up_arrow_event(this.app.read(cx).account_chat_settings().up_arrow)
3013 {
3014 cx.emit(event);
2984 cx.stop_propagation();
3015 cx.stop_propagation();
2985 }
3016 }
2986 }))
3017 }))
@@ -3026,6 +3057,19 @@ impl Render for Composer {
3026 } else if this.popup_is_open() {
3057 } else if this.popup_is_open() {
3027 this.accept_popup(window, cx);
3058 this.accept_popup(window, cx);
3028 cx.stop_propagation();
3059 cx.stop_propagation();
3060 } else if enter_starts_line(
3061 this.app.read(cx).account_chat_settings().enter_key,
3062 action.shift,
3063 action.secondary,
3064 ) {
3065 cx.stop_propagation();
3066 window.dispatch_action(
3067 Box::new(Enter {
3068 secondary: false,
3069 shift: true,
3070 }),
3071 cx,
3072 );
3029 } else if this.break_line(action.shift, window, cx) {
3073 } else if this.break_line(action.shift, window, cx) {
3030 cx.stop_propagation();
3074 cx.stop_propagation();
3031 }
3075 }
@@ -3154,7 +3198,7 @@ impl Render for Composer {
3154 .debug_selector(|| COMPOSER_LEADING_TAG.into())
3198 .debug_selector(|| COMPOSER_LEADING_TAG.into())
3155 .flex_none()
3199 .flex_none()
3156 .gap(px(COMPOSER_BUTTON_INSET))
3200 .gap(px(COMPOSER_BUTTON_INSET))
3157 .child(format_toggle)
3201 .children(format_toggle)
3158 .children(fun)
3202 .children(fun)
3159 .children(attach),
3203 .children(attach),
3160 )
3204 )
@@ -3194,7 +3238,31 @@ impl Render for Composer {
3194
3238
3195#[cfg(test)]
3239#[cfg(test)]
3196mod tests {
3240mod tests {
3197 use super::{active_mention, submitted_text};
3241 use super::{
3242 ComposerEvent, EnterKeyBehavior, UpArrowBehavior, active_mention, enter_starts_line,
3243 submitted_text, up_arrow_event,
3244 };
3245
3246 #[test]
3247 fn new_line_mode_keeps_plain_enter_and_sends_on_ctrl_enter() {
3248 assert!(enter_starts_line(EnterKeyBehavior::NewLine, false, false));
3249 assert!(!enter_starts_line(EnterKeyBehavior::NewLine, false, true));
3250 assert!(!enter_starts_line(EnterKeyBehavior::NewLine, true, false));
3251 assert!(!enter_starts_line(EnterKeyBehavior::Send, false, false));
3252 }
3253
3254 #[test]
3255 fn up_arrow_follows_the_account_setting() {
3256 assert!(matches!(
3257 up_arrow_event(UpArrowBehavior::EditLastMessage),
3258 Some(ComposerEvent::EditLast)
3259 ));
3260 assert!(matches!(
3261 up_arrow_event(UpArrowBehavior::NavigateToMessages),
3262 Some(ComposerEvent::FocusMessages)
3263 ));
3264 assert!(up_arrow_event(UpArrowBehavior::StayInCompose).is_none());
3265 }
3198 use gpui_kit::component::input::InputEvent;
3266 use gpui_kit::component::input::InputEvent;
3199
3267
3200 fn press(shift: bool) -> InputEvent {
3268 fn press(shift: bool) -> InputEvent {
crates/app/src/views/conversation.rs +13 −2
@@ -35,13 +35,13 @@ mod render_env;
35 35 mod scheduled;
36 36 mod shared;
37 37
38 use super::add_people_dialog::open_add_people;
38 39 use super::attachments::FileActions;
39 40 use super::avatar::{
40 41 bot_tile, member_stack, person_avatar, spec_avatar, square_avatar, with_presence,
41 42 };
42 43 use super::call_controls::header_call_controls;
43 44 use super::channel_tabs::{ChannelPane, HEADER_TITLE_MAX_WIDTH};
44 use super::add_people_dialog::open_add_people;
45 45 use super::chat_members::members_popover;
46 46 use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};
47 47 use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
@@ -60,6 +60,7 @@ use crate::app_state::{AppEvent, AppState, Selection, composer_name, selection_t
60 60 use crate::backend::Engine;
61 61 use crate::card_state::CardScope;
62 62 use crate::channel_files::DownloadSource;
63 use crate::chat_settings_actions::shown_receipt;
63 64 use crate::data::{existing_one_on_one, is_one_on_one, one_on_one_bot, others};
64 65 use crate::demo_library::DemoLibrary;
65 66 use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
@@ -679,7 +680,7 @@ impl ConversationView {
679 680 | AppEvent::Call => {}
680 681 AppEvent::LiveMeeting => cx.notify(),
681 682 AppEvent::Saved => cx.notify(),
682 AppEvent::Translation => self.rebuild(false, cx),
683 AppEvent::Translation | AppEvent::ChatSettings => self.rebuild(false, cx),
683 684 AppEvent::Pins(conversation_id) => self.on_pins_changed(conversation_id, cx),
684 685 AppEvent::Typing => cx.notify(),
685 686 AppEvent::Scheduled => self.rebuild(false, cx),
@@ -729,6 +730,7 @@ impl ConversationView {
729 730 self.schedule((**outgoing).clone(), *send_at, window, cx)
730 731 }
731 732 ComposerEvent::EditLast => self.edit_last_own(window, cx),
733 ComposerEvent::FocusMessages => window.focus(&self.focus_handle, cx),
732 734 ComposerEvent::Typing(active) => self.send_typing(*active, cx),
733 735 }
734 736 }
@@ -1874,6 +1876,15 @@ impl ConversationView {
1874 1876 }
1875 1877
1876 1878 fn receipts(&self, records: &[MessageRecord], cx: &App) -> HashMap<String, Receipt> {
1879 let settings = self.app.read(cx).account_chat_settings();
1880 let mut receipts = self.raw_receipts(records, cx);
1881 for receipt in receipts.values_mut() {
1882 *receipt = shown_receipt(&settings, *receipt);
1883 }
1884 receipts
1885 }
1886
1887 fn raw_receipts(&self, records: &[MessageRecord], cx: &App) -> HashMap<String, Receipt> {
1877 1888 let state = self.app.read(cx);
1878 1889 if state.mode.demo {
1879 1890 let read_ids = crate::demo::read_message_ids(records);
@@ -35,13 +35,13 @@ mod render_env;
35mod scheduled;
35mod scheduled;
36mod shared;
36mod shared;
37
37
38use super::add_people_dialog::open_add_people;
38use super::attachments::FileActions;
39use super::attachments::FileActions;
39use super::avatar::{
40use super::avatar::{
40 bot_tile, member_stack, person_avatar, spec_avatar, square_avatar, with_presence,
41 bot_tile, member_stack, person_avatar, spec_avatar, square_avatar, with_presence,
41};
42};
42use super::call_controls::header_call_controls;
43use super::call_controls::header_call_controls;
43use super::channel_tabs::{ChannelPane, HEADER_TITLE_MAX_WIDTH};
44use super::channel_tabs::{ChannelPane, HEADER_TITLE_MAX_WIDTH};
44use super::add_people_dialog::open_add_people;
45use super::chat_members::members_popover;
45use super::chat_members::members_popover;
46use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};
46use super::composer::{Composer, ComposerEvent, EditPreview, Outgoing, ReplyPreview};
47use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
47use super::message_actions::{Action, DelegateEntry, MessageMenu, QUICK_REACTION_COUNT};
@@ -60,6 +60,7 @@ use crate::app_state::{AppEvent, AppState, Selection, composer_name, selection_t
60use crate::backend::Engine;
60use crate::backend::Engine;
61use crate::card_state::CardScope;
61use crate::card_state::CardScope;
62use crate::channel_files::DownloadSource;
62use crate::channel_files::DownloadSource;
63use crate::chat_settings_actions::shown_receipt;
63use crate::data::{existing_one_on_one, is_one_on_one, one_on_one_bot, others};
64use crate::data::{existing_one_on_one, is_one_on_one, one_on_one_bot, others};
64use crate::demo_library::DemoLibrary;
65use crate::demo_library::DemoLibrary;
65use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
66use crate::downloads::{self, ClickAction, DownloadKey, Downloads, PartFile, RevealTarget};
@@ -679,7 +680,7 @@ impl ConversationView {
679 | AppEvent::Call => {}
680 | AppEvent::Call => {}
680 AppEvent::LiveMeeting => cx.notify(),
681 AppEvent::LiveMeeting => cx.notify(),
681 AppEvent::Saved => cx.notify(),
682 AppEvent::Saved => cx.notify(),
682 AppEvent::Translation => self.rebuild(false, cx),
683 AppEvent::Translation | AppEvent::ChatSettings => self.rebuild(false, cx),
683 AppEvent::Pins(conversation_id) => self.on_pins_changed(conversation_id, cx),
684 AppEvent::Pins(conversation_id) => self.on_pins_changed(conversation_id, cx),
684 AppEvent::Typing => cx.notify(),
685 AppEvent::Typing => cx.notify(),
685 AppEvent::Scheduled => self.rebuild(false, cx),
686 AppEvent::Scheduled => self.rebuild(false, cx),
@@ -729,6 +730,7 @@ impl ConversationView {
729 self.schedule((**outgoing).clone(), *send_at, window, cx)
730 self.schedule((**outgoing).clone(), *send_at, window, cx)
730 }
731 }
731 ComposerEvent::EditLast => self.edit_last_own(window, cx),
732 ComposerEvent::EditLast => self.edit_last_own(window, cx),
733 ComposerEvent::FocusMessages => window.focus(&self.focus_handle, cx),
732 ComposerEvent::Typing(active) => self.send_typing(*active, cx),
734 ComposerEvent::Typing(active) => self.send_typing(*active, cx),
733 }
735 }
734 }
736 }
@@ -1874,6 +1876,15 @@ impl ConversationView {
1874 }
1876 }
1875
1877
1876 fn receipts(&self, records: &[MessageRecord], cx: &App) -> HashMap<String, Receipt> {
1878 fn receipts(&self, records: &[MessageRecord], cx: &App) -> HashMap<String, Receipt> {
1879 let settings = self.app.read(cx).account_chat_settings();
1880 let mut receipts = self.raw_receipts(records, cx);
1881 for receipt in receipts.values_mut() {
1882 *receipt = shown_receipt(&settings, *receipt);
1883 }
1884 receipts
1885 }
1886
1887 fn raw_receipts(&self, records: &[MessageRecord], cx: &App) -> HashMap<String, Receipt> {
1877 let state = self.app.read(cx);
1888 let state = self.app.read(cx);
1878 if state.mode.demo {
1889 if state.mode.demo {
1879 let read_ids = crate::demo::read_message_ids(records);
1890 let read_ids = crate::demo::read_message_ids(records);
crates/app/src/views/conversation/feed.rs +3 −1
@@ -190,7 +190,9 @@ impl ConversationView {
190 190 let root_id = self.reply_root.clone();
191 191 self.send_typing_in(root_id, *active, cx);
192 192 }
193 ComposerEvent::Schedule { .. } | ComposerEvent::EditLast => {}
193 ComposerEvent::Schedule { .. }
194 | ComposerEvent::EditLast
195 | ComposerEvent::FocusMessages => {}
194 196 }
195 197 }
196 198
@@ -190,7 +190,9 @@ impl ConversationView {
190 let root_id = self.reply_root.clone();
190 let root_id = self.reply_root.clone();
191 self.send_typing_in(root_id, *active, cx);
191 self.send_typing_in(root_id, *active, cx);
192 }
192 }
193 ComposerEvent::Schedule { .. } | ComposerEvent::EditLast => {}
193 ComposerEvent::Schedule { .. }
194 | ComposerEvent::EditLast
195 | ComposerEvent::FocusMessages => {}
194 }
196 }
195 }
197 }
196
198
crates/app/src/views/conversation/render_env.rs +2 −0
@@ -314,6 +314,8 @@ impl RenderEnv {
314 314 call: self.call_actions(message, cx),
315 315 reaction_proposal,
316 316 undo_delete: self.undo_delete_action(message, is_real, view, cx),
317 compact: self.app.read(cx).account_chat_settings().message_density
318 == teams_core::MessageDensity::Compact,
317 319 }
318 320 }
319 321
@@ -314,6 +314,8 @@ impl RenderEnv {
314 call: self.call_actions(message, cx),
314 call: self.call_actions(message, cx),
315 reaction_proposal,
315 reaction_proposal,
316 undo_delete: self.undo_delete_action(message, is_real, view, cx),
316 undo_delete: self.undo_delete_action(message, is_real, view, cx),
317 compact: self.app.read(cx).account_chat_settings().message_density
318 == teams_core::MessageDensity::Compact,
317 }
319 }
318 }
320 }
319
321
crates/app/src/views/message_row.rs +41 −7
@@ -49,6 +49,10 @@ pub const BUBBLE_TAGS: [&str; 12] = [
49 49 pub(super) const AVATAR_SIZE: f32 = 28.;
50 50 pub(super) const AVATAR_GAP: f32 = 8.;
51 51 const SERIES_START_GAP: f32 = 8.;
52 const SERIES_GAP: f32 = 2.;
53 const COMPACT_SERIES_START_GAP: f32 = 4.;
54 const COMPACT_SERIES_GAP: f32 = 1.;
55 const COMPACT_BUBBLE_PADDING_Y: f32 = 4.;
52 56 pub(super) const BODY_SIZE: f32 = 13.5;
53 57 const MAX_WIDTH_RATIO: f32 = 0.7;
54 58 const NARROW_BUBBLE_WIDTH: f32 = 300.;
@@ -89,6 +93,24 @@ pub struct RowActions {
89 93 pub call: CallActions,
90 94 pub reaction_proposal: Option<ReactionPill>,
91 95 pub undo_delete: SharedRowAction,
96 pub compact: bool,
97 }
98
99 pub fn row_spacing(has_previous: bool, compact: bool) -> f32 {
100 match (has_previous, compact) {
101 (true, false) => SERIES_GAP,
102 (true, true) => COMPACT_SERIES_GAP,
103 (false, false) => SERIES_START_GAP,
104 (false, true) => COMPACT_SERIES_START_GAP,
105 }
106 }
107
108 pub fn bubble_padding_y(compact: bool) -> f32 {
109 if compact {
110 COMPACT_BUBBLE_PADDING_Y
111 } else {
112 BUBBLE_PADDING_Y
113 }
92 114 }
93 115
94 116 const TOOLBAR_RIGHT_INSET: f32 = 0.;
@@ -190,7 +212,7 @@ fn bubble(
190 212 .rounded_br(px(corners.bottom_right))
191 213 .rounded_bl(px(corners.bottom_left))
192 214 .px(px(12.))
193 .py(px(BUBBLE_PADDING_Y))
215 .py(px(bubble_padding_y(extras.compact)))
194 216 })
195 217 .text_size(px(BODY_SIZE))
196 218 .line_height(relative(1.45));
@@ -299,7 +321,7 @@ fn bubble(
299 321 .child(
300 322 h_flex()
301 323 .flex_none()
302 .mb(px(META_BOTTOM_INSET - BUBBLE_PADDING_Y))
324 .mb(px(META_BOTTOM_INSET - bubble_padding_y(extras.compact)))
303 325 .child(bubble_meta(row, own, saved)),
304 326 ),
305 327 );
@@ -348,6 +370,7 @@ struct BubbleExtras {
348 370 agent_run: Option<AgentRun>,
349 371 reaction_proposal: Option<ReactionPill>,
350 372 undo_delete: SharedRowAction,
373 compact: bool,
351 374 }
352 375
353 376 fn agent_chip(run: Option<AgentRun>) -> Option<Div> {
@@ -685,6 +708,7 @@ pub fn render_message_row(
685 708 pinned: _,
686 709 reaction_proposal,
687 710 undo_delete,
711 compact,
688 712 } = actions;
689 713 let extras = BubbleExtras {
690 714 hover: hovered,
@@ -700,13 +724,10 @@ pub fn render_message_row(
700 724 agent_run,
701 725 reaction_proposal,
702 726 undo_delete,
727 compact,
703 728 };
704 729 let own = row.own;
705 let spacing = if row.series.has_prev {
706 px(2.)
707 } else {
708 px(SERIES_START_GAP)
709 };
730 let spacing = px(row_spacing(row.series.has_prev, compact));
710 731 let mut container = v_flex().w_full().px(px(ROW_PADDING));
711 732 if let Some(day) = &row.day_header {
712 733 container = container.child(day_separator(day));
@@ -740,3 +761,16 @@ pub fn render_message_row(
740 761 )
741 762 .into_any_element()
742 763 }
764
765 #[cfg(test)]
766 mod density_tests {
767 use super::{META_BOTTOM_INSET, bubble_padding_y, row_spacing};
768
769 #[test]
770 fn compact_density_tightens_gaps_and_bubble_padding() {
771 assert!(row_spacing(false, true) < row_spacing(false, false));
772 assert!(row_spacing(true, true) < row_spacing(true, false));
773 assert!(bubble_padding_y(true) < bubble_padding_y(false));
774 assert!(META_BOTTOM_INSET - bubble_padding_y(true) >= 0.);
775 }
776 }
@@ -49,6 +49,10 @@ pub const BUBBLE_TAGS: [&str; 12] = [
49pub(super) const AVATAR_SIZE: f32 = 28.;
49pub(super) const AVATAR_SIZE: f32 = 28.;
50pub(super) const AVATAR_GAP: f32 = 8.;
50pub(super) const AVATAR_GAP: f32 = 8.;
51const SERIES_START_GAP: f32 = 8.;
51const SERIES_START_GAP: f32 = 8.;
52const SERIES_GAP: f32 = 2.;
53const COMPACT_SERIES_START_GAP: f32 = 4.;
54const COMPACT_SERIES_GAP: f32 = 1.;
55const COMPACT_BUBBLE_PADDING_Y: f32 = 4.;
52pub(super) const BODY_SIZE: f32 = 13.5;
56pub(super) const BODY_SIZE: f32 = 13.5;
53const MAX_WIDTH_RATIO: f32 = 0.7;
57const MAX_WIDTH_RATIO: f32 = 0.7;
54const NARROW_BUBBLE_WIDTH: f32 = 300.;
58const NARROW_BUBBLE_WIDTH: f32 = 300.;
@@ -89,6 +93,24 @@ pub struct RowActions {
89 pub call: CallActions,
93 pub call: CallActions,
90 pub reaction_proposal: Option<ReactionPill>,
94 pub reaction_proposal: Option<ReactionPill>,
91 pub undo_delete: SharedRowAction,
95 pub undo_delete: SharedRowAction,
96 pub compact: bool,
97}
98
99pub fn row_spacing(has_previous: bool, compact: bool) -> f32 {
100 match (has_previous, compact) {
101 (true, false) => SERIES_GAP,
102 (true, true) => COMPACT_SERIES_GAP,
103 (false, false) => SERIES_START_GAP,
104 (false, true) => COMPACT_SERIES_START_GAP,
105 }
106}
107
108pub fn bubble_padding_y(compact: bool) -> f32 {
109 if compact {
110 COMPACT_BUBBLE_PADDING_Y
111 } else {
112 BUBBLE_PADDING_Y
113 }
92}
114}
93
115
94const TOOLBAR_RIGHT_INSET: f32 = 0.;
116const TOOLBAR_RIGHT_INSET: f32 = 0.;
@@ -190,7 +212,7 @@ fn bubble(
190 .rounded_br(px(corners.bottom_right))
212 .rounded_br(px(corners.bottom_right))
191 .rounded_bl(px(corners.bottom_left))
213 .rounded_bl(px(corners.bottom_left))
192 .px(px(12.))
214 .px(px(12.))
193 .py(px(BUBBLE_PADDING_Y))
215 .py(px(bubble_padding_y(extras.compact)))
194 })
216 })
195 .text_size(px(BODY_SIZE))
217 .text_size(px(BODY_SIZE))
196 .line_height(relative(1.45));
218 .line_height(relative(1.45));
@@ -299,7 +321,7 @@ fn bubble(
299 .child(
321 .child(
300 h_flex()
322 h_flex()
301 .flex_none()
323 .flex_none()
302 .mb(px(META_BOTTOM_INSET - BUBBLE_PADDING_Y))
324 .mb(px(META_BOTTOM_INSET - bubble_padding_y(extras.compact)))
303 .child(bubble_meta(row, own, saved)),
325 .child(bubble_meta(row, own, saved)),
304 ),
326 ),
305 );
327 );
@@ -348,6 +370,7 @@ struct BubbleExtras {
348 agent_run: Option<AgentRun>,
370 agent_run: Option<AgentRun>,
349 reaction_proposal: Option<ReactionPill>,
371 reaction_proposal: Option<ReactionPill>,
350 undo_delete: SharedRowAction,
372 undo_delete: SharedRowAction,
373 compact: bool,
351}
374}
352
375
353fn agent_chip(run: Option<AgentRun>) -> Option<Div> {
376fn agent_chip(run: Option<AgentRun>) -> Option<Div> {
@@ -685,6 +708,7 @@ pub fn render_message_row(
685 pinned: _,
708 pinned: _,
686 reaction_proposal,
709 reaction_proposal,
687 undo_delete,
710 undo_delete,
711 compact,
688 } = actions;
712 } = actions;
689 let extras = BubbleExtras {
713 let extras = BubbleExtras {
690 hover: hovered,
714 hover: hovered,
@@ -700,13 +724,10 @@ pub fn render_message_row(
700 agent_run,
724 agent_run,
701 reaction_proposal,
725 reaction_proposal,
702 undo_delete,
726 undo_delete,
727 compact,
703 };
728 };
704 let own = row.own;
729 let own = row.own;
705 let spacing = if row.series.has_prev {
730 let spacing = px(row_spacing(row.series.has_prev, compact));
706 px(2.)
707 } else {
708 px(SERIES_START_GAP)
709 };
710 let mut container = v_flex().w_full().px(px(ROW_PADDING));
731 let mut container = v_flex().w_full().px(px(ROW_PADDING));
711 if let Some(day) = &row.day_header {
732 if let Some(day) = &row.day_header {
712 container = container.child(day_separator(day));
733 container = container.child(day_separator(day));
@@ -740,3 +761,16 @@ pub fn render_message_row(
740 )
761 )
741 .into_any_element()
762 .into_any_element()
742}
763}
764
765#[cfg(test)]
766mod density_tests {
767 use super::{META_BOTTOM_INSET, bubble_padding_y, row_spacing};
768
769 #[test]
770 fn compact_density_tightens_gaps_and_bubble_padding() {
771 assert!(row_spacing(false, true) < row_spacing(false, false));
772 assert!(row_spacing(true, true) < row_spacing(true, false));
773 assert!(bubble_padding_y(true) < bubble_padding_y(false));
774 assert!(META_BOTTOM_INSET - bubble_padding_y(true) >= 0.);
775 }
776}
crates/app/src/views/sidebar.rs +83 −13
@@ -13,7 +13,7 @@ use gpui_kit::*;
13 13 use store::{
14 14 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, SidebarTeam, Store, TeamRecord,
15 15 };
16 use teams_core::is_notes_chat;
16 use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat};
17 17
18 18 use super::activity_panel::ActivityPanel;
19 19 use super::avatar::{spec_avatar, square_avatar, with_presence};
@@ -212,18 +212,18 @@ fn chat_menu(
212 212 if notes {
213 213 return popup;
214 214 }
215 popup = popup
216 .item(
217 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
218 .icon(menu_icon(if muted {
219 IconName::Bell
220 } else {
221 IconName::BellOff
222 }))
223 .on_click(move |_, _, cx| {
224 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
225 }),
226 )
215 popup = popup.item(
216 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
217 .icon(menu_icon(if muted {
218 IconName::Bell
219 } else {
220 IconName::BellOff
221 }))
222 .on_click(move |_, _, cx| {
223 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
224 }),
225 );
226 popup = notifications_submenu(popup, window, cx, context, target)
227 227 .separator()
228 228 .item(
229 229 PopupMenuItem::new("Hide")
@@ -250,6 +250,76 @@ fn chat_menu(
250 250 popup
251 251 }
252 252
253 const CHAT_NOTIFICATION_MODES: [(&str, ChatNotificationMode); 2] = [
254 ("All new messages", ChatNotificationMode::AllNewMessages),
255 ("Mute", ChatNotificationMode::Mute),
256 ];
257
258 const DESKTOP_NOTIFICATIONS: [(&str, DesktopNotifications); 2] = [
259 (
260 "Match settings used for all chats",
261 DesktopNotifications::MatchAllChats,
262 ),
263 ("Don't get desktop notifications", DesktopNotifications::Off),
264 ];
265
266 fn notifications_submenu(
267 popup: PopupMenu,
268 window: &mut Window,
269 cx: &mut Context<PopupMenu>,
270 context: &MenuContext,
271 target: &ChatMenuTarget,
272 ) -> PopupMenu {
273 let state = context.state.clone();
274 let chat_id = target.id.clone();
275 let mode = if target.muted {
276 ChatNotificationMode::Mute
277 } else {
278 ChatNotificationMode::AllNewMessages
279 };
280 let desktop = state.read(cx).chat_desktop_notifications(&chat_id);
281 popup.submenu_with_icon(
282 Some(menu_icon(IconName::Bell)),
283 "Manage notifications",
284 window,
285 cx,
286 move |submenu, _, _| {
287 let choose = |chosen_mode: ChatNotificationMode,
288 chosen_desktop: DesktopNotifications| {
289 let (state, chat_id) = (state.clone(), chat_id.clone());
290 move |_: &ClickEvent, _: &mut Window, cx: &mut App| {
291 state.update(cx, |state, cx| {
292 state.set_chat_notifications(&chat_id, chosen_mode, chosen_desktop, cx)
293 });
294 }
295 };
296 let submenu = submenu.label("Chat notification mode");
297 let submenu =
298 CHAT_NOTIFICATION_MODES
299 .iter()
300 .fold(submenu, |submenu, (label, value)| {
301 submenu.item(
302 PopupMenuItem::new(*label)
303 .checked(*value == mode)
304 .on_click(choose(*value, desktop)),
305 )
306 });
307 let submenu = submenu
308 .separator()
309 .label("Set a desktop notification preference");
310 DESKTOP_NOTIFICATIONS
311 .iter()
312 .fold(submenu, |submenu, (label, value)| {
313 submenu.item(
314 PopupMenuItem::new(*label)
315 .checked(*value == desktop)
316 .on_click(choose(mode, *value)),
317 )
318 })
319 },
320 )
321 }
322
253 323 #[derive(Clone)]
254 324 struct SectionMenuTarget {
255 325 id: String,
@@ -13,7 +13,7 @@ use gpui_kit::*;
13use store::{
13use store::{
14 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, SidebarTeam, Store, TeamRecord,
14 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, SidebarTeam, Store, TeamRecord,
15};
15};
16use teams_core::is_notes_chat;
16use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat};
17
17
18use super::activity_panel::ActivityPanel;
18use super::activity_panel::ActivityPanel;
19use super::avatar::{spec_avatar, square_avatar, with_presence};
19use super::avatar::{spec_avatar, square_avatar, with_presence};
@@ -212,18 +212,18 @@ fn chat_menu(
212 if notes {
212 if notes {
213 return popup;
213 return popup;
214 }
214 }
215 popup = popup
215 popup = popup.item(
216 .item(
216 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
217 PopupMenuItem::new(if muted { "Unmute" } else { "Mute" })
217 .icon(menu_icon(if muted {
218 .icon(menu_icon(if muted {
218 IconName::Bell
219 IconName::Bell
219 } else {
220 } else {
220 IconName::BellOff
221 IconName::BellOff
221 }))
222 }))
222 .on_click(move |_, _, cx| {
223 .on_click(move |_, _, cx| {
223 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
224 mute_state.update(cx, |state, cx| state.set_chat_muted(&mute_id, !muted, cx));
224 }),
225 }),
225 );
226 )
226 popup = notifications_submenu(popup, window, cx, context, target)
227 .separator()
227 .separator()
228 .item(
228 .item(
229 PopupMenuItem::new("Hide")
229 PopupMenuItem::new("Hide")
@@ -250,6 +250,76 @@ fn chat_menu(
250 popup
250 popup
251}
251}
252
252
253const CHAT_NOTIFICATION_MODES: [(&str, ChatNotificationMode); 2] = [
254 ("All new messages", ChatNotificationMode::AllNewMessages),
255 ("Mute", ChatNotificationMode::Mute),
256];
257
258const DESKTOP_NOTIFICATIONS: [(&str, DesktopNotifications); 2] = [
259 (
260 "Match settings used for all chats",
261 DesktopNotifications::MatchAllChats,
262 ),
263 ("Don't get desktop notifications", DesktopNotifications::Off),
264];
265
266fn notifications_submenu(
267 popup: PopupMenu,
268 window: &mut Window,
269 cx: &mut Context<PopupMenu>,
270 context: &MenuContext,
271 target: &ChatMenuTarget,
272) -> PopupMenu {
273 let state = context.state.clone();
274 let chat_id = target.id.clone();
275 let mode = if target.muted {
276 ChatNotificationMode::Mute
277 } else {
278 ChatNotificationMode::AllNewMessages
279 };
280 let desktop = state.read(cx).chat_desktop_notifications(&chat_id);
281 popup.submenu_with_icon(
282 Some(menu_icon(IconName::Bell)),
283 "Manage notifications",
284 window,
285 cx,
286 move |submenu, _, _| {
287 let choose = |chosen_mode: ChatNotificationMode,
288 chosen_desktop: DesktopNotifications| {
289 let (state, chat_id) = (state.clone(), chat_id.clone());
290 move |_: &ClickEvent, _: &mut Window, cx: &mut App| {
291 state.update(cx, |state, cx| {
292 state.set_chat_notifications(&chat_id, chosen_mode, chosen_desktop, cx)
293 });
294 }
295 };
296 let submenu = submenu.label("Chat notification mode");
297 let submenu =
298 CHAT_NOTIFICATION_MODES
299 .iter()
300 .fold(submenu, |submenu, (label, value)| {
301 submenu.item(
302 PopupMenuItem::new(*label)
303 .checked(*value == mode)
304 .on_click(choose(*value, desktop)),
305 )
306 });
307 let submenu = submenu
308 .separator()
309 .label("Set a desktop notification preference");
310 DESKTOP_NOTIFICATIONS
311 .iter()
312 .fold(submenu, |submenu, (label, value)| {
313 submenu.item(
314 PopupMenuItem::new(*label)
315 .checked(*value == desktop)
316 .on_click(choose(mode, *value)),
317 )
318 })
319 },
320 )
321}
322
253#[derive(Clone)]
323#[derive(Clone)]
254struct SectionMenuTarget {
324struct SectionMenuTarget {
255 id: String,
325 id: String,