From f17d0302723046da031b272c510c54d53aace849 Mon Sep 17 00:00:00 2001 From: Luke Faraone Date: Tue, 20 Aug 2013 14:57:26 -0400 Subject: [PATCH] Send IDLE continuously when idle, interpret a too-old status as offline. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps make our statuses more meaningful and should resolve trac #1534. As part of this, we lower OFFLINE_THRESHOLD_SECS to 1.1̅6 minutes and mark the user as idle after 5 minutes. (imported from commit ee6b1ad203554a84b11e16c4c6195be9df5bcf4f) --- static/js/activity.js | 42 +++++++++++++---------------------------- static/styles/zulip.css | 4 ++-- zerver/lib/actions.py | 2 +- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/static/js/activity.js b/static/js/activity.js index 3b4cd91103..315fb56768 100644 --- a/static/js/activity.js +++ b/static/js/activity.js @@ -5,21 +5,19 @@ var exports = {}; Helpers for detecting user activity and managing user idle states */ -/* After this amount of no activity, mark you idle regardless of your focus */ -var DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000; +/* Broadcast "idle" to server after 5 minutes of local inactivity */ +var DEFAULT_IDLE_TIMEOUT_MS = 5 * 60 * 1000; /* Time between keep-alive pings */ var ACTIVE_PING_INTERVAL_MS = 60 * 1000; -/* Timeouts for away and idle state */ -var AWAY_THRESHOLD_SECS = 10 * 60; -var IDLE_THRESHOLD_SECS = DEFAULT_IDLE_TIMEOUT_MS / 1000; +/* Mark users as offline after 70 seconds since their last checkin */ +var OFFLINE_THRESHOLD_SECS = 70; /* Keep in sync with views.py:json_update_active_status() */ var ACTIVE = "active"; var IDLE = "idle"; var has_focus = true; -var ping_timer; var user_info = {}; @@ -32,9 +30,9 @@ function sort_users(users, user_info) { return 1; } - if (user_info[a] === 'away' && user_info[b] !== 'away') { + if (user_info[a] === 'idle' && user_info[b] !== 'idle') { return -1; - } else if (user_info[b] === 'away' && user_info[a] !== 'away') { + } else if (user_info[b] === 'idle' && user_info[a] !== 'idle') { return 1; } @@ -62,12 +60,6 @@ function focus_lost() { } has_focus = false; - - clearInterval(ping_timer); - ping_timer = undefined; - - $.post('/json/update_active_status', {status: IDLE}); - } function update_users() { @@ -77,28 +69,21 @@ function update_users() { function status_from_timestamp(baseline_time, presence) { if (presence.website === undefined) { - return 'idle'; + return 'offline'; } var age = baseline_time - presence.website.timestamp; - var status = 'idle'; - if (presence.website.status === ACTIVE && age >= 0) { - if (age < AWAY_THRESHOLD_SECS) { - status = 'active'; - } else if (age < IDLE_THRESHOLD_SECS) { - status = 'away'; - } + var status = 'offline'; + if (age < OFFLINE_THRESHOLD_SECS) { + status = presence.website.status; } return status; } function focus_ping() { - if (!has_focus) { - return; - } - - $.post('/json/update_active_status', {status: ACTIVE}, function (data) { + $.post('/json/update_active_status', + {status: (has_focus) ? ACTIVE : IDLE}, function (data) { if (data === undefined || data.presences === undefined) { // We sometimes receive no data even on successful // requests; we should figure out why but this will @@ -128,7 +113,6 @@ function focus_ping() { function focus_gained() { if (!has_focus) { has_focus = true; - ping_timer = setInterval(focus_ping, ACTIVE_PING_INTERVAL_MS); focus_ping(); } @@ -141,7 +125,7 @@ exports.initialize = function () { onActive: focus_gained, keepTracking: true}); - ping_timer = setInterval(focus_ping, ACTIVE_PING_INTERVAL_MS); + setInterval(focus_ping, ACTIVE_PING_INTERVAL_MS); focus_ping(); }; diff --git a/static/styles/zulip.css b/static/styles/zulip.css index 5d7c706352..202258b0ae 100644 --- a/static/styles/zulip.css +++ b/static/styles/zulip.css @@ -428,7 +428,7 @@ a:hover code { border-color: #44C21D; } -.user_away .user-status-indicator { +.user_idle .user-status-indicator { border-color: #EC7E18; background-color: #EC7E18; @@ -441,7 +441,7 @@ a:hover code { filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#ec7e18',GradientType=0 ); /* IE6-9 */ } -.user_idle .user-status-indicator { +.user_offline .user-status-indicator { background-color: none; border-color: gray; } diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 59989457f4..61712b7107 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -874,7 +874,7 @@ def do_update_user_presence(user_profile, client, log_time, status): client = client) created = False - stale_status = (log_time - presence.timestamp) > datetime.timedelta(minutes=10) + stale_status = (log_time - presence.timestamp) > datetime.timedelta(minutes=1, seconds=10) was_idle = presence.status == UserPresence.IDLE became_online = (status == UserPresence.ACTIVE) and (stale_status or was_idle)