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)
This commit is contained in:
Tim Abbott
2013-05-08 15:15:40 -04:00
parent d483500e64
commit b1f75e8d3f

View File

@@ -222,12 +222,6 @@ function message_is_notifiable(message) {
subs.receives_notifications(message.stream))); 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) { exports.received_messages = function (messages) {
var i, title_needs_update = false; var i, title_needs_update = false;
if (window_has_focus) { if (window_has_focus) {
@@ -235,13 +229,18 @@ exports.received_messages = function (messages) {
} }
$.each(messages, function (index, message) { $.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; 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); 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(); $("#notifications-area").find("audio")[0].play();
} }
} }