From 6fe93a3ff609d8c4f75a6715984c9150962bd628 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 9 Apr 2025 17:57:56 +0530 Subject: [PATCH] inbox_ui: Remove extra effort to return message object. There is no difference in this case when a message object is returned vs not. So, we just return as soon as we have the requried data. This will useful when won't have message ids associated with topic easily when rendering inbox style channel view. --- web/src/inbox_ui.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.ts index 9b0739256d..846d99521c 100644 --- a/web/src/inbox_ui.ts +++ b/web/src/inbox_ui.ts @@ -949,24 +949,22 @@ export function get_focused_row_message(): {message?: Message | undefined} & ( return {message}; } - const $stream = $focused_row.parent(".inbox-topic-container").parent(); - const stream_key = $stream.attr("id"); - assert(stream_key !== undefined); - const row_info = topics_dict.get(stream_key)!.get(conversation_key); - assert(row_info !== undefined); - const message = message_store.get(row_info.latest_msg_id); + // Last case: focused on a topic row. // Since inbox is populated based on unread data which is part // of /register request, it is possible that we don't have the // actual message in our message_store. In that case, we return // a fake message object. - if (message === undefined) { - return { - msg_type: "stream", - stream_id: row_info.stream_id, - topic: row_info.topic_name, - }; - } - return {message}; + const $topic_menu_elt = $focused_row.find(".inbox-topic-menu"); + const topic = $topic_menu_elt.attr("data-topic-name"); + assert(topic !== undefined); + const stream_id = Number($topic_menu_elt.attr("data-stream-id")); + assert(stream_id !== undefined); + + return { + msg_type: "stream", + stream_id, + topic, + }; } export function toggle_topic_visibility_policy(): boolean {