edit_history: Refactor first entry's calculation of show_date_row.

Previously, the show_date_row flag for the first entry in the edit
history modal was directly set to `true`, while in all other entries
it was calculated with identical code. Though show_date_row for the
first entry should indeed always be true, there's no need for it to be
a special case.

In preparation for factoring out the calculation of show_date_row,
this commit nominally calculates the first entry's show_date_row with
the same code that is used to calculate show_date_row for all other
entries. Nominally, because it will still always end up being true.
This commit is contained in:
Sharif Naas
2020-06-06 16:56:14 -07:00
committed by Tim Abbott
parent ffe06ad809
commit 07973d09c9

View File

@@ -6,7 +6,7 @@ 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;
let prev_timestamp = null;
for (const [index, msg] of data.message_history.entries()) {
// Format timestamp nicely for display
@@ -23,7 +23,8 @@ exports.fetch_and_render_message_history = function (message) {
if (index === 0) {
item.posted_or_edited = "Posted by";
item.body_to_render = msg.rendered_content;
item.show_date_row = true;
// This will always be true because of `prev_timestamp = null` above.
item.show_date_row = !moment(timestamp).isSame(prev_timestamp, 'day');
} else if (msg.prev_topic && msg.prev_content) {
item.posted_or_edited = "Edited by";
item.body_to_render = msg.content_html_diff;