From c0c11fe2261f0ecdad31dacd2247ede5fd2fd7f2 Mon Sep 17 00:00:00 2001 From: Pragati Agrawal Date: Thu, 15 Aug 2019 15:46:37 +0530 Subject: [PATCH] settings_users: Refactor logic for "last active" column in users table. This uses "last_active" attribute of `user` (`item`) object and makes code much more readable. --- static/js/settings_users.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/static/js/settings_users.js b/static/js/settings_users.js index ec39301ce5..57be216d82 100644 --- a/static/js/settings_users.js +++ b/static/js/settings_users.js @@ -176,18 +176,13 @@ function populate_users(realm_people_data) { modifier: function (item) { var activity_rendered; var today = new XDate(); - if (presence.presence_info[item.user_id]) { - // XDate takes number of milliseconds since UTC epoch. - var last_active = presence.presence_info[item.user_id].last_active * 1000; - - if (!isNaN(last_active)) { - var last_active_date = new XDate(last_active); - activity_rendered = timerender.render_date(last_active_date, undefined, today); - } else { - activity_rendered = $("").text(i18n.t("Never")); - } - } else { + if (item.last_active === LAST_ACTIVE_UNKNOWN) { activity_rendered = $("").text(i18n.t("Unknown")); + } else if (item.last_active === LAST_ACTIVE_NEVER) { + activity_rendered = $("").text(i18n.t("Never")); + } else { + activity_rendered = timerender.render_date( + new XDate(item.last_active * 1000), undefined, today); } var $row = $(render_admin_user_list({