From efa5b3cce115f3e7cbcd83d0a35997dfcee9257c Mon Sep 17 00:00:00 2001 From: Sayam Samal Date: Mon, 28 Oct 2024 19:11:55 +0530 Subject: [PATCH] stream_popover: Handle no messages condition for a topic being moved. Previously, when there were no messages in the topic being moved, the banner in the move topic modal only showed a "Failed" error banner which did not convey the actual error to the user. Also, a server call was being made even when there were no messages in the topic being moved. This commit explicitly handles the non-existent topic, prevents a call to the server when the message_id is undefined, and displays a more informative error banner to the user. --- web/src/stream_popover.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/web/src/stream_popover.js b/web/src/stream_popover.js index f627063061..a1c2127a5b 100644 --- a/web/src/stream_popover.js +++ b/web/src/stream_popover.js @@ -491,6 +491,16 @@ export async function build_move_topic_to_stream_popover( current_stream_id, old_topic_name, (message_id) => { + if (message_id === undefined) { + // There are no messages in the given topic, so we show an error banner + // and return, preventing any attempts to move a non-existent topic. + dialog_widget.hide_dialog_spinner(); + ui_report.client_error( + $t_html({defaultMessage: "There are no messages to move."}), + $("#move_topic_modal #dialog_error"), + ); + return; + } message_edit.move_topic_containing_message_to_stream( message_id, select_stream_id,