Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

recent_view: Update rendered time when user becomes active.

Aman Agrawala271df68db92
diff --git a/web/src/recent_view_ui.ts b/web/src/recent_view_ui.ts
index be2e30b564e..eba7f6d08aa 100644
--- a/web/src/recent_view_ui.ts
+++ b/web/src/recent_view_ui.ts
@@ -11,6 +11,7 @@ import render_recent_view_row from "../templates/recent_view_row.hbs";
import render_recent_view_body from "../templates/recent_view_table.hbs";
import render_user_with_status_icon from "../templates/user_with_status_icon.hbs";
+import * as activity from "./activity.ts";
import * as blueslip from "./blueslip.ts";
import * as buddy_data from "./buddy_data.ts";
import * as compose_closed_ui from "./compose_closed_ui.ts";
@@ -1380,6 +1381,30 @@ export function complete_rerender(): void {
setup_dropdown_filters_widget();
}
+export function update_recent_view_rendered_time(): void {
+ if (activity.client_is_active || !recent_view_util.is_visible() || !topics_widget) {
+ return;
+ }
+
+ // Since we render relative time in recent view, it needs to be
+ // updated otherwise it will show stale time. But, we don't want
+ // to update it every minute due to performance reasons. So, we
+ // only update it when the user comes back from idle which has
+ // maximum chance of user seeing incorrect rendered time.
+ for (const conversation_data of topics_widget.get_rendered_list()) {
+ const last_msg = message_store.get(conversation_data.last_msg_id);
+ assert(last_msg !== undefined);
+ const time = new Date(last_msg.timestamp * 1000);
+ const updated_time = timerender.relative_time_string_from_date(time);
+ const $row = get_topic_row(conversation_data);
+ const rendered_time = $row.find(".recent_topic_timestamp").text().trim();
+ if (updated_time === rendered_time) {
+ continue;
+ }
+ $row.find(".recent_topic_timestamp a").text(updated_time);
+ }
+}
+
export function show(): void {
// We remove event handler before hiding, so they need to
// be attached again, checking for topics_widget to be defined
@@ -1959,4 +1984,5 @@ export function initialize({
revive_current_focus();
}
});
+ $(window).on("focus", update_recent_view_rendered_time);
}
diff --git a/web/src/ui_init.js b/web/src/ui_init.js
index f0a9c32a00c..a29d2eb8cdf 100644
--- a/web/src/ui_init.js
+++ b/web/src/ui_init.js
@@ -490,6 +490,7 @@ export function initialize_everything(state_data) {
realm_logo.initialize();
message_lists.initialize();
+ // Needs to be initialized before activity to register window.focus event.
recent_view_ui.initialize({
on_click_participant(avatar_element, participant_user_id) {
const user = people.get_by_user_id(participant_user_id);