message_edit: Fix display of repeated stream moves.

The recent commits to display the previous and new streams for a moved
message did not correctly handle messages moved multiple times.

To do this, we need to do a somewhat awkward loop, at least until we
modify the API to do this loop for us.
This commit is contained in:
Tim Abbott 2022-02-01 13:58:46 -08:00
parent 71ce154a02
commit b7a07a753f
1 changed files with 16 additions and 3 deletions

View File

@ -24,6 +24,7 @@ export function fetch_and_render_message_history(message) {
success(data) { success(data) {
const content_edit_history = []; const content_edit_history = [];
let prev_time = null; let prev_time = null;
let prev_stream_item = null;
for (const [index, msg] of data.message_history.entries()) { for (const [index, msg] of data.message_history.entries()) {
// Format times and dates nicely for display // Format times and dates nicely for display
@ -60,7 +61,12 @@ export function fetch_and_render_message_history(message) {
} else { } else {
item.prev_stream = stream_data.maybe_get_stream_name(msg.prev_stream); item.prev_stream = stream_data.maybe_get_stream_name(msg.prev_stream);
} }
item.new_stream = stream_data.maybe_get_stream_name(message.stream_id); if (prev_stream_item !== null) {
prev_stream_item.new_stream = stream_data.maybe_get_stream_name(
msg.prev_stream,
);
}
prev_stream_item = item;
} else if (msg.prev_topic) { } else if (msg.prev_topic) {
item.posted_or_edited = $t({defaultMessage: "Topic edited by"}); item.posted_or_edited = $t({defaultMessage: "Topic edited by"});
item.topic_edited = true; item.topic_edited = true;
@ -75,7 +81,12 @@ export function fetch_and_render_message_history(message) {
} else { } else {
item.prev_stream = stream_data.maybe_get_stream_name(msg.prev_stream); item.prev_stream = stream_data.maybe_get_stream_name(msg.prev_stream);
} }
item.new_stream = stream_data.maybe_get_stream_name(message.stream_id); if (prev_stream_item !== null) {
prev_stream_item.new_stream = stream_data.maybe_get_stream_name(
msg.prev_stream,
);
}
prev_stream_item = item;
} else { } else {
// just a content edit // just a content edit
item.posted_or_edited = $t({defaultMessage: "Edited by"}); item.posted_or_edited = $t({defaultMessage: "Edited by"});
@ -83,9 +94,11 @@ export function fetch_and_render_message_history(message) {
} }
content_edit_history.push(item); content_edit_history.push(item);
prev_time = time; prev_time = time;
} }
if (prev_stream_item !== null) {
prev_stream_item.new_stream = stream_data.maybe_get_stream_name(message.stream_id);
}
$("#message-history").attr("data-message-id", message.id); $("#message-history").attr("data-message-id", message.id);
$("#message-history").html( $("#message-history").html(
render_message_edit_history({ render_message_edit_history({