mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
message-edit-tooltip: Use message_container.modified to show tooltip.
When we build the message_container for the message list view, we get a boolean value for showing the edit notice (saving, moved, or edited) on the message, so we now use that for whether we show the associated message edit tooltip as well. Also, if the message is modified, then we either have a last edited timestamp from the server or from a local edit, so it shouldn't be undefined.
This commit is contained in:
committed by
Tim Abbott
parent
9849048d6e
commit
7c653165af
@@ -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,
|
||||
|
Reference in New Issue
Block a user