edit_history: Refactor how we handle times during modal creation.

Currently, the edit history modal does not respect the time format
setting (whether to show times in 12-hour or 24-hour format) when
displaying message edit times (#15171).

This commit refactors how fetch_and_render_message_history() handles
times in order to make fixing that issue in a reasonable way easier.
It will be fixed in a following commit.
This commit is contained in:
Sharif Naas 2020-06-02 04:28:33 -07:00 committed by Tim Abbott
parent 3c6c0dbbe2
commit 8451fb6700
1 changed files with 9 additions and 7 deletions

View File

@ -6,16 +6,18 @@ exports.fetch_and_render_message_history = function (message) {
data: {message_id: JSON.stringify(message.id)},
success: function (data) {
const content_edit_history = [];
let prev_timestamp = null;
let prev_datestamp = null;
for (const [index, msg] of data.message_history.entries()) {
// Format timestamp nicely for display
const timestamp = timerender.get_full_time(msg.timestamp);
// Format times and dates nicely for display
const time = new XDate(msg.timestamp * 1000);
const datestamp = time.toDateString();
const item = {
timestamp: moment(timestamp).format("h:mm A"),
display_date: moment(timestamp).format("MMMM D, YYYY"),
show_date_row: !moment(timestamp).isSame(prev_timestamp, 'day'),
timestamp: time.toString('h:mm TT'),
display_date: time.toString("MMMM d, yyyy"),
show_date_row: datestamp !== prev_datestamp,
};
if (msg.user_id) {
const person = people.get_by_user_id(msg.user_id);
item.edited_by = person.full_name;
@ -43,7 +45,7 @@ exports.fetch_and_render_message_history = function (message) {
content_edit_history.push(item);
prev_timestamp = timestamp;
prev_datestamp = datestamp;
}
$('#message-history').attr('data-message-id', message.id);
$('#message-history').html(render_message_edit_history({