BlueGit

ict rusty-teams

feat(settings): Teams chat and notification rows in settings

- Chats: message density, Enter key, mark-down, read receipts
- General: Up arrow key behaviour
- Notifications: preset, chat alerts, message preview, meeting chats

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
5df63e190d843ee21f413358c82cb556ae1157de
Parent
8a1b4521
6 files changed +328 −49
crates/app/src/settings/account.rs added +144 −0
@@ -0,0 +1,144 @@
1 use gpui_kit::*;
2 use teams_core::{
3 ActivityAlert, ChatSettingChange, EnterKeyBehavior, MeetingChatNotifications, MessageDensity,
4 NotificationPreset, UpArrowBehavior,
5 };
6
7 use super::rows::{Choice, control_row, select};
8 use crate::app_state::AppState;
9
10 pub struct Labeled<T: 'static> {
11 pub label: &'static str,
12 pub value: T,
13 }
14
15 const fn option<T>(label: &'static str, value: T) -> Labeled<T> {
16 Labeled { label, value }
17 }
18
19 pub const DENSITY: [Labeled<MessageDensity>; 2] = [
20 option("Comfy", MessageDensity::Comfy),
21 option("Compact", MessageDensity::Compact),
22 ];
23
24 pub const ENTER_KEY: [Labeled<EnterKeyBehavior>; 2] = [
25 option("Send the message", EnterKeyBehavior::Send),
26 option(
27 "Start a new line (to send, select Send or use Ctrl+Enter).",
28 EnterKeyBehavior::NewLine,
29 ),
30 ];
31
32 pub const UP_ARROW: [Labeled<UpArrowBehavior>; 3] = [
33 option(
34 "Move focus to message list",
35 UpArrowBehavior::NavigateToMessages,
36 ),
37 option("Edit last message", UpArrowBehavior::EditLastMessage),
38 option("Stay in compose box", UpArrowBehavior::StayInCompose),
39 ];
40
41 pub const PRESETS: [Labeled<NotificationPreset>; 3] = [
42 option("All activity", NotificationPreset::AllActivity),
43 option("Mentions & replies", NotificationPreset::MentionsAndReplies),
44 option("Customised", NotificationPreset::Customised),
45 ];
46
47 pub const CHAT_MESSAGES: [Labeled<ActivityAlert>; 2] = [
48 option("Show in banner", ActivityAlert::OnlyBanner),
49 option("Off", ActivityAlert::Off),
50 ];
51
52 pub const MENTIONS: [Labeled<ActivityAlert>; 2] = [
53 option("Show in Activity and banner", ActivityAlert::BannerAndFeed),
54 option("Show in Activity", ActivityAlert::OnlyFeed),
55 ];
56
57 pub const ACTIVITY_OR_OFF: [Labeled<ActivityAlert>; 3] = [
58 option("Show in Activity and banner", ActivityAlert::BannerAndFeed),
59 option("Show in Activity", ActivityAlert::OnlyFeed),
60 option("Off", ActivityAlert::Off),
61 ];
62
63 pub const MEETING_CHATS: [Labeled<MeetingChatNotifications>; 3] = [
64 option("Mute", MeetingChatNotifications::Mute),
65 option("Unmute", MeetingChatNotifications::Unmute),
66 option(
67 "Mute until I join or send a message",
68 MeetingChatNotifications::MuteUntilJoin,
69 ),
70 ];
71
72 pub fn preset_detail(preset: NotificationPreset) -> &'static str {
73 match preset {
74 NotificationPreset::AllActivity => "New messages, reactions, and all mentions",
75 NotificationPreset::MentionsAndReplies => "Personal mentions and replies to your messages",
76 NotificationPreset::Customised => "Your customised settings are active.",
77 }
78 }
79
80 pub fn meeting_chats_detail(setting: MeetingChatNotifications) -> &'static str {
81 match setting {
82 MeetingChatNotifications::Mute => "Don't send notifications for any meetings.",
83 MeetingChatNotifications::Unmute => "Send notifications for all meetings.",
84 MeetingChatNotifications::MuteUntilJoin => {
85 "Only send notifications if I've joined a meeting or sent a message."
86 }
87 }
88 }
89
90 pub fn label_of<T: PartialEq + Copy>(options: &[Labeled<T>], current: T) -> &'static str {
91 options
92 .iter()
93 .find(|option| option.value == current)
94 .map(|option| option.label)
95 .unwrap_or_default()
96 }
97
98 pub fn account_select<T: PartialEq + Copy + 'static>(
99 app: &Entity<AppState>,
100 (id, title, detail): (&'static str, &'static str, &'static str),
101 options: &'static [Labeled<T>],
102 current: T,
103 change: fn(T) -> ChatSettingChange,
104 ) -> Div {
105 let choices = options
106 .iter()
107 .map(|option| {
108 let (app, value) = (app.clone(), option.value);
109 Choice::new(option.label, value == current, move |cx| {
110 app.update(cx, |state, cx| state.save_chat_setting(change(value), cx))
111 })
112 })
113 .collect();
114 control_row(
115 title,
116 detail,
117 select(id, label_of(options, current), false, choices),
118 )
119 }
120
121 #[cfg(test)]
122 mod tests {
123 use teams_core::{ActivityAlert, MeetingChatNotifications, MessageDensity, UpArrowBehavior};
124
125 use super::{CHAT_MESSAGES, DENSITY, MEETING_CHATS, MENTIONS, UP_ARROW, label_of};
126
127 #[test]
128 fn every_value_has_a_teams_label() {
129 assert_eq!(label_of(&DENSITY, MessageDensity::Compact), "Compact");
130 assert_eq!(
131 label_of(&UP_ARROW, UpArrowBehavior::default()),
132 "Edit last message"
133 );
134 assert_eq!(
135 label_of(&MEETING_CHATS, MeetingChatNotifications::default()),
136 "Mute until I join or send a message"
137 );
138 assert_eq!(
139 label_of(&CHAT_MESSAGES, ActivityAlert::OnlyBanner),
140 "Show in banner"
141 );
142 assert_eq!(label_of(&MENTIONS, ActivityAlert::Off), "");
143 }
144 }
@@ -0,0 +1,144 @@
1use gpui_kit::*;
2use teams_core::{
3 ActivityAlert, ChatSettingChange, EnterKeyBehavior, MeetingChatNotifications, MessageDensity,
4 NotificationPreset, UpArrowBehavior,
5};
6
7use super::rows::{Choice, control_row, select};
8use crate::app_state::AppState;
9
10pub struct Labeled<T: 'static> {
11 pub label: &'static str,
12 pub value: T,
13}
14
15const fn option<T>(label: &'static str, value: T) -> Labeled<T> {
16 Labeled { label, value }
17}
18
19pub const DENSITY: [Labeled<MessageDensity>; 2] = [
20 option("Comfy", MessageDensity::Comfy),
21 option("Compact", MessageDensity::Compact),
22];
23
24pub const ENTER_KEY: [Labeled<EnterKeyBehavior>; 2] = [
25 option("Send the message", EnterKeyBehavior::Send),
26 option(
27 "Start a new line (to send, select Send or use Ctrl+Enter).",
28 EnterKeyBehavior::NewLine,
29 ),
30];
31
32pub const UP_ARROW: [Labeled<UpArrowBehavior>; 3] = [
33 option(
34 "Move focus to message list",
35 UpArrowBehavior::NavigateToMessages,
36 ),
37 option("Edit last message", UpArrowBehavior::EditLastMessage),
38 option("Stay in compose box", UpArrowBehavior::StayInCompose),
39];
40
41pub const PRESETS: [Labeled<NotificationPreset>; 3] = [
42 option("All activity", NotificationPreset::AllActivity),
43 option("Mentions & replies", NotificationPreset::MentionsAndReplies),
44 option("Customised", NotificationPreset::Customised),
45];
46
47pub const CHAT_MESSAGES: [Labeled<ActivityAlert>; 2] = [
48 option("Show in banner", ActivityAlert::OnlyBanner),
49 option("Off", ActivityAlert::Off),
50];
51
52pub const MENTIONS: [Labeled<ActivityAlert>; 2] = [
53 option("Show in Activity and banner", ActivityAlert::BannerAndFeed),
54 option("Show in Activity", ActivityAlert::OnlyFeed),
55];
56
57pub const ACTIVITY_OR_OFF: [Labeled<ActivityAlert>; 3] = [
58 option("Show in Activity and banner", ActivityAlert::BannerAndFeed),
59 option("Show in Activity", ActivityAlert::OnlyFeed),
60 option("Off", ActivityAlert::Off),
61];
62
63pub const MEETING_CHATS: [Labeled<MeetingChatNotifications>; 3] = [
64 option("Mute", MeetingChatNotifications::Mute),
65 option("Unmute", MeetingChatNotifications::Unmute),
66 option(
67 "Mute until I join or send a message",
68 MeetingChatNotifications::MuteUntilJoin,
69 ),
70];
71
72pub fn preset_detail(preset: NotificationPreset) -> &'static str {
73 match preset {
74 NotificationPreset::AllActivity => "New messages, reactions, and all mentions",
75 NotificationPreset::MentionsAndReplies => "Personal mentions and replies to your messages",
76 NotificationPreset::Customised => "Your customised settings are active.",
77 }
78}
79
80pub fn meeting_chats_detail(setting: MeetingChatNotifications) -> &'static str {
81 match setting {
82 MeetingChatNotifications::Mute => "Don't send notifications for any meetings.",
83 MeetingChatNotifications::Unmute => "Send notifications for all meetings.",
84 MeetingChatNotifications::MuteUntilJoin => {
85 "Only send notifications if I've joined a meeting or sent a message."
86 }
87 }
88}
89
90pub fn label_of<T: PartialEq + Copy>(options: &[Labeled<T>], current: T) -> &'static str {
91 options
92 .iter()
93 .find(|option| option.value == current)
94 .map(|option| option.label)
95 .unwrap_or_default()
96}
97
98pub fn account_select<T: PartialEq + Copy + 'static>(
99 app: &Entity<AppState>,
100 (id, title, detail): (&'static str, &'static str, &'static str),
101 options: &'static [Labeled<T>],
102 current: T,
103 change: fn(T) -> ChatSettingChange,
104) -> Div {
105 let choices = options
106 .iter()
107 .map(|option| {
108 let (app, value) = (app.clone(), option.value);
109 Choice::new(option.label, value == current, move |cx| {
110 app.update(cx, |state, cx| state.save_chat_setting(change(value), cx))
111 })
112 })
113 .collect();
114 control_row(
115 title,
116 detail,
117 select(id, label_of(options, current), false, choices),
118 )
119}
120
121#[cfg(test)]
122mod tests {
123 use teams_core::{ActivityAlert, MeetingChatNotifications, MessageDensity, UpArrowBehavior};
124
125 use super::{CHAT_MESSAGES, DENSITY, MEETING_CHATS, MENTIONS, UP_ARROW, label_of};
126
127 #[test]
128 fn every_value_has_a_teams_label() {
129 assert_eq!(label_of(&DENSITY, MessageDensity::Compact), "Compact");
130 assert_eq!(
131 label_of(&UP_ARROW, UpArrowBehavior::default()),
132 "Edit last message"
133 );
134 assert_eq!(
135 label_of(&MEETING_CHATS, MeetingChatNotifications::default()),
136 "Mute until I join or send a message"
137 );
138 assert_eq!(
139 label_of(&CHAT_MESSAGES, ActivityAlert::OnlyBanner),
140 "Show in banner"
141 );
142 assert_eq!(label_of(&MENTIONS, ActivityAlert::Off), "");
143 }
144}
crates/app/src/settings/chats.rs +78 −20
@@ -1,30 +1,88 @@
1 1 use gpui_kit::component::v_flex;
2 2 use gpui_kit::*;
3 use teams_core::ChatSection;
3 use teams_core::{ChatSection, ChatSettingChange};
4 4
5 use super::account::{DENSITY, ENTER_KEY, account_select};
5 6 use super::rows::{caption, toggle_row};
6 7 use crate::app_state::AppState;
7 8 use crate::theme;
8 9
10 const MARKDOWN_DETAIL: &str = "Use mark-down language to define the structure and appearance of messages. Your formatting will take effect once you send your message. When this is on, the formatting options menu won't be visible.";
11 const RECEIPTS_DETAIL: &str = "Let people know when you've seen their messages and know when they've seen yours. Close and reopen any chat windows for the setting to take effect in those chats.";
12
9 13 pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 let enabled = app
11 .read(cx)
12 .directory
13 .section_settings
14 .enabled(ChatSection::Muted);
15 let toggle_app = app.clone();
16 v_flex().w_full().child(caption("CHAT LIST")).child(
17 toggle_row(
18 "settings-muted-section",
19 "Show muted items in their own section",
20 "Read from your Teams account",
21 theme::text_muted(),
22 enabled,
14 let state = app.read(cx);
15 let muted_section = state.directory.section_settings.enabled(ChatSection::Muted);
16 let settings = state.account_chat_settings();
17 let markdown_mode = state.markdown_mode;
18 let (section_app, markdown_app, receipts_app) = (app.clone(), app.clone(), app.clone());
19 v_flex()
20 .w_full()
21 .child(caption("CHAT LIST"))
22 .child(
23 toggle_row(
24 "settings-muted-section",
25 "Show muted items in their own section",
26 "Read from your Teams account",
27 theme::text_muted(),
28 muted_section,
29 )
30 .on_click(move |_, _, cx| {
31 section_app.update(cx, |state, cx| {
32 state.set_chat_section(ChatSection::Muted, !muted_section, cx)
33 })
34 }),
35 )
36 .child(caption("CHATS"))
37 .child(account_select(
38 app,
39 (
40 "settings-message-density",
41 "Message density",
42 "Compact your chats and see more messages",
43 ),
44 &DENSITY,
45 settings.message_density,
46 ChatSettingChange::MessageDensity,
47 ))
48 .child(account_select(
49 app,
50 (
51 "settings-enter-key",
52 "When writing a message, press Enter to",
53 "This setting doesn't apply when message formatting is active.",
54 ),
55 &ENTER_KEY,
56 settings.enter_key,
57 ChatSettingChange::EnterKey,
58 ))
59 .child(
60 toggle_row(
61 "settings-markdown",
62 "Format messages using mark-down",
63 MARKDOWN_DETAIL,
64 theme::text_muted(),
65 markdown_mode,
66 )
67 .on_click(move |_, _, cx| {
68 markdown_app.update(cx, |state, cx| state.set_markdown_mode(!markdown_mode, cx))
69 }),
70 )
71 .child(
72 toggle_row(
73 "settings-read-receipts",
74 "Read receipts",
75 RECEIPTS_DETAIL,
76 theme::text_muted(),
77 settings.read_receipts,
78 )
79 .on_click(move |_, _, cx| {
80 receipts_app.update(cx, |state, cx| {
81 state.save_chat_setting(
82 ChatSettingChange::ReadReceipts(!settings.read_receipts),
83 cx,
84 )
85 })
86 }),
23 87 )
24 .on_click(move |_, _, cx| {
25 toggle_app.update(cx, |state, cx| {
26 state.set_chat_section(ChatSection::Muted, !enabled, cx)
27 })
28 }),
29 )
30 88 }
@@ -1,30 +1,88 @@
1use gpui_kit::component::v_flex;
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
2use gpui_kit::*;
3use teams_core::ChatSection;
3use teams_core::{ChatSection, ChatSettingChange};
4
4
5use super::account::{DENSITY, ENTER_KEY, account_select};
5use super::rows::{caption, toggle_row};
6use super::rows::{caption, toggle_row};
6use crate::app_state::AppState;
7use crate::app_state::AppState;
7use crate::theme;
8use crate::theme;
8
9
10const MARKDOWN_DETAIL: &str = "Use mark-down language to define the structure and appearance of messages. Your formatting will take effect once you send your message. When this is on, the formatting options menu won't be visible.";
11const RECEIPTS_DETAIL: &str = "Let people know when you've seen their messages and know when they've seen yours. Close and reopen any chat windows for the setting to take effect in those chats.";
12
9pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
13pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 let enabled = app
14 let state = app.read(cx);
11 .read(cx)
15 let muted_section = state.directory.section_settings.enabled(ChatSection::Muted);
12 .directory
16 let settings = state.account_chat_settings();
13 .section_settings
17 let markdown_mode = state.markdown_mode;
14 .enabled(ChatSection::Muted);
18 let (section_app, markdown_app, receipts_app) = (app.clone(), app.clone(), app.clone());
15 let toggle_app = app.clone();
19 v_flex()
16 v_flex().w_full().child(caption("CHAT LIST")).child(
20 .w_full()
17 toggle_row(
21 .child(caption("CHAT LIST"))
18 "settings-muted-section",
22 .child(
19 "Show muted items in their own section",
23 toggle_row(
20 "Read from your Teams account",
24 "settings-muted-section",
21 theme::text_muted(),
25 "Show muted items in their own section",
22 enabled,
26 "Read from your Teams account",
27 theme::text_muted(),
28 muted_section,
29 )
30 .on_click(move |_, _, cx| {
31 section_app.update(cx, |state, cx| {
32 state.set_chat_section(ChatSection::Muted, !muted_section, cx)
33 })
34 }),
35 )
36 .child(caption("CHATS"))
37 .child(account_select(
38 app,
39 (
40 "settings-message-density",
41 "Message density",
42 "Compact your chats and see more messages",
43 ),
44 &DENSITY,
45 settings.message_density,
46 ChatSettingChange::MessageDensity,
47 ))
48 .child(account_select(
49 app,
50 (
51 "settings-enter-key",
52 "When writing a message, press Enter to",
53 "This setting doesn't apply when message formatting is active.",
54 ),
55 &ENTER_KEY,
56 settings.enter_key,
57 ChatSettingChange::EnterKey,
58 ))
59 .child(
60 toggle_row(
61 "settings-markdown",
62 "Format messages using mark-down",
63 MARKDOWN_DETAIL,
64 theme::text_muted(),
65 markdown_mode,
66 )
67 .on_click(move |_, _, cx| {
68 markdown_app.update(cx, |state, cx| state.set_markdown_mode(!markdown_mode, cx))
69 }),
70 )
71 .child(
72 toggle_row(
73 "settings-read-receipts",
74 "Read receipts",
75 RECEIPTS_DETAIL,
76 theme::text_muted(),
77 settings.read_receipts,
78 )
79 .on_click(move |_, _, cx| {
80 receipts_app.update(cx, |state, cx| {
81 state.save_chat_setting(
82 ChatSettingChange::ReadReceipts(!settings.read_receipts),
83 cx,
84 )
85 })
86 }),
23 )
87 )
24 .on_click(move |_, _, cx| {
25 toggle_app.update(cx, |state, cx| {
26 state.set_chat_section(ChatSection::Muted, !enabled, cx)
27 })
28 }),
29 )
30}
88}
crates/app/src/settings/dialog.rs +1 −1
@@ -135,7 +135,7 @@ impl SettingsDialog {
135 135 general::render(&self.center, &self.app, cx).into_any_element()
136 136 }
137 137 SettingsSection::Notifications => {
138 notifications::render(&self.center, cx).into_any_element()
138 notifications::render(&self.center, &self.app, cx).into_any_element()
139 139 }
140 140 SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),
141 141 SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
@@ -135,7 +135,7 @@ impl SettingsDialog {
135 general::render(&self.center, &self.app, cx).into_any_element()
135 general::render(&self.center, &self.app, cx).into_any_element()
136 }
136 }
137 SettingsSection::Notifications => {
137 SettingsSection::Notifications => {
138 notifications::render(&self.center, cx).into_any_element()
138 notifications::render(&self.center, &self.app, cx).into_any_element()
139 }
139 }
140 SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),
140 SettingsSection::Appearance => appearance::render(&self.app, cx).into_any_element(),
141 SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
141 SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
crates/app/src/settings/general.rs +14 −1
@@ -6,8 +6,9 @@ use gpui_kit::component::{
6 6 v_flex,
7 7 };
8 8 use gpui_kit::*;
9 use teams_core::TranslationBehavior;
9 use teams_core::{ChatSettingChange, TranslationBehavior};
10 10
11 use super::account::{UP_ARROW, account_select};
11 12 use super::rows::{Choice, caption, control_row, select, toggle_row};
12 13 use crate::app_state::AppState;
13 14 use crate::notify::NotificationCenter;
@@ -44,6 +45,18 @@ pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &
44 45 })
45 46 }),
46 47 )
48 .child(caption("COMPOSE BOX"))
49 .child(account_select(
50 app,
51 (
52 "settings-up-arrow",
53 "Up arrow key behaviour in compose box",
54 "Choose what happens when you press Up arrow at the beginning of the compose box.",
55 ),
56 &UP_ARROW,
57 app.read(cx).account_chat_settings().up_arrow,
58 ChatSettingChange::UpArrow,
59 ))
47 60 .child(caption("TRANSLATION"))
48 61 .children(translation_rows(app, cx))
49 62 }
@@ -6,8 +6,9 @@ use gpui_kit::component::{
6 v_flex,
6 v_flex,
7};
7};
8use gpui_kit::*;
8use gpui_kit::*;
9use teams_core::TranslationBehavior;
9use teams_core::{ChatSettingChange, TranslationBehavior};
10
10
11use super::account::{UP_ARROW, account_select};
11use super::rows::{Choice, caption, control_row, select, toggle_row};
12use super::rows::{Choice, caption, control_row, select, toggle_row};
12use crate::app_state::AppState;
13use crate::app_state::AppState;
13use crate::notify::NotificationCenter;
14use crate::notify::NotificationCenter;
@@ -44,6 +45,18 @@ pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &
44 })
45 })
45 }),
46 }),
46 )
47 )
48 .child(caption("COMPOSE BOX"))
49 .child(account_select(
50 app,
51 (
52 "settings-up-arrow",
53 "Up arrow key behaviour in compose box",
54 "Choose what happens when you press Up arrow at the beginning of the compose box.",
55 ),
56 &UP_ARROW,
57 app.read(cx).account_chat_settings().up_arrow,
58 ChatSettingChange::UpArrow,
59 ))
47 .child(caption("TRANSLATION"))
60 .child(caption("TRANSLATION"))
48 .children(translation_rows(app, cx))
61 .children(translation_rows(app, cx))
49}
62}
crates/app/src/settings/mod.rs +1 −0
@@ -1,4 +1,5 @@
1 1 mod about;
2 mod account;
2 3 mod appearance;
3 4 mod calls;
4 5 mod chats;
@@ -1,4 +1,5 @@
1mod about;
1mod about;
2mod account;
2mod appearance;
3mod appearance;
3mod calls;
4mod calls;
4mod chats;
5mod chats;
crates/app/src/settings/notifications.rs +90 −27
@@ -1,7 +1,14 @@
1 1 use gpui_kit::component::{h_flex, v_flex};
2 2 use gpui_kit::*;
3 3
4 use teams_core::ChatSettingChange;
5
6 use super::account::{
7 ACTIVITY_OR_OFF, CHAT_MESSAGES, MEETING_CHATS, MENTIONS, PRESETS, account_select,
8 meeting_chats_detail, preset_detail,
9 };
4 10 use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
11 use crate::app_state::AppState;
5 12 use crate::notify::NotificationCenter;
6 13 use crate::notify::rules::{Corner, Settings};
7 14 use crate::notify::sounds::AlertSound;
@@ -17,20 +24,12 @@ struct Toggle {
17 24 field: Accessor,
18 25 }
19 26
20 const APPEARANCE: [Toggle; 2] = [
21 Toggle {
22 id: "settings-preview",
23 title: "Show message preview",
24 detail: "Off: only \"New message\"",
25 field: |settings| &mut settings.preview,
26 },
27 Toggle {
28 id: "settings-flash",
29 title: "Flash taskbar when notifications are received",
30 detail: "On new messages, until you open the window",
31 field: |settings| &mut settings.flash,
32 },
33 ];
27 const FLASH: Toggle = Toggle {
28 id: "settings-flash",
29 title: "Flash taskbar when notifications are received",
30 detail: "On new messages, until you open the window",
31 field: |settings| &mut settings.flash,
32 };
34 33
35 34 const NOTIFICATION_SOUND: Toggle = Toggle {
36 35 id: "settings-notification-sound",
@@ -61,13 +60,6 @@ const CALL_SOUNDS: [Toggle; 2] = [
61 60 },
62 61 ];
63 62
64 const MENTIONS_ONLY: Toggle = Toggle {
65 id: "settings-mentions-only",
66 title: "Mentions only",
67 detail: "Direct messages and @mentions",
68 field: |settings| &mut settings.mentions_only,
69 };
70
71 63 const HIDE_IN_CALLS: Toggle = Toggle {
72 64 id: "settings-hide-in-calls",
73 65 title: "Hide notifications during calls and meetings",
@@ -75,7 +67,8 @@ const HIDE_IN_CALLS: Toggle = Toggle {
75 67 field: |settings| &mut settings.mute_in_calls,
76 68 };
77 69
78 pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
70 pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
71 let account = app.read(cx).account_chat_settings().notifications;
79 72 let mut current = center.read(cx).settings().clone();
80 73 let corner = current.corner;
81 74 let sounds = current.sounds.clone();
@@ -83,17 +76,17 @@ pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
83 76 let on = *(toggle.field)(&mut current);
84 77 toggle_element(center, toggle, on)
85 78 };
86 let appearance: Vec<Stateful<Div>> = APPEARANCE.iter().map(&mut toggle).collect();
79 let flash = toggle(&FLASH);
87 80 let notification_sound = toggle(&NOTIFICATION_SOUND);
88 81 let urgent_sound = toggle(&URGENT_SOUND);
89 82 let call_sounds: Vec<Stateful<Div>> = CALL_SOUNDS.iter().map(&mut toggle).collect();
90 let mentions_only = toggle(&MENTIONS_ONLY);
91 83 let hide_in_calls = toggle(&HIDE_IN_CALLS);
92 84 let test_center = center.clone();
93 85 v_flex()
94 86 .w_full()
95 87 .child(caption("APPEARANCE AND SOUND"))
96 .children(appearance)
88 .child(preview_toggle(app, account.show_preview))
89 .child(flash)
97 90 .child(control_row(
98 91 "Position on the screen",
99 92 "Corner of the main screen",
@@ -141,12 +134,82 @@ pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
141 134 |settings| &mut settings.sounds.urgent_sound_type,
142 135 ))
143 136 .children(call_sounds)
144 .child(caption("WHAT YOU GET NOTIFIED FOR"))
145 .child(mentions_only)
137 .child(caption("TEAMS AND CHANNELS"))
138 .child(account_select(
139 app,
140 (
141 "settings-notification-preset",
142 "Teams and channels",
143 preset_detail(account.preset),
144 ),
145 &PRESETS,
146 account.preset,
147 ChatSettingChange::Preset,
148 ))
149 .child(caption("CHAT"))
150 .child(account_select(
151 app,
152 ("settings-chat-messages", "Chat message notifications", ""),
153 &CHAT_MESSAGES,
154 account.chat_messages,
155 ChatSettingChange::ChatMessages,
156 ))
157 .child(account_select(
158 app,
159 ("settings-personal-mentions", "Personal @mentions", ""),
160 &MENTIONS,
161 account.personal_mentions,
162 ChatSettingChange::PersonalMentions,
163 ))
164 .child(account_select(
165 app,
166 (
167 "settings-everyone-mentions",
168 "Everyone in chat @mentions",
169 "",
170 ),
171 &ACTIVITY_OR_OFF,
172 account.everyone_mentions,
173 ChatSettingChange::EveryoneMentions,
174 ))
175 .child(account_select(
176 app,
177 ("settings-likes", "Likes and reactions", ""),
178 &ACTIVITY_OR_OFF,
179 account.likes,
180 ChatSettingChange::Likes,
181 ))
146 182 .child(caption("MEETINGS AND CALLS"))
183 .child(account_select(
184 app,
185 (
186 "settings-meeting-chats",
187 "Meeting chat notifications",
188 meeting_chats_detail(account.meeting_chats),
189 ),
190 &MEETING_CHATS,
191 account.meeting_chats,
192 ChatSettingChange::MeetingChats,
193 ))
147 194 .child(hide_in_calls)
148 195 }
149 196
197 fn preview_toggle(app: &Entity<AppState>, on: bool) -> Stateful<Div> {
198 let app = app.clone();
199 toggle_row(
200 "settings-preview",
201 "Show message preview",
202 "Off: only \"New message\"",
203 theme::text_muted(),
204 on,
205 )
206 .on_click(move |_, _, cx| {
207 app.update(cx, |state, cx| {
208 state.save_chat_setting(ChatSettingChange::ShowPreview(!on), cx)
209 })
210 })
211 }
212
150 213 fn toggle_element(center: &Entity<NotificationCenter>, toggle: &Toggle, on: bool) -> Stateful<Div> {
151 214 let center = center.clone();
152 215 let field = toggle.field;
@@ -1,7 +1,14 @@
1use gpui_kit::component::{h_flex, v_flex};
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
2use gpui_kit::*;
3
3
4use teams_core::ChatSettingChange;
5
6use super::account::{
7 ACTIVITY_OR_OFF, CHAT_MESSAGES, MEETING_CHATS, MENTIONS, PRESETS, account_select,
8 meeting_chats_detail, preset_detail,
9};
4use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
10use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
11use crate::app_state::AppState;
5use crate::notify::NotificationCenter;
12use crate::notify::NotificationCenter;
6use crate::notify::rules::{Corner, Settings};
13use crate::notify::rules::{Corner, Settings};
7use crate::notify::sounds::AlertSound;
14use crate::notify::sounds::AlertSound;
@@ -17,20 +24,12 @@ struct Toggle {
17 field: Accessor,
24 field: Accessor,
18}
25}
19
26
20const APPEARANCE: [Toggle; 2] = [
27const FLASH: Toggle = Toggle {
21 Toggle {
28 id: "settings-flash",
22 id: "settings-preview",
29 title: "Flash taskbar when notifications are received",
23 title: "Show message preview",
30 detail: "On new messages, until you open the window",
24 detail: "Off: only \"New message\"",
31 field: |settings| &mut settings.flash,
25 field: |settings| &mut settings.preview,
32};
26 },
27 Toggle {
28 id: "settings-flash",
29 title: "Flash taskbar when notifications are received",
30 detail: "On new messages, until you open the window",
31 field: |settings| &mut settings.flash,
32 },
33];
34
33
35const NOTIFICATION_SOUND: Toggle = Toggle {
34const NOTIFICATION_SOUND: Toggle = Toggle {
36 id: "settings-notification-sound",
35 id: "settings-notification-sound",
@@ -61,13 +60,6 @@ const CALL_SOUNDS: [Toggle; 2] = [
61 },
60 },
62];
61];
63
62
64const MENTIONS_ONLY: Toggle = Toggle {
65 id: "settings-mentions-only",
66 title: "Mentions only",
67 detail: "Direct messages and @mentions",
68 field: |settings| &mut settings.mentions_only,
69};
70
71const HIDE_IN_CALLS: Toggle = Toggle {
63const HIDE_IN_CALLS: Toggle = Toggle {
72 id: "settings-hide-in-calls",
64 id: "settings-hide-in-calls",
73 title: "Hide notifications during calls and meetings",
65 title: "Hide notifications during calls and meetings",
@@ -75,7 +67,8 @@ const HIDE_IN_CALLS: Toggle = Toggle {
75 field: |settings| &mut settings.mute_in_calls,
67 field: |settings| &mut settings.mute_in_calls,
76};
68};
77
69
78pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
70pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
71 let account = app.read(cx).account_chat_settings().notifications;
79 let mut current = center.read(cx).settings().clone();
72 let mut current = center.read(cx).settings().clone();
80 let corner = current.corner;
73 let corner = current.corner;
81 let sounds = current.sounds.clone();
74 let sounds = current.sounds.clone();
@@ -83,17 +76,17 @@ pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
83 let on = *(toggle.field)(&mut current);
76 let on = *(toggle.field)(&mut current);
84 toggle_element(center, toggle, on)
77 toggle_element(center, toggle, on)
85 };
78 };
86 let appearance: Vec<Stateful<Div>> = APPEARANCE.iter().map(&mut toggle).collect();
79 let flash = toggle(&FLASH);
87 let notification_sound = toggle(&NOTIFICATION_SOUND);
80 let notification_sound = toggle(&NOTIFICATION_SOUND);
88 let urgent_sound = toggle(&URGENT_SOUND);
81 let urgent_sound = toggle(&URGENT_SOUND);
89 let call_sounds: Vec<Stateful<Div>> = CALL_SOUNDS.iter().map(&mut toggle).collect();
82 let call_sounds: Vec<Stateful<Div>> = CALL_SOUNDS.iter().map(&mut toggle).collect();
90 let mentions_only = toggle(&MENTIONS_ONLY);
91 let hide_in_calls = toggle(&HIDE_IN_CALLS);
83 let hide_in_calls = toggle(&HIDE_IN_CALLS);
92 let test_center = center.clone();
84 let test_center = center.clone();
93 v_flex()
85 v_flex()
94 .w_full()
86 .w_full()
95 .child(caption("APPEARANCE AND SOUND"))
87 .child(caption("APPEARANCE AND SOUND"))
96 .children(appearance)
88 .child(preview_toggle(app, account.show_preview))
89 .child(flash)
97 .child(control_row(
90 .child(control_row(
98 "Position on the screen",
91 "Position on the screen",
99 "Corner of the main screen",
92 "Corner of the main screen",
@@ -141,12 +134,82 @@ pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
141 |settings| &mut settings.sounds.urgent_sound_type,
134 |settings| &mut settings.sounds.urgent_sound_type,
142 ))
135 ))
143 .children(call_sounds)
136 .children(call_sounds)
144 .child(caption("WHAT YOU GET NOTIFIED FOR"))
137 .child(caption("TEAMS AND CHANNELS"))
145 .child(mentions_only)
138 .child(account_select(
139 app,
140 (
141 "settings-notification-preset",
142 "Teams and channels",
143 preset_detail(account.preset),
144 ),
145 &PRESETS,
146 account.preset,
147 ChatSettingChange::Preset,
148 ))
149 .child(caption("CHAT"))
150 .child(account_select(
151 app,
152 ("settings-chat-messages", "Chat message notifications", ""),
153 &CHAT_MESSAGES,
154 account.chat_messages,
155 ChatSettingChange::ChatMessages,
156 ))
157 .child(account_select(
158 app,
159 ("settings-personal-mentions", "Personal @mentions", ""),
160 &MENTIONS,
161 account.personal_mentions,
162 ChatSettingChange::PersonalMentions,
163 ))
164 .child(account_select(
165 app,
166 (
167 "settings-everyone-mentions",
168 "Everyone in chat @mentions",
169 "",
170 ),
171 &ACTIVITY_OR_OFF,
172 account.everyone_mentions,
173 ChatSettingChange::EveryoneMentions,
174 ))
175 .child(account_select(
176 app,
177 ("settings-likes", "Likes and reactions", ""),
178 &ACTIVITY_OR_OFF,
179 account.likes,
180 ChatSettingChange::Likes,
181 ))
146 .child(caption("MEETINGS AND CALLS"))
182 .child(caption("MEETINGS AND CALLS"))
183 .child(account_select(
184 app,
185 (
186 "settings-meeting-chats",
187 "Meeting chat notifications",
188 meeting_chats_detail(account.meeting_chats),
189 ),
190 &MEETING_CHATS,
191 account.meeting_chats,
192 ChatSettingChange::MeetingChats,
193 ))
147 .child(hide_in_calls)
194 .child(hide_in_calls)
148}
195}
149
196
197fn preview_toggle(app: &Entity<AppState>, on: bool) -> Stateful<Div> {
198 let app = app.clone();
199 toggle_row(
200 "settings-preview",
201 "Show message preview",
202 "Off: only \"New message\"",
203 theme::text_muted(),
204 on,
205 )
206 .on_click(move |_, _, cx| {
207 app.update(cx, |state, cx| {
208 state.save_chat_setting(ChatSettingChange::ShowPreview(!on), cx)
209 })
210 })
211}
212
150fn toggle_element(center: &Entity<NotificationCenter>, toggle: &Toggle, on: bool) -> Stateful<Div> {
213fn toggle_element(center: &Entity<NotificationCenter>, toggle: &Toggle, on: bool) -> Stateful<Div> {
151 let center = center.clone();
214 let center = center.clone();
152 let field = toggle.field;
215 let field = toggle.field;