From a0ab87bef21ebef54f9eb95682e51ba74e0fec2b Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Thu, 8 Mar 2018 12:20:16 +0530 Subject: [PATCH] notifications: Clean and automate global notifications update handler. To prevent specifying notifications individually for global updates, automate handle_global_notification_updates using settings_notifications.notification_settings where we have the keys of all the types of notifications. --- static/js/notifications.js | 24 ++---------------------- static/js/settings_notifications.js | 4 ++-- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/static/js/notifications.js b/static/js/notifications.js index f5c4aecaa9..bbf921c9b4 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -658,28 +658,8 @@ 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 (notification_name === "enable_stream_desktop_notifications") { - page_params.enable_stream_desktop_notifications = setting; - } else if (notification_name === "enable_stream_push_notifications") { - page_params.enable_stream_push_notifications = setting; - } else if (notification_name === "enable_stream_sounds") { - page_params.enable_stream_sounds = setting; - } else if (notification_name === "enable_desktop_notifications") { - page_params.enable_desktop_notifications = setting; - } else if (notification_name === "enable_sounds") { - page_params.enable_sounds = setting; - } else if (notification_name === "enable_offline_email_notifications") { - page_params.enable_offline_email_notifications = setting; - } else if (notification_name === "enable_offline_push_notifications") { - page_params.enable_offline_push_notifications = setting; - } else if (notification_name === "enable_online_push_notifications") { - page_params.enable_online_push_notifications = setting; - } else if (notification_name === "enable_digest_emails") { - page_params.enable_digest_emails = setting; - } else if (notification_name === "pm_content_in_desktop_notifications") { - page_params.pm_content_in_desktop_notifications = setting; - } else if (notification_name === "realm_name_in_notifications") { - page_params.realm_name_in_notifications = setting; + if (settings_notifications.notification_settings.indexOf(notification_name) !== -1) { + page_params[notification_name] = setting; } }; diff --git a/static/js/settings_notifications.js b/static/js/settings_notifications.js index e8383ced32..c108c4a507 100644 --- a/static/js/settings_notifications.js +++ b/static/js/settings_notifications.js @@ -22,7 +22,7 @@ var other_notification_settings = [ "realm_name_in_notifications", ]; -var notification_settings = other_notification_settings.concat( +exports.notification_settings = other_notification_settings.concat( pm_mention_notification_settings, _.map(stream_notification_settings, function (item) { return item.setting; @@ -91,7 +91,7 @@ exports.set_up = function () { }; function _update_page() { - _.each(notification_settings, function (setting) { + _.each(exports.notification_settings, function (setting) { $("#" + setting).prop('checked', page_params[setting]); }); }