Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
presence: Use consistent logic for displaying last active time.
Tim Abbott16bd6e6b1de5
diff --git a/frontend_tests/node_tests/buddy_data.js b/frontend_tests/node_tests/buddy_data.jsindex 8698ae1d523..a4e019d9f19 100644--- a/frontend_tests/node_tests/buddy_data.js+++ b/frontend_tests/node_tests/buddy_data.js@@ -505,11 +505,14 @@ test("user_last_seen_time_status", (override) => {assert.equal(buddy_data.user_last_seen_time_status(selma.user_id), "translated: Active now");page_params.realm_is_zephyr_mirror_realm = true;- assert.equal(buddy_data.user_last_seen_time_status(old_user.user_id), "translated: Unknown");+ assert.equal(+ buddy_data.user_last_seen_time_status(old_user.user_id),+ "translated: Last active: translated: Unknown",+ );page_params.realm_is_zephyr_mirror_realm = false;assert.equal(buddy_data.user_last_seen_time_status(old_user.user_id),- "translated: More than 2 weeks ago",+ "translated: Last active: translated: More than 2 weeks ago",);override(presence, "last_active_date", (user_id) => {@@ -522,7 +525,10 @@ test("user_last_seen_time_status", (override) => {return "May 12";});- assert.equal(buddy_data.user_last_seen_time_status(old_user.user_id), "May 12");+ assert.equal(+ buddy_data.user_last_seen_time_status(old_user.user_id),+ "translated: Last active: May 12",+ );});test("get_items_for_users", () => {diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.jsindex bec0fe2a583..27c5b975b27 100644--- a/frontend_tests/node_tests/popovers.js+++ b/frontend_tests/node_tests/popovers.js@@ -171,7 +171,8 @@ test_ui("sender_hover", (override) => {user_time: undefined,user_type: $t({defaultMessage: "Member"}),user_circle_class: "user_circle_empty",- user_last_seen_time_status: "translated: More than 2 weeks ago",+ user_last_seen_time_status:+ "translated: Last active: translated: More than 2 weeks ago",pm_with_uri: "#narrow/pm-with/42-alice",sent_by_uri: "#narrow/sender/42-alice",private_message_class: "respond_personal_button",diff --git a/static/js/buddy_data.js b/static/js/buddy_data.jsindex d9733d024a5..3a745fb85c6 100644--- a/static/js/buddy_data.js+++ b/static/js/buddy_data.js@@ -145,22 +145,24 @@ export function user_last_seen_time_status(user_id) {return $t({defaultMessage: "Active now"});}+ const last_active_date = presence.last_active_date(user_id);+ let last_seen;if (page_params.realm_is_zephyr_mirror_realm) {// We don't send presence data to clients in Zephyr mirroring realms- return $t({defaultMessage: "Unknown"});- }-- // There are situations where the client has incomplete presence- // history on a user. This can happen when users are deactivated,- // or when they just haven't been present in a long time (and we- // may have queries on presence that go back only N weeks).- //- // We give the somewhat vague status of "Unknown" for these users.- const last_active_date = presence.last_active_date(user_id);- if (last_active_date === undefined) {- return $t({defaultMessage: "More than 2 weeks ago"});+ last_seen = $t({defaultMessage: "Unknown"});+ } else if (last_active_date === undefined) {+ // There are situations where the client has incomplete presence+ // history on a user. This can happen when users are deactivated,+ // or when they just haven't been present in a long time (and we+ // may have queries on presence that go back only N weeks).+ //+ // We give this vague status for such users; we will get to+ // delete this code when we finish rewriting the presence API.+ last_seen = $t({defaultMessage: "More than 2 weeks ago"});+ } else {+ last_seen = timerender.last_seen_status_from_date(last_active_date);}- return timerender.last_seen_status_from_date(last_active_date);+ return $t({defaultMessage: "Last active: {last_seen}"}, {last_seen});}export function info_for(user_id) {@@ -181,15 +183,6 @@ export function info_for(user_id) {};}-function get_last_seen(active_status, last_seen) {- if (active_status === "active") {- return last_seen;- }-- const last_seen_text = $t({defaultMessage: "Last active: {last_seen}"}, {last_seen});- return last_seen_text;-}-export function get_title_data(user_ids_string, is_group) {if (is_group === true) {// For groups, just return a string with recipient names.@@ -230,7 +223,6 @@ export function get_title_data(user_ids_string, is_group) {// For buddy list and individual PMS. Since is_group=False, it's// a single, human, user.- const active_status = presence.get_status(user_id);const last_seen = user_last_seen_time_status(user_id);const is_my_user = people.is_my_user_id(user_id);@@ -239,7 +231,7 @@ export function get_title_data(user_ids_string, is_group) {return {first_line: person.full_name,second_line: user_status.get_status_text(user_id),- third_line: get_last_seen(active_status, last_seen),+ third_line: last_seen,show_you: is_my_user,};}@@ -247,7 +239,7 @@ export function get_title_data(user_ids_string, is_group) {// Users does not have a status.return {first_line: person.full_name,- second_line: get_last_seen(active_status, last_seen),+ second_line: last_seen,third_line: "",show_you: is_my_user,};