diff --git a/static/js/settings_config.ts b/static/js/settings_config.ts index b1f6ace5a7..581ac45a8d 100644 --- a/static/js/settings_config.ts +++ b/static/js/settings_config.ts @@ -584,6 +584,17 @@ export const stream_notification_settings: (keyof StreamNotificationSettings)[] "wildcard_mentions_notify", ]; +export const generalize_stream_notification_setting: Record< + keyof StreamSpecificNotificationSettings, + keyof StreamNotificationSettings +> = { + desktop_notifications: "enable_stream_desktop_notifications", + audible_notifications: "enable_stream_audible_notifications", + push_notifications: "enable_stream_push_notifications", + email_notifications: "enable_stream_email_notifications", + wildcard_mentions_notify: "wildcard_mentions_notify", +}; + export const pm_mention_notification_settings: (keyof PmNotificationSettings)[] = [ "enable_desktop_notifications", "enable_sounds", diff --git a/static/js/stream_data.js b/static/js/stream_data.js index c4d9bd84d6..16ea4c07c2 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -468,10 +468,7 @@ export function receives_notifications(stream_id, notification_name) { if (sub[notification_name] !== null) { return sub[notification_name]; } - if (notification_name === "wildcard_mentions_notify") { - return user_settings[notification_name]; - } - return user_settings["enable_stream_" + notification_name]; + return user_settings[settings_config.generalize_stream_notification_setting[notification_name]]; } export function all_subscribed_streams_are_in_home_view() { diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 11fdbe24c4..67ab896038 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -330,11 +330,8 @@ export function stream_setting_changed(e, from_notification_settings) { return; } if (is_notification_setting(setting) && sub[setting] === null) { - if (setting === "wildcard_mentions_notify") { - sub[setting] = user_settings[setting]; - } else { - sub[setting] = user_settings["enable_stream_" + setting]; - } + sub[setting] = + user_settings[settings_config.generalize_stream_notification_setting[setting]]; } set_stream_property(sub, setting, e.target.checked, status_element); } diff --git a/static/js/stream_settings_data.js b/static/js/stream_settings_data.js index 247386a7a2..e664629ade 100644 --- a/static/js/stream_settings_data.js +++ b/static/js/stream_settings_data.js @@ -60,9 +60,10 @@ export function get_unmatched_streams_for_notification_settings() { const settings_values = {}; let make_table_row = false; for (const notification_name of settings_config.stream_specific_notification_settings) { - const prepend = - notification_name === "wildcard_mentions_notify" ? "" : "enable_stream_"; - const default_setting = user_settings[prepend + notification_name]; + const default_setting = + user_settings[ + settings_config.generalize_stream_notification_setting[notification_name] + ]; const stream_setting = stream_data.receives_notifications( row.stream_id, notification_name,