diff --git a/web/src/message_list.js b/web/src/message_list.js index cdfee6684d..e332ddb7a8 100644 --- a/web/src/message_list.js +++ b/web/src/message_list.js @@ -537,5 +537,5 @@ export function initialize() { excludes_muted_topics: true, }); message_lists.set_home(home_msg_list); - message_lists.set_current(home_msg_list); + message_lists.update_current_message_list(home_msg_list); } diff --git a/web/src/message_lists.ts b/web/src/message_lists.ts index 22690d854b..f9c1edc5f6 100644 --- a/web/src/message_lists.ts +++ b/web/src/message_lists.ts @@ -55,10 +55,25 @@ export type MessageList = { export let home: MessageList | undefined; export let current: MessageList | undefined; -export function set_current(msg_list: MessageList): void { +function set_current(msg_list: MessageList): void { + // NOTE: Use update_current_message_list instead of this function. current = msg_list; } +export function update_current_message_list(msg_list: MessageList): void { + if (msg_list !== home) { + home?.view.$list.removeClass("focused-message-list"); + } + + if (current !== home) { + // Remove old msg list from DOM. + current?.view.$list.remove(); + } + + set_current(msg_list); + current?.view.$list.addClass("focused-message-list"); +} + export function set_home(msg_list: MessageList): void { home = msg_list; } diff --git a/web/src/narrow.js b/web/src/narrow.js index 03a3b5fdad..c2bfc2b73e 100644 --- a/web/src/narrow.js +++ b/web/src/narrow.js @@ -87,20 +87,6 @@ export function save_narrow(terms) { changehash(new_hash); } -export function update_current_message_list(msg_list) { - if (msg_list !== message_lists.home) { - message_lists.home?.view.$list.removeClass("focused-message-list"); - } - - if (message_lists.current !== message_lists.home) { - // Remove old msg list from DOM. - message_lists.current?.view.$list.remove(); - } - - message_lists.set_current(msg_list); - message_lists.current.view.$list.addClass("focused-message-list"); -} - export function activate(raw_terms, opts) { /* Main entry point for switching to a new view / message list. Note that for historical reasons related to the current @@ -461,7 +447,7 @@ export function activate(raw_terms, opts) { // Show the new set of messages. It is important to set message_lists.current to // the view right as it's being shown, because we rely on message_lists.current // being shown for deciding when to condense messages. - update_current_message_list(msg_list); + message_lists.update_current_message_list(msg_list); let then_select_offset; if (id_info.target_id === id_info.final_select_id) { @@ -1115,7 +1101,7 @@ export function deactivate() { narrow_state.reset_current_filter(); narrow_state.set_has_shown_message_list_view(); - update_current_message_list(message_lists.home); + message_lists.update_current_message_list(message_lists.home); message_lists.current.resume_reading(); condense.condense_and_collapse(message_lists.home.view.$list.find(".message_row")); diff --git a/web/tests/narrow_activate.test.js b/web/tests/narrow_activate.test.js index 446dcba6c5..1c5a459f48 100644 --- a/web/tests/narrow_activate.test.js +++ b/web/tests/narrow_activate.test.js @@ -38,7 +38,7 @@ const message_lists = mock_esm("../src/message_lists", { }, }, }, - set_current(msg_list) { + update_current_message_list(msg_list) { message_lists.current = msg_list; }, }); diff --git a/web/tests/popover_menus_data.test.js b/web/tests/popover_menus_data.test.js index 9e1687cd8a..7703449e5a 100644 --- a/web/tests/popover_menus_data.test.js +++ b/web/tests/popover_menus_data.test.js @@ -9,6 +9,10 @@ const {page_params, realm} = require("./lib/zpage_params"); const {Filter} = zrequire("filter"); const {MessageList} = zrequire("message_list"); const message_lists = zrequire("message_lists"); +message_lists.update_current_message_list = (list) => { + message_lists.current = list; +}; + const popover_menus_data = zrequire("popover_menus_data"); const people = zrequire("people"); const compose_state = zrequire("compose_state"); @@ -135,7 +139,7 @@ test("my_message_all_actions", () => { // Get message with maximum permissions available // Initialize message list const list = init_message_list(); - message_lists.set_current(list); + message_lists.update_current_message_list(list); // Assume message has been previously edited. // Message is sent by me, and is a stream. I should have all permissions to this message. @@ -185,7 +189,7 @@ test("not_my_message_view_actions", () => { // Get message that is only viewable const list = init_message_list(); - message_lists.set_current(list); + message_lists.update_current_message_list(list); // Message is sent by somebody else and is a stream with previous history. // I should only be able to view this message with no edit/move permissions. @@ -225,7 +229,7 @@ test("not_my_message_view_source_and_move", () => { // Get message that is movable with viewable source const list = init_message_list(); - message_lists.set_current(list); + message_lists.update_current_message_list(list); // Message tests edge case where message it sent by someone else. // Message is movable, however--I should have only view permissions with the exception of moving the message.