use gpui_kit::component::{h_flex, v_flex}; use gpui_kit::*; use teams_core::ChatSettingChange; use super::account::{ ACTIVITY_OR_OFF, CHAT_MESSAGES, MEETING_CHATS, MENTIONS, PRESETS, account_select, meeting_chats_detail, preset_detail, }; use super::rows::{Choice, caption, control_row, select, text_button, toggle_row}; use crate::app_state::AppState; use crate::i18n::tr; use crate::notify::NotificationCenter; use crate::notify::rules::{Corner, Settings}; use crate::notify::sounds::AlertSound; use crate::presence_follow::{ MANAGE_STATUS_NOTIFICATIONS, STATUS_NOTIFICATIONS_DESCRIPTION, TURN_OFF, }; use crate::theme; type Accessor = fn(&mut Settings) -> &mut bool; type SoundAccessor = fn(&mut Settings) -> &mut AlertSound; struct Toggle { id: &'static str, title_key: &'static str, detail_key: Option<&'static str>, field: Accessor, } const FLASH: Toggle = Toggle { id: "settings-flash", title_key: "settings.notifications.flash_taskbar", detail_key: Some("settings.notifications.flash_taskbar_detail"), field: |settings| &mut settings.flash, }; const NOTIFICATION_SOUND: Toggle = Toggle { id: "settings-notification-sound", title_key: "settings.notifications.play_sounds", detail_key: None, field: |settings| &mut settings.sounds.notification_sound, }; const URGENT_SOUND: Toggle = Toggle { id: "settings-urgent-sound", title_key: "settings.notifications.urgent_sounds", detail_key: None, field: |settings| &mut settings.sounds.urgent_sound, }; const CALL_SOUNDS: [Toggle; 2] = [ Toggle { id: "settings-call-sound", title_key: "settings.notifications.call_sounds", detail_key: None, field: |settings| &mut settings.sounds.call_and_meeting_sound, }, Toggle { id: "settings-busy-sound", title_key: "settings.notifications.busy_sounds", detail_key: None, field: |settings| &mut settings.sounds.sound_when_busy, }, ]; const HIDE_IN_CALLS: Toggle = Toggle { id: "settings-hide-in-calls", title_key: "settings.notifications.hide_in_calls", detail_key: Some("settings.notifications.hide_in_calls_detail"), field: |settings| &mut settings.mute_in_calls, }; pub fn render(center: &Entity, app: &Entity, cx: &App) -> Div { let account = app.read(cx).account_chat_settings().notifications; let mut current = center.read(cx).settings().clone(); let corner = current.corner; let sounds = current.sounds.clone(); let mut toggle = |toggle: &Toggle| { let on = *(toggle.field)(&mut current); toggle_element(center, toggle, on) }; let flash = toggle(&FLASH); let notification_sound = toggle(&NOTIFICATION_SOUND); let urgent_sound = toggle(&URGENT_SOUND); let call_sounds: Vec> = CALL_SOUNDS.iter().map(&mut toggle).collect(); let hide_in_calls = toggle(&HIDE_IN_CALLS); let test_center = center.clone(); v_flex() .w_full() .child(caption(tr("settings.caption.appearance_and_sound"))) .child(preview_toggle(app, account.show_preview)) .child(flash) .child(control_row( tr("settings.notifications.position"), tr("settings.notifications.position_detail"), select( "settings-position", corner.label(), false, corner_choices(center, corner), ), )) .child(control_row( tr("settings.notifications.test"), tr("settings.notifications.test_detail"), text_button( "settings-test-notification", tr("settings.notifications.send_test"), ) .on_click(move |_, _, cx| { test_center.update(cx, |center, cx| center.send_test_notification(cx)) }), )) .child(caption(tr("settings.caption.sound"))) .child(notification_sound) .child(sound_row( center, ( "settings-notification-sound-type", "settings-notification-sound-preview", ), tr("settings.notifications.notification_sound"), &AlertSound::NORMAL, sounds.notification_sound_type, sounds.notification_sound, |settings| &mut settings.sounds.notification_sound_type, )) .child(urgent_sound) .child(sound_row( center, ( "settings-urgent-sound-type", "settings-urgent-sound-preview", ), tr("settings.notifications.urgent_sound"), &AlertSound::URGENT, sounds.urgent_sound_type, sounds.urgent_sound, |settings| &mut settings.sounds.urgent_sound_type, )) .children(call_sounds) .child(caption("TEAMS AND CHANNELS")) .child(account_select( app, ( "settings-notification-preset", tr("settings.notifications.teams_channels"), preset_detail(account.preset), ), &PRESETS, account.preset, ChatSettingChange::Preset, )) .child(caption("CHAT")) .child(account_select( app, ( "settings-chat-messages", tr("settings.notifications.chat_messages"), "", ), &CHAT_MESSAGES, account.chat_messages, ChatSettingChange::ChatMessages, )) .child(account_select( app, ("settings-personal-mentions", "Personal @mentions", ""), &MENTIONS, account.personal_mentions, ChatSettingChange::PersonalMentions, )) .child(account_select( app, ( "settings-everyone-mentions", "Everyone in chat @mentions", "", ), &ACTIVITY_OR_OFF, account.everyone_mentions, ChatSettingChange::EveryoneMentions, )) .child(account_select( app, ( "settings-likes", tr("settings.notifications.likes_reactions"), "", ), &ACTIVITY_OR_OFF, account.likes, ChatSettingChange::Likes, )) .child(caption("MEETINGS AND CALLS")) .child(account_select( app, ( "settings-meeting-chats", tr("settings.notifications.meeting_chats"), meeting_chats_detail(account.meeting_chats), ), &MEETING_CHATS, account.meeting_chats, ChatSettingChange::MeetingChats, )) .child(hide_in_calls) .child(caption("PEOPLE")) .child(control_row( MANAGE_STATUS_NOTIFICATIONS, STATUS_NOTIFICATIONS_DESCRIPTION, div(), )) .children(followed_rows(app, cx)) } fn followed_rows(app: &Entity, cx: &App) -> Vec
{ app.read(cx) .followed_presence .iter() .enumerate() .map(|(index, person)| { let (app, user_id, name) = (app.clone(), person.user_id.clone(), person.name.clone()); control_row( person.name.clone(), "", text_button(("settings-unfollow-presence", index), TURN_OFF).on_click( move |_, _, cx| { app.update(cx, |state, cx| { state.set_presence_followed(&user_id, &name, false, cx) }) }, ), ) }) .collect() } fn preview_toggle(app: &Entity, on: bool) -> Stateful
{ let app = app.clone(); toggle_row( "settings-preview", tr("settings.notifications.show_preview"), "Off: only \"New message\"", theme::text_muted(), on, ) .on_click(move |_, _, cx| { app.update(cx, |state, cx| { state.save_chat_setting(ChatSettingChange::ShowPreview(!on), cx) }) }) } fn toggle_element(center: &Entity, toggle: &Toggle, on: bool) -> Stateful
{ let center = center.clone(); let field = toggle.field; let detail = toggle.detail_key.map(tr).unwrap_or_default(); toggle_row( toggle.id, tr(toggle.title_key), detail, theme::text_muted(), on, ) .on_click(move |_, _, cx| { center.update(cx, |center, cx| { center.update_settings(cx, |settings| { let value = field(settings); *value = !*value; }) }) }) } fn corner_choices(center: &Entity, current: Corner) -> Vec { Corner::ALL .into_iter() .map(|corner| { let center = center.clone(); Choice::new(corner.label(), corner == current, move |cx| { center.update(cx, |center, cx| { center.update_settings(cx, |settings| settings.corner = corner) }) }) }) .collect() } fn sound_row( center: &Entity, (id, preview_id): (&'static str, &'static str), title: impl Into, options: &'static [AlertSound], current: AlertSound, enabled: bool, field: SoundAccessor, ) -> Div { let choices = options .iter() .map(|sound| { let (center, sound) = (center.clone(), *sound); Choice::new(sound.label(), sound == current, move |cx| { center.update(cx, |center, cx| { center.update_settings(cx, |settings| *field(settings) = sound); center.preview_sound(sound.file_name(), cx); }) }) }) .collect(); let preview_center = center.clone(); control_row( title, "", h_flex() .gap(px(8.)) .items_center() .child(select(id, current.label(), !enabled, choices)) .child( text_button(preview_id, "Preview").on_click(move |_, _, cx| { preview_center.update(cx, |center, cx| { center.preview_sound(current.file_name(), cx) }) }), ), ) }