Skip to content

Commit

Permalink
settings_users: Refactor logic for "last active" column in users table.
Browse files Browse the repository at this point in the history
This uses "last_active" attribute of `user` (`item`) object and makes code
much more readable.
  • Loading branch information
pragatiagrawal31 authored and timabbott committed Aug 15, 2019
1 parent a3ef885 commit c0c11fe
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions static/js/settings_users.js
Expand Up @@ -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 = $("<span></span>").text(i18n.t("Never"));
}
} else {
if (item.last_active === LAST_ACTIVE_UNKNOWN) {
activity_rendered = $("<span></span>").text(i18n.t("Unknown"));
} else if (item.last_active === LAST_ACTIVE_NEVER) {
activity_rendered = $("<span></span>").text(i18n.t("Never"));
} else {
activity_rendered = timerender.render_date(
new XDate(item.last_active * 1000), undefined, today);
}

var $row = $(render_admin_user_list({
Expand Down

0 comments on commit c0c11fe

Please sign in to comment.