From a33c68026c9b0853c441d7aeff3195594e5d2c0d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 18 Mar 2024 16:55:33 -0700 Subject: [PATCH] message_edit_history: Fix display of unknown private streams. Previously, if such a stream were in certain positions in message edit history, it would incorrectly be displayed as the empty string. --- web/src/message_edit_history.ts | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/web/src/message_edit_history.ts b/web/src/message_edit_history.ts index 44069cdfa8..0b7b69a1c3 100644 --- a/web/src/message_edit_history.ts +++ b/web/src/message_edit_history.ts @@ -85,6 +85,14 @@ const keyboard_handling_context: messages_overlay_ui.Context = { }, }; +function get_display_stream_name(stream_id: number): string { + const stream_name = sub_store.maybe_get_stream_name(stream_id); + if (stream_name === undefined) { + return $t({defaultMessage: "Unknown stream"}); + } + return stream_name; +} + export function fetch_and_render_message_history(message: Message): void { $("#message-edit-history-overlay-container").empty(); $("#message-edit-history-overlay-container").append(render_message_history_overlay()); @@ -128,22 +136,15 @@ export function fetch_and_render_message_history(message: Message): void { prev_topic = msg.prev_topic; new_topic = msg.topic; } else if (msg.prev_topic && msg.prev_stream) { - const sub = sub_store.get(msg.prev_stream); edited_by_notice = $t({defaultMessage: "Moved by {full_name}"}, {full_name}); topic_edited = true; prev_topic = msg.prev_topic; new_topic = msg.topic; stream_changed = true; prev_stream_id = msg.prev_stream; - if (!sub) { - prev_stream = $t({defaultMessage: "Unknown stream"}); - } else { - prev_stream = sub_store.maybe_get_stream_name(msg.prev_stream); - } + prev_stream = get_display_stream_name(msg.prev_stream); if (prev_stream_item !== null) { - prev_stream_item.new_stream = sub_store.maybe_get_stream_name( - msg.prev_stream, - ); + prev_stream_item.new_stream = get_display_stream_name(msg.prev_stream); } } else if (msg.prev_topic) { edited_by_notice = $t({defaultMessage: "Moved by {full_name}"}, {full_name}); @@ -151,19 +152,12 @@ export function fetch_and_render_message_history(message: Message): void { prev_topic = msg.prev_topic; new_topic = msg.topic; } else if (msg.prev_stream) { - const sub = sub_store.get(msg.prev_stream); edited_by_notice = $t({defaultMessage: "Moved by {full_name}"}, {full_name}); stream_changed = true; prev_stream_id = msg.prev_stream; - if (!sub) { - prev_stream = $t({defaultMessage: "Unknown stream"}); - } else { - prev_stream = sub_store.maybe_get_stream_name(msg.prev_stream); - } + prev_stream = get_display_stream_name(msg.prev_stream); if (prev_stream_item !== null) { - prev_stream_item.new_stream = sub_store.maybe_get_stream_name( - msg.prev_stream, - ); + prev_stream_item.new_stream = get_display_stream_name(msg.prev_stream); } } else { // just a content edit @@ -194,7 +188,7 @@ export function fetch_and_render_message_history(message: Message): void { } if (prev_stream_item !== null) { assert(message.type === "stream"); - prev_stream_item.new_stream = sub_store.maybe_get_stream_name(message.stream_id); + prev_stream_item.new_stream = get_display_stream_name(message.stream_id); } // In order to correctly compute the recipient_bar_color