settings_config: Move Realm level notification settings.

We make `all_notifications` a function to avoid a
require-time dependency on page_params.
This commit is contained in:
Ryan Rehman 2020-03-28 22:33:43 +05:30 committed by Tim Abbott
parent 39577b58ba
commit 58d06f3911
5 changed files with 100 additions and 103 deletions

View File

@ -1,5 +1,6 @@
const render_compose_notification = require('../templates/compose_notification.hbs');
const render_notification = require('../templates/notification.hbs');
const settings_config = require("./settings_config");
const notice_memory = new Map();
@ -749,11 +750,11 @@ exports.handle_global_notification_updates = function (notification_name, settin
// Update the global settings checked when determining if we should notify
// for a given message. These settings do not affect whether or not a
// particular stream should receive notifications.
if (settings_notifications.all_notification_settings.includes(notification_name)) {
if (settings_config.all_notification_settings.includes(notification_name)) {
page_params[notification_name] = setting;
}
if (settings_notifications.stream_notification_settings.includes(notification_name)) {
if (settings_config.stream_notification_settings.includes(notification_name)) {
notification_name = notification_name.replace("enable_stream_", "");
stream_ui_updates.update_notification_setting_checkbox(notification_name);
}

View File

@ -98,11 +98,11 @@ exports.build_page = function () {
settings_label: exports.settings_label,
demote_inactive_streams_values: settings_config.demote_inactive_streams_values,
twenty_four_hour_time_values: settings_config.twenty_four_hour_time_values,
general_settings: settings_notifications.all_notifications.general_settings,
notification_settings: settings_notifications.all_notifications.settings,
general_settings: settings_config.all_notifications().general_settings,
notification_settings: settings_config.all_notifications().settings,
desktop_icon_count_display_values: settings_notifications.desktop_icon_count_display_values,
show_push_notifications_tooltip:
settings_notifications.all_notifications.show_push_notifications_tooltip,
settings_config.all_notifications().show_push_notifications_tooltip,
display_settings: settings_config.get_all_display_settings(),
user_can_change_name: settings_account.user_can_change_name(),
user_can_change_avatar: settings_account.user_can_change_avatar(),

View File

@ -155,3 +155,88 @@ const time_limit_dropdown_values = new Map([
]);
exports.msg_edit_limit_dropdown_values = time_limit_dropdown_values;
exports.msg_delete_limit_dropdown_values = time_limit_dropdown_values;
// NOTIFICATIONS
exports.general_notifications_table_columns = [
/* An array of notification settings of any category like
* `stream_notification_settings` which makes a single row of
* "Notification triggers" table should follow this order
*/
"visual", "audio", "mobile", "email", "all_mentions",
];
exports.stream_specific_notification_settings = [
"desktop_notifications",
"audible_notifications",
"push_notifications",
"email_notifications",
"wildcard_mentions_notify",
];
exports.stream_notification_settings = [
"enable_stream_desktop_notifications",
"enable_stream_audible_notifications",
"enable_stream_push_notifications",
"enable_stream_email_notifications",
"wildcard_mentions_notify",
];
const pm_mention_notification_settings = [
"enable_desktop_notifications",
"enable_sounds",
"enable_offline_push_notifications",
"enable_offline_email_notifications",
];
const desktop_notification_settings = [
"pm_content_in_desktop_notifications",
];
const mobile_notification_settings = [
"enable_online_push_notifications",
];
const email_notification_settings = [
"enable_digest_emails",
"enable_login_emails",
"message_content_in_email_notifications",
"realm_name_in_notifications",
];
const other_notification_settings = desktop_notification_settings.concat(
["desktop_icon_count_display"],
mobile_notification_settings,
email_notification_settings,
["notification_sound"]
);
exports.all_notification_settings = other_notification_settings.concat(
pm_mention_notification_settings,
exports.stream_notification_settings
);
exports.all_notifications = () => ({
general_settings: [
{
label: i18n.t("Streams"),
notification_settings: settings_notifications.get_notifications_table_row_data(
exports.stream_notification_settings),
},
{
label: i18n.t("PMs, mentions, and alerts"),
notification_settings: settings_notifications.get_notifications_table_row_data(
pm_mention_notification_settings),
},
],
settings: {
desktop_notification_settings: desktop_notification_settings,
mobile_notification_settings: mobile_notification_settings,
email_notification_settings: email_notification_settings,
},
show_push_notifications_tooltip: {
push_notifications: !page_params.realm_push_notifications_enabled,
enable_online_push_notifications: !page_params.realm_push_notifications_enabled,
},
});

View File

@ -1,66 +1,8 @@
const render_stream_specific_notification_row = require('../templates/settings/stream_specific_notification_row.hbs');
const settings_config = require("./settings_config");
const general_notifications_table_columns = [
/* An array of notification settings of any category like
* `stream_notification_settings` which makes a single row of
* "Notification triggers" table should follow this order
*/
"visual", "audio", "mobile", "email", "all_mentions",
];
exports.stream_notification_settings = [
"enable_stream_desktop_notifications",
"enable_stream_audible_notifications",
"enable_stream_push_notifications",
"enable_stream_email_notifications",
"wildcard_mentions_notify",
];
const stream_specific_notification_settings = [
"desktop_notifications",
"audible_notifications",
"push_notifications",
"email_notifications",
"wildcard_mentions_notify",
];
const pm_mention_notification_settings = [
"enable_desktop_notifications",
"enable_sounds",
"enable_offline_push_notifications",
"enable_offline_email_notifications",
];
const desktop_notification_settings = [
"pm_content_in_desktop_notifications",
];
const mobile_notification_settings = [
"enable_online_push_notifications",
];
const email_notification_settings = [
"enable_digest_emails",
"enable_login_emails",
"message_content_in_email_notifications",
"realm_name_in_notifications",
];
const other_notification_settings = desktop_notification_settings.concat(
["desktop_icon_count_display"],
mobile_notification_settings,
email_notification_settings,
["notification_sound"]
);
exports.all_notification_settings = other_notification_settings.concat(
pm_mention_notification_settings,
exports.stream_notification_settings
);
function get_notifications_table_row_data(notify_settings) {
return general_notifications_table_columns.map((column, index) => {
exports.get_notifications_table_row_data = function (notify_settings) {
return settings_config.general_notifications_table_columns.map((column, index) => {
const setting_name = notify_settings[index];
if (setting_name === undefined) {
return {
@ -79,30 +21,6 @@ function get_notifications_table_row_data(notify_settings) {
checkbox.is_checked = page_params[setting_name];
return checkbox;
});
}
exports.all_notifications = {
general_settings: [
{
label: i18n.t("Streams"),
notification_settings: get_notifications_table_row_data(
exports.stream_notification_settings),
},
{
label: i18n.t("PMs, mentions, and alerts"),
notification_settings: get_notifications_table_row_data(
pm_mention_notification_settings),
},
],
settings: {
desktop_notification_settings: desktop_notification_settings,
mobile_notification_settings: mobile_notification_settings,
email_notification_settings: email_notification_settings,
},
show_push_notifications_tooltip: {
push_notifications: !page_params.realm_push_notifications_enabled,
enable_online_push_notifications: !page_params.realm_push_notifications_enabled,
},
};
exports.desktop_icon_count_display_values = {
@ -134,8 +52,9 @@ function rerender_ui() {
modifier: function (unmatched_streams) {
return render_stream_specific_notification_row({
stream: unmatched_streams,
stream_specific_notification_settings: stream_specific_notification_settings,
is_disabled: exports.all_notifications.show_push_notifications_tooltip,
stream_specific_notification_settings:
settings_config.stream_specific_notification_settings,
is_disabled: settings_config.all_notifications().show_push_notifications_tooltip,
});
},
}).init();
@ -205,7 +124,7 @@ exports.set_up = function () {
};
exports.update_page = function () {
for (const setting of exports.all_notification_settings) {
for (const setting of settings_config.all_notification_settings) {
if (setting === 'enable_offline_push_notifications'
&& !page_params.realm_push_notifications_enabled) {
// If push notifications are disabled at the realm level,

View File

@ -441,14 +441,6 @@ exports.receives_notifications = function (stream_name, notification_name) {
return page_params["enable_stream_" + notification_name];
};
const stream_notification_settings = [
"desktop_notifications",
"audible_notifications",
"push_notifications",
"email_notifications",
"wildcard_mentions_notify",
];
exports.update_calculated_fields = function (sub) {
sub.is_admin = page_params.is_admin;
// Admin can change any stream's name & description either stream is public or
@ -475,7 +467,7 @@ exports.update_calculated_fields = function (sub) {
exports.update_subscribers_count(sub);
// Apply the defaults for our notification settings for rendering.
for (const setting of stream_notification_settings) {
for (const setting of settings_config.stream_specific_notification_settings) {
sub[setting + "_display"] = exports.receives_notifications(sub.name, setting);
}
};
@ -754,7 +746,7 @@ exports.get_unmatched_streams_for_notification_settings = function () {
for (const row of subscribed_rows) {
const settings_values = {};
let make_table_row = false;
for (const notification_name of stream_notification_settings) {
for (const notification_name of settings_config.stream_specific_notification_settings) {
const prepend = notification_name === 'wildcard_mentions_notify' ? "" : "enable_stream_";
const default_setting = page_params[prepend + notification_name];
const stream_setting = exports.receives_notifications(row.name, notification_name);