From e83c026a27d5999aaf758251fd43dc8f05cf4d53 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Mon, 16 Sep 2013 12:22:52 -0400 Subject: [PATCH] Set focus-related flags correctly after a server reload (imported from commit 408469c0da0cfa5513e6838329816cd88665981f) --- static/js/activity.js | 4 +++- static/js/notifications.js | 6 +++++- zerver/tests/frontend/node/activity.js | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/static/js/activity.js b/static/js/activity.js index 485d066207..0d2a52897c 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -17,7 +17,9 @@ var OFFLINE_THRESHOLD_SECS = 140; exports.ACTIVE = "active"; exports.IDLE = "idle"; -exports.has_focus = true; +// When you start Zulip, has_focus should be true, but it might not be the +// case after a server-initiated reload. +exports.has_focus = document.hasFocus && document.hasFocus(); // We initialize this to true, to count new page loads, but set it to // false in the onload function in reload.js if this was a diff --git a/static/js/notifications.js b/static/js/notifications.js index 3e11284d0b..064449703a 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -3,7 +3,11 @@ var notifications = (function () { var exports = {}; var notice_memory = {}; -var window_has_focus = true; + +// When you start Zulip, window_has_focus should be true, but it might not be the +// case after a server-initiated reload. +var window_has_focus = document.hasFocus && document.hasFocus(); + var asked_permission_already = false; var names; var supports_sound; diff --git a/zerver/tests/frontend/node/activity.js b/zerver/tests/frontend/node/activity.js index 82759d0384..3ccf6fd09a 100644 --- a/zerver/tests/frontend/node/activity.js +++ b/zerver/tests/frontend/node/activity.js @@ -14,6 +14,12 @@ set_global('$', function () { }; }); +set_global('document', { + hasFocus: function () { + return true; + } +}); + var activity = require('js/activity.js'); (function test_sort_users() {