From 0f798c7783b559335f13259b234c3bd8273cb0ae Mon Sep 17 00:00:00 2001 From: Waseem Daher Date: Tue, 12 Feb 2013 14:40:28 -0500 Subject: [PATCH] Add an orange dot "away" status for presence information. (imported from commit 7adaff6bee4e3ba3164d2d47b32da28e136c56af) --- zephyr/static/images/orange-dot.png | Bin 0 -> 269 bytes zephyr/static/js/activity.js | 49 +++++++++++++++++++--------- zephyr/static/js/ui.js | 9 +++-- zephyr/static/styles/zephyr.css | 9 +++++ 4 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 zephyr/static/images/orange-dot.png diff --git a/zephyr/static/images/orange-dot.png b/zephyr/static/images/orange-dot.png new file mode 100644 index 0000000000000000000000000000000000000000..653dc4dd746526c47b0bdcf2e4c7fd521b48bf5a GIT binary patch literal 269 zcmeAS@N?(olHy`uVBq!ia0vp^oFL4>1|%O$WD@{VY)RhkE)4%caKYZ?lR?r29+AZi z4BSE>%y{W;-5;PJdx@v7EBjq09$|Hp?ZrX`K%rTlE{-7*ms>Ba&vHs+IQH=Q;q`B% zSo9B=81Uvax&Cgvd(dIR=2xyAJ_c*Kl7xKNUcb7uN`d2$CfoT9KbD_aGVkv#ZvQIg zInVP|OC~O8%kMGdcze-s&a#ujVk>sPgvzmE4$=*WsU#< literal 0 HcmV?d00001 diff --git a/zephyr/static/js/activity.js b/zephyr/static/js/activity.js index 904ed231c4..085a4fbb78 100644 --- a/zephyr/static/js/activity.js +++ b/zephyr/static/js/activity.js @@ -1,32 +1,42 @@ var activity = (function () { +var exports = {}; /* Helpers for detecting user activity and managing user idle states */ -/* 5 minutes after no activity, idle regardless of focus */ -var DEFAULT_IDLE_TIMEOUT = 5 * 60 * 1000 ; +/* 15 minutes after no activity, idle regardless of focus */ +var DEFAULT_IDLE_TIMEOUT_MS = 15 * 60 * 1000; /* 1 minute between keep-alive pings */ -var ACTIVE_PING_INTERVAL = 60 * 1000; -/* Twice the ping interval is the cutoff for dead clients */ -var IDLE_THRESHOLD_SECS = 2 * ACTIVE_PING_INTERVAL / 1000; +var ACTIVE_PING_INTERVAL_MS = 60 * 1000; + +/* Timeouts for away and idle state */ +var AWAY_THRESHOLD_SECS = 5 * 60; +var IDLE_THRESHOLD_SECS = DEFAULT_IDLE_TIMEOUT_MS / 1000; /* Keep in sync with views.py:json_update_active_status() */ var ACTIVE = "active"; var IDLE = "idle"; +/* Client-side state constants */ +exports.user_active = "active"; +exports.user_away = "away"; +exports.user_idle = "idle"; var has_focus = true; var ping_timer; -var exports = {}; - - function sort_users(users, user_info) { // TODO sort by unread count first, once we support that users.sort(function (a, b) { - if (user_info[a] && !user_info[b]) { + if (user_info[a] === exports.user_active && user_info[b] !== exports.user_active) { return -1; - } else if (user_info[b] && !user_info[a]) { + } else if (user_info[b] === exports.user_active && user_info[a] !== exports.user_active) { + return 1; + } + + if (user_info[a] === exports.user_away && user_info[b] !== exports.user_away) { + return -1; + } else if (user_info[b] === exports.user_away && user_info[a] !== exports.user_away) { return 1; } @@ -76,9 +86,16 @@ function focus_ping() { } if (email !== this_email) { - var active = presence.website !== undefined && presence.website.status === ACTIVE && - age >= 0 && age < IDLE_THRESHOLD_SECS; - user_info[this_email] = active; + var status = exports.user_idle; + if (presence.website !== undefined + && presence.website.status === ACTIVE && age >= 0) { + if (age < AWAY_THRESHOLD_SECS) { + status = exports.user_active; + } else if (age < IDLE_THRESHOLD_SECS) { + status = exports.user_away; + } + } + user_info[this_email] = status; } }); users = sort_users(Object.keys(user_info), user_info); @@ -89,7 +106,7 @@ function focus_ping() { function focus_gained() { if (!has_focus) { has_focus = true; - ping_timer = setInterval(focus_ping, ACTIVE_PING_INTERVAL); + ping_timer = setInterval(focus_ping, ACTIVE_PING_INTERVAL_MS); focus_ping(); } @@ -97,12 +114,12 @@ function focus_gained() { exports.initialize = function () { $(window).focus(focus_gained); - $(window).idle({idle: DEFAULT_IDLE_TIMEOUT, + $(window).idle({idle: DEFAULT_IDLE_TIMEOUT_MS, onIdle: focus_lost, onActive: focus_gained, keepTracking: true}); - ping_timer = setInterval(focus_ping, ACTIVE_PING_INTERVAL); + ping_timer = setInterval(focus_ping, ACTIVE_PING_INTERVAL_MS); focus_ping(); }; diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index c110c35170..6aaf9baed1 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -936,8 +936,13 @@ exports.set_presence_list = function(users, presence_info) { compose.start('private', {'private_message_recipient': email}); e.preventDefault(); }); - if (presence_info[email]) { - user.addClass('active-icon'); + switch (presence_info[email]) { + case activity.user_active: + user.addClass('active-icon'); + break; + case activity.user_away: + user.addClass('away-icon'); + break; } $('#user_presences').append(user); diff --git a/zephyr/static/styles/zephyr.css b/zephyr/static/styles/zephyr.css index d38d92aaf8..bc39b00923 100644 --- a/zephyr/static/styles/zephyr.css +++ b/zephyr/static/styles/zephyr.css @@ -98,6 +98,7 @@ a:hover code { #user_presences li { margin-left: 15px; } + #user_presences li.active-icon { margin-left: 0px; } @@ -106,6 +107,14 @@ a:hover code { margin-right: 6px; /* +9px image = 15px */ } +#user_presences li.away-icon { + margin-left: 0px; +} +#user_presences li.away-icon:before { + content: url(/static/images/orange-dot.png); + margin-right: 6px; /* +9px image = 15px */ +} + ul.filters { list-style-type: none; padding-right: 1em;