From 07973d09c96d4b8b989b6e249c1800a6ee681e60 Mon Sep 17 00:00:00 2001 From: Sharif Naas Date: Sat, 6 Jun 2020 16:56:14 -0700 Subject: [PATCH] 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. --- static/js/message_edit_history.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/static/js/message_edit_history.js b/static/js/message_edit_history.js index da00eccdc9..9ebd7ea590 100644 --- a/static/js/message_edit_history.js +++ b/static/js/message_edit_history.js @@ -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;