Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_view: Access window.history.state through browser_history.
evykassirer3da3661a3459
diff --git a/web/src/browser_history.ts b/web/src/browser_history.tsindex 4d42d5cc809..506b33014b0 100644--- a/web/src/browser_history.ts+++ b/web/src/browser_history.ts@@ -175,6 +175,11 @@ export function update_current_history_state_data(new_data: StateData): void {window.history.replaceState(state_data, "", window.location.href);}+export function get_current_state_show_more_topics(): boolean | undefined {+ const current_state = state_data_schema.nullable().parse(window.history.state);+ return current_state?.show_more_topics;+}+export function get_home_view_hash(): string {let home_view_hash = `#${user_settings.web_home_view}`;if (home_view_hash === "#recent_topics") {diff --git a/web/src/message_view.js b/web/src/message_view.jsindex 41a1d89908b..1cee06081de 100644--- a/web/src/message_view.js+++ b/web/src/message_view.js@@ -208,7 +208,7 @@ function create_and_update_message_list(filter, id_info, opts) {// workflow we have which calls `message_view.show` after hash is updated.if (opts.change_hash) {update_hash_to_match_filter(filter, opts.trigger);- opts.show_more_topics = window.history.state?.show_more_topics ?? false;+ opts.show_more_topics = browser_history.get_current_state_show_more_topics() ?? false;}// Show the new set of messages. It is important to set message_lists.current todiff --git a/web/tests/narrow_activate.test.js b/web/tests/narrow_activate.test.jsindex 06f78897348..1149b11c2ed 100644--- a/web/tests/narrow_activate.test.js+++ b/web/tests/narrow_activate.test.js@@ -14,6 +14,7 @@ const {Filter} = zrequire("../src/filter");const all_messages_data = mock_esm("../src/all_messages_data");const browser_history = mock_esm("../src/browser_history", {state: {changing_hash: false},+ get_current_state_show_more_topics: () => undefined,});const compose_actions = mock_esm("../src/compose_actions");const compose_banner = mock_esm("../src/compose_banner");