From 5c884753785c0229c0acee72f584238cfb79b133 Mon Sep 17 00:00:00 2001 From: Yashashvi Dave Date: Fri, 14 Jun 2019 22:38:36 +0530 Subject: [PATCH] static/js/stream_data: Deduplicate notification setting updates. Commit also add `stream_data.js` to full test covered enforced files for `test-js-with-node` tests. --- static/js/stream_data.js | 30 ++++++++++-------------------- tools/test-js-with-node | 4 +--- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/static/js/stream_data.js b/static/js/stream_data.js index b8e01c06ff..d5e8ac8656 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -300,6 +300,13 @@ exports.receives_notifications = function (stream_name, notification_name) { return page_params["enable_stream_" + notification_name]; }; +var stream_notification_settings = [ + "desktop_notifications", + "audible_notifications", + "push_notifications", + "email_notifications", +]; + 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 @@ -326,26 +333,9 @@ exports.update_calculated_fields = function (sub) { exports.update_subscribers_count(sub); // Apply the defaults for our notification settings for rendering. - if (sub.email_notifications === null) { - sub.email_notifications_display = page_params.enable_stream_email_notifications; - } else { - sub.email_notifications_display = sub.email_notifications; - } - if (sub.push_notifications === null) { - sub.push_notifications_display = page_params.enable_stream_push_notifications; - } else { - sub.push_notifications_display = sub.push_notifications; - } - if (sub.desktop_notifications === null) { - sub.desktop_notifications_display = page_params.enable_stream_desktop_notifications; - } else { - sub.desktop_notifications_display = sub.desktop_notifications; - } - if (sub.audible_notifications === null) { - sub.audible_notifications_display = page_params.enable_stream_audible_notifications; - } else { - sub.audible_notifications_display = sub.audible_notifications; - } + _.each(stream_notification_settings, function (setting) { + sub[setting + "_display"] = exports.receives_notifications(sub.name, setting); + }); }; exports.all_subscribed_streams_are_in_home_view = function () { diff --git a/tools/test-js-with-node b/tools/test-js-with-node index d331c1d4c8..07f213f69b 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -70,9 +70,7 @@ enforce_fully_covered = { # 'static/js/settings_ui.js', 'static/js/settings_muting.js', 'static/js/settings_user_groups.js', - # Removed because of an intermediate state of the subscription - # notifications migration. - # 'static/js/stream_data.js', + 'static/js/stream_data.js', 'static/js/stream_events.js', 'static/js/stream_sort.js', 'static/js/top_left_corner.js',