diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js
index d06037d3fa..df6ddfc1c4 100644
--- a/tools/jslint/check-all.js
+++ b/tools/jslint/check-all.js
@@ -41,7 +41,7 @@ var globals =
+ ' home_unread_messages'
+ ' maybe_scroll_to_selected recenter_pointer_on_display suppress_scroll_pointer_update'
+ ' process_visible_unread_messages message_range message_in_table process_loaded_for_unread'
- + ' mark_all_as_read message_unread process_read_messages'
+ + ' mark_all_as_read message_unread process_read_messages unread_in_current_view'
;
diff --git a/zephyr/static/js/notifications.js b/zephyr/static/js/notifications.js
index 3e0134e327..d1a664ce78 100644
--- a/zephyr/static/js/notifications.js
+++ b/zephyr/static/js/notifications.js
@@ -4,7 +4,6 @@ var exports = {};
var notice_memory = {};
var window_has_focus = true;
-var new_message_count = 0;
var asked_permission_already = false;
var names;
@@ -16,18 +15,49 @@ function browser_desktop_notifications_on () {
window.webkitNotifications.checkPermission() === 0);
}
-function update_title_count(new_count) {
- // Update window title and favicon to reflect new_message_count.
- //
- // If new_count is given, set new_message_count to that first.
- var n;
+exports.initialize = function () {
+ names = fullname.toLowerCase().split(" ");
+ names.push(email.split("@")[0].toLowerCase());
+ names.push("all");
+ names.push("everyone");
+ names.push("" + fullname.toLowerCase() + "");
- if (new_count !== undefined) {
- if (new_message_count === new_count)
- return;
- new_message_count = new_count;
+ $(window).focus(function () {
+ window_has_focus = true;
+ exports.update_title_count();
+
+ $.each(notice_memory, function (index, notice_mem_entry) {
+ notice_mem_entry.obj.cancel();
+ });
+
+
+ process_visible_unread_messages();
+ }).blur(function () {
+ window_has_focus = false;
+ }).mouseover(function () {
+ exports.update_title_count();
+ });
+
+ if (!window.webkitNotifications) {
+ return;
}
+ $(document).click(function () {
+ if (!desktop_notifications_enabled || asked_permission_already) {
+ return;
+ }
+ if (window.webkitNotifications.checkPermission() !== 0) { // 0 is PERMISSION_ALLOWED
+ window.webkitNotifications.requestPermission(function () {});
+ asked_permission_already = true;
+ }
+ });
+};
+
+exports.update_title_count = function () {
+ // Update window title and favicon to reflect unread messages in current view
+ var n;
+
+ var new_message_count = unread_in_current_view();
document.title = (new_message_count ? ("(" + new_message_count + ") ") : "")
+ domain + " - Humbug";
@@ -47,44 +77,6 @@ function update_title_count(new_count) {
util.set_favicon('/static/favicon.ico?v=2');
}
}
-}
-
-exports.initialize = function () {
- names = fullname.toLowerCase().split(" ");
- names.push(email.split("@")[0].toLowerCase());
- names.push("all");
- names.push("everyone");
- names.push("" + fullname.toLowerCase() + "");
-
- $(window).focus(function () {
- window_has_focus = true;
- update_title_count(0);
-
- $.each(notice_memory, function (index, notice_mem_entry) {
- notice_mem_entry.obj.cancel();
- });
-
-
- process_visible_unread_messages();
- }).blur(function () {
- window_has_focus = false;
- }).mouseover(function () {
- update_title_count(0);
- });
-
- if (!window.webkitNotifications) {
- return;
- }
-
- $(document).click(function () {
- if (!desktop_notifications_enabled || asked_permission_already) {
- return;
- }
- if (window.webkitNotifications.checkPermission() !== 0) { // 0 is PERMISSION_ALLOWED
- window.webkitNotifications.requestPermission(function () {});
- asked_permission_already = true;
- }
- });
};
exports.window_has_focus = function () {
@@ -208,7 +200,6 @@ exports.received_messages = function (messages) {
$.each(messages, function (index, message) {
if (message.sender_email !== email && narrow.message_in_home(message)) {
- new_message_count++;
title_needs_update = true;
if (desktop_notifications_enabled &&
@@ -221,7 +212,7 @@ exports.received_messages = function (messages) {
});
if (title_needs_update) {
- update_title_count();
+ exports.update_title_count();
}
};
diff --git a/zephyr/static/js/notifications_bar.js b/zephyr/static/js/notifications_bar.js
index 332c987e32..fce73b116f 100644
--- a/zephyr/static/js/notifications_bar.js
+++ b/zephyr/static/js/notifications_bar.js
@@ -50,21 +50,11 @@ function hide() {
// If there's a custom message, or if the last message is off the bottom of the
// screen, then show the notifications bar.
exports.update = function () {
- var unread_messages_below = 0;
- if (!narrow.active()) {
- unread_messages_below = home_unread_messages;
- } else {
- $.each(current_msg_list.all(), function (idx, msg) {
- if (message_unread(msg) && msg.id > current_msg_list.selected_id()) {
- unread_messages_below += 1;
- }
- });
- }
if (on_custom)
show(custom_message);
else if (rows.last_visible().offset() !== null // otherwise the next line will error
&& rows.last_visible().offset().top + rows.last_visible().height() > viewport.scrollTop() + viewport.height()
- && unread_messages_below > 0)
+ && unread_in_current_view() > 0)
show("More messages below");
else
hide();
diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js
index ebd8085488..8575f187ff 100644
--- a/zephyr/static/js/ui.js
+++ b/zephyr/static/js/ui.js
@@ -530,8 +530,10 @@ $(function () {
} else if (!have_scrolled_away_from_top) {
have_scrolled_away_from_top = true;
}
- // When the window scrolls, it may cause some messages to go off the screen
+ // When the window scrolls, it may cause some messages to
+ // enter the screen and become read
notifications_bar.update();
+ notifications.update_title_count();
var new_selected = current_msg_list.selected_id();
if (scroll_start_message === undefined) {
diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js
index e99714dd34..9f977ed328 100644
--- a/zephyr/static/js/zephyr.js
+++ b/zephyr/static/js/zephyr.js
@@ -192,6 +192,20 @@ function send_queued_flags() {
var unread_counts = {'stream': {}, 'private': {}};
var home_unread_messages = 0;
+function unread_in_current_view() {
+ var unread = 0;
+ if (!narrow.active()) {
+ unread = home_unread_messages;
+ } else {
+ $.each(current_msg_list.all(), function (idx, msg) {
+ if (message_unread(msg) && msg.id > current_msg_list.selected_id()) {
+ unread += 1;
+ }
+ });
+ }
+ return unread;
+}
+
function message_unread(message) {
if (message === undefined) {
return false;