From b1f75e8d3f67a7fd25dab341feaa60b1b7359543 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 8 May 2013 15:15:40 -0400 Subject: [PATCH] Clean up notifications.received_messages. This is trying to make the logic flow clear -- e.g. we check once, at the beginning, for whether the message is notifiable, and the checks for whether the various notification settings are enabled are more parallel. (imported from commit a68c71a53055191bc16682a85f739ed8e40ddeae) --- zephyr/static/js/notifications.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/zephyr/static/js/notifications.js b/zephyr/static/js/notifications.js index 18435ebe08..e1ae52f002 100644 --- a/zephyr/static/js/notifications.js +++ b/zephyr/static/js/notifications.js @@ -222,12 +222,6 @@ function message_is_notifiable(message) { subs.receives_notifications(message.stream))); } -function should_show_notification(message) { - return page_params.desktop_notifications_enabled && - browser_desktop_notifications_on() && - message_is_notifiable(message); -} - exports.received_messages = function (messages) { var i, title_needs_update = false; if (window_has_focus) { @@ -235,13 +229,18 @@ exports.received_messages = function (messages) { } $.each(messages, function (index, message) { - if (message.sender_email !== page_params.email && narrow.message_in_home(message)) { + if (message.sender_email !== page_params.email && + narrow.message_in_home(message)) { title_needs_update = true; - if (should_show_notification(message)) { + if (!message_is_notifiable(message)) { + return; + } + if (page_params.desktop_notifications_enabled && + browser_desktop_notifications_on()) { process_desktop_notification(message); } - if (supports_sound && page_params.sounds_enabled && message_is_notifiable(message)) { + if (page_params.sounds_enabled && supports_sound) { $("#notifications-area").find("audio")[0].play(); } }