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.

message-edit-tooltip: Use message_container.modified to show tooltip.

Lauryn Menard7c653165afe9
diff --git a/web/src/message_list_tooltips.ts b/web/src/message_list_tooltips.ts
index 071cf9ae249..c7e53db1b9f 100644
--- a/web/src/message_list_tooltips.ts
+++ b/web/src/message_list_tooltips.ts
@@ -9,7 +9,6 @@ import render_narrow_tooltip from "../templates/narrow_tooltip.hbs";
import * as compose_validate from "./compose_validate.ts";
import {$t} from "./i18n.ts";
import * as message_lists from "./message_lists.ts";
-import type {Message} from "./message_store.ts";
import * as popover_menus from "./popover_menus.ts";
import * as reactions from "./reactions.ts";
import * as rows from "./rows.ts";
@@ -124,21 +123,9 @@ export function destroy_all_message_list_tooltips(): void {
message_list_tippy_instances.clear();
}
-function get_last_edit_timestr(message: Message): string | null {
- let last_edit_timestamp;
- if (message.local_edit_timestamp !== undefined) {
- last_edit_timestamp = message.local_edit_timestamp;
- } else {
- last_edit_timestamp = message.last_edit_timestamp!;
- }
- const last_edit_time = new Date(last_edit_timestamp * 1000);
-
- // Return null if the timestamp is invalid (i.e., there's no edit history).
- if (Number.isNaN(last_edit_time.getTime())) {
- return null;
- }
-
- let date = timerender.render_date(last_edit_time).textContent;
+function get_time_string(timestamp: number): string {
+ const last_modified_time = new Date(timestamp * 1000);
+ let date = timerender.render_date(last_modified_time).textContent;
// If the date is today or yesterday, we don't want to show the date as capitalized.
// Thus, we need to check if the date string contains a digit or not using regex,
// since any other date except today/yesterday will contain a digit.
@@ -149,7 +136,7 @@ function get_last_edit_timestr(message: Message): string | null {
{defaultMessage: "{date} at {time}"},
{
date,
- time: timerender.stringify_time(last_edit_time),
+ time: timerender.stringify_time(last_modified_time),
},
);
}
@@ -392,15 +379,22 @@ export function initialize(): void {
assert(message_lists.current !== undefined);
const message_container = message_lists.current.view.message_containers.get(message_id);
assert(message_container !== undefined);
- const last_edit_timestr = get_last_edit_timestr(message_container.msg);
- if (last_edit_timestr === null) {
+ // If there is no indicator that the message has been modified (saving,
+ // edited, moved), then we don't show the message edit notice tooltip.
+ if (!message_container.modified) {
return false;
}
+ // We know the message has been modified, so we either have a timestamp
+ // from the server or from a local edit.
+ assert(message_container.last_edit_timestamp !== undefined);
+ const last_modified_time_string = get_time_string(
+ message_container.last_edit_timestamp,
+ );
instance.setContent(
parse_html(
render_message_edit_notice_tooltip({
moved: message_container.moved,
- last_edit_timestr,
+ last_edit_timestr: last_modified_time_string,
realm_message_edit_history_is_visible:
realm.realm_message_edit_history_visibility_policy !==
message_edit_history_visibility_policy_values.never.code,