From ffeb027b4ce3ec5033a9fbcce96a4041e056cbb2 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 5 Mar 2025 08:09:02 +0000 Subject: [PATCH] ui_init: Don't add `with` operator if topic has no messages. Left sidebar can contain links empty topics. If user clicks on them, we add `with` operator to the narrow if the topic is empty. Reproducer: * Click on a topic in left sidebar. * Delete all the messages in the topic. * Click on the topic again. --- web/src/ui_init.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/web/src/ui_init.js b/web/src/ui_init.js index a29d2eb8cd..91a1b9c2eb 100644 --- a/web/src/ui_init.js +++ b/web/src/ui_init.js @@ -668,16 +668,16 @@ export function initialize_everything(state_data) { topic, ); - assert(latest_msg_id !== undefined); + const narrow = [ + {operator: "channel", operand: sub.stream_id.toString()}, + {operator: "topic", operand: topic}, + ]; - message_view.show( - [ - {operator: "channel", operand: sub.stream_id.toString()}, - {operator: "topic", operand: topic}, - {operator: "with", operand: latest_msg_id}, - ], - {trigger: "sidebar"}, - ); + if (latest_msg_id !== undefined) { + narrow.push({operator: "with", operand: latest_msg_id}); + } + + message_view.show(narrow, {trigger: "sidebar"}); }, }); drafts.initialize_ui();