mirror of
https://github.com/zulip/zulip.git
synced 2025-10-31 20:13:46 +00:00
activity: Rename has_focus to client_is_active.
This makes it a lot more clear what it actually means, which is not directly related to whether the browser window is focused.
This commit is contained in:
@@ -854,7 +854,7 @@ run_test('initialize', () => {
|
|||||||
scroll_handler_started = true;
|
scroll_handler_started = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
activity.has_focus = false;
|
activity.client_is_active = false;
|
||||||
|
|
||||||
activity.initialize();
|
activity.initialize();
|
||||||
clear();
|
clear();
|
||||||
@@ -863,7 +863,7 @@ run_test('initialize', () => {
|
|||||||
assert(!activity.new_user_input);
|
assert(!activity.new_user_input);
|
||||||
assert(!$('#zephyr-mirror-error').hasClass('show'));
|
assert(!$('#zephyr-mirror-error').hasClass('show'));
|
||||||
assert.equal(page_params.presences, undefined);
|
assert.equal(page_params.presences, undefined);
|
||||||
assert(activity.has_focus);
|
assert(activity.client_is_active);
|
||||||
$(window).idle = function (params) {
|
$(window).idle = function (params) {
|
||||||
params.onIdle();
|
params.onIdle();
|
||||||
};
|
};
|
||||||
@@ -878,7 +878,7 @@ run_test('initialize', () => {
|
|||||||
|
|
||||||
assert($('#zephyr-mirror-error').hasClass('show'));
|
assert($('#zephyr-mirror-error').hasClass('show'));
|
||||||
assert(!activity.new_user_input);
|
assert(!activity.new_user_input);
|
||||||
assert(!activity.has_focus);
|
assert(!activity.client_is_active);
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
|||||||
@@ -16,14 +16,17 @@ var ACTIVE_PING_INTERVAL_MS = 50 * 1000;
|
|||||||
exports.ACTIVE = "active";
|
exports.ACTIVE = "active";
|
||||||
exports.IDLE = "idle";
|
exports.IDLE = "idle";
|
||||||
|
|
||||||
// When you start Zulip, has_focus should be true, but it might not be the
|
// When you open Zulip in a new browser window, client_is_active
|
||||||
// case after a server-initiated reload.
|
// should be true. When a server-initiated reload happens, however,
|
||||||
exports.has_focus = document.hasFocus && document.hasFocus();
|
// it should be initialized to false. We handle this with a check for
|
||||||
|
// whether the window is focused at initialization time.
|
||||||
|
exports.client_is_active = document.hasFocus && document.hasFocus();
|
||||||
|
|
||||||
// We initialize this to true, to count new page loads, but set it to
|
// new_user_input is a more strict version of client_is_active used
|
||||||
// false in the onload function in reload.js if this was a
|
// primarily for analytics. We initialize this to true, to count new
|
||||||
// server-initiated-reload to avoid counting a server-initiated reload
|
// page loads, but set it to false in the onload function in reload.js
|
||||||
// as user activity.
|
// if this was a server-initiated-reload to avoid counting a
|
||||||
|
// server-initiated reload as user activity.
|
||||||
exports.new_user_input = true;
|
exports.new_user_input = true;
|
||||||
|
|
||||||
var huddle_timestamps = new Dict();
|
var huddle_timestamps = new Dict();
|
||||||
@@ -163,7 +166,7 @@ function mark_client_idle() {
|
|||||||
// When we become idle, we don't immediately send anything to the
|
// When we become idle, we don't immediately send anything to the
|
||||||
// server; instead, we wait for our next periodic update, since
|
// server; instead, we wait for our next periodic update, since
|
||||||
// this data is fundamentally not timely.
|
// this data is fundamentally not timely.
|
||||||
exports.has_focus = false;
|
exports.client_is_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.redraw_user = function (user_id) {
|
exports.redraw_user = function (user_id) {
|
||||||
@@ -265,7 +268,7 @@ function focus_ping(want_redraw) {
|
|||||||
}
|
}
|
||||||
channel.post({
|
channel.post({
|
||||||
url: '/json/users/me/presence',
|
url: '/json/users/me/presence',
|
||||||
data: {status: exports.has_focus ? exports.ACTIVE : exports.IDLE,
|
data: {status: exports.client_is_active ? exports.ACTIVE : exports.IDLE,
|
||||||
ping_only: !want_redraw,
|
ping_only: !want_redraw,
|
||||||
new_user_input: exports.new_user_input},
|
new_user_input: exports.new_user_input},
|
||||||
idempotent: true,
|
idempotent: true,
|
||||||
@@ -302,8 +305,8 @@ function focus_ping(want_redraw) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mark_client_active() {
|
function mark_client_active() {
|
||||||
if (!exports.has_focus) {
|
if (!exports.client_is_active) {
|
||||||
exports.has_focus = true;
|
exports.client_is_active = true;
|
||||||
focus_ping(false);
|
focus_ping(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -939,7 +939,7 @@ MessageListView.prototype = {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activity.has_focus) {
|
if (!activity.client_is_active) {
|
||||||
// Don't autoscroll if the window hasn't had focus
|
// Don't autoscroll if the window hasn't had focus
|
||||||
// recently. This in intended to help protect us from
|
// recently. This in intended to help protect us from
|
||||||
// auto-scrolling downwards when the window is in the
|
// auto-scrolling downwards when the window is in the
|
||||||
|
|||||||
Reference in New Issue
Block a user