Fix unread count in favicon when focusing window.

This fixes a pretty subtle bug where the window-focus handler
wasn't updating the unread counts in the title, but it was
hard to notice, because as soon as you moved the mouse, the
problem fixed itself.

Apart from fixing the bug, this patch eliminates the expensive
mouseover handler, which is a big win.

The fix to the window-focus involved some unrelated cleanup.  I
decoupled update_title_count() from received_messages(), as the
former method will probably live somewhere else soon.

Also, in order to get window-focus to update the title count,
I went pretty deep in the stack and added a call to
update_title_count() inside of update_unread_counts().  This
fixes window-focus as well as restoring that behavior to
code paths that were calling received_messages().

You'll see that call to update_title_count() is now adjacent
to the call to update_dom_with_unread_counts(), which is
fairly sensible, but then are calls to similar methods like
notifications.received_messages() that happen higher up in
the call chain, which seems kind of inconsistent to me.  I
also don't like the fact that you have to go through a
mostly model-based function to get to view-based stuff, so
there are some refactorings coming.

(imported from commit 2261450f205f1aa81d30194b371a1c5ac6a7bdec)
This commit is contained in:
Steve Howell 2013-05-17 12:31:04 -04:00 committed by Leo Franchi
parent 1e76383f03
commit 69977ce825
2 changed files with 3 additions and 8 deletions

View File

@ -35,8 +35,6 @@ exports.initialize = function () {
process_visible_unread_messages();
}).blur(function () {
window_has_focus = false;
}).mouseover(function () {
exports.update_title_count();
});
if (!window.webkitNotifications) {
@ -223,12 +221,11 @@ function message_is_notifiable(message) {
}
exports.received_messages = function (messages) {
var i, title_needs_update = false;
var i;
$.each(messages, function (index, message) {
if (message.sender_email !== page_params.email &&
narrow.message_in_home(message)) {
title_needs_update = !window_has_focus;
// We send notifications for messages which the user has
// configured as notifiable, as long as they haven't been
@ -247,10 +244,6 @@ exports.received_messages = function (messages) {
}
}
});
if (title_needs_update) {
exports.update_title_count();
}
};
return exports;

View File

@ -335,6 +335,8 @@ function update_unread_counts() {
// This updates some DOM elements directly, so try to
// avoid excessive calls to this.
stream_list.update_dom_with_unread_counts(res);
notifications.update_title_count();
}
function mark_all_as_read(cont) {