From 81526936ab4e9170f7057b81d8abf388cf07f882 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 8 Jun 2023 09:41:41 -0700 Subject: [PATCH] starred_messages: Use standard initialization patterns. We aim to only call .initialize methods from ui_init.js, and prefer to pop fields off page_params there and pass them into modules. --- web/src/starred_messages.js | 5 ++--- web/src/starred_messages_ui.js | 1 - web/src/ui_init.js | 3 +++ web/tests/starred_messages.test.js | 8 +++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/web/src/starred_messages.js b/web/src/starred_messages.js index 8f4262eec9..766aab316b 100644 --- a/web/src/starred_messages.js +++ b/web/src/starred_messages.js @@ -1,12 +1,11 @@ import * as message_store from "./message_store"; -import {page_params} from "./page_params"; export const starred_ids = new Set(); -export function initialize() { +export function initialize(starred_messages_params) { starred_ids.clear(); - for (const id of page_params.starred_messages) { + for (const id of starred_messages_params.starred_messages) { starred_ids.add(id); } } diff --git a/web/src/starred_messages_ui.js b/web/src/starred_messages_ui.js index 176c5fb5b8..3799540afc 100644 --- a/web/src/starred_messages_ui.js +++ b/web/src/starred_messages_ui.js @@ -101,6 +101,5 @@ export function confirm_unstar_all_messages_in_topic(stream_id, topic) { } export function initialize() { - starred_messages.initialize(); rerender_ui(); } diff --git a/web/src/ui_init.js b/web/src/ui_init.js index f6d58ad2c6..e60584242f 100644 --- a/web/src/ui_init.js +++ b/web/src/ui_init.js @@ -91,6 +91,7 @@ import * as settings_realm_user_settings_defaults from "./settings_realm_user_se import * as settings_sections from "./settings_sections"; import * as settings_toggle from "./settings_toggle"; import * as spoilers from "./spoilers"; +import * as starred_messages from "./starred_messages"; import * as starred_messages_ui from "./starred_messages_ui"; import * as stream_data from "./stream_data"; import * as stream_edit from "./stream_edit"; @@ -558,6 +559,7 @@ export function initialize_everything() { const presence_params = pop_fields("presences", "server_timestamp"); + const starred_messages_params = pop_fields("starred_messages"); const stream_data_params = pop_fields( "subscriptions", "unsubscribed", @@ -599,6 +601,7 @@ export function initialize_everything() { realm_user_settings_defaults.initialize(realm_settings_defaults_params); people.initialize(page_params.user_id, people_params); + starred_messages.initialize(starred_messages_params); let date_joined; if (!page_params.is_spectator) { diff --git a/web/tests/starred_messages.test.js b/web/tests/starred_messages.test.js index 3088c6e73f..b8c65570c1 100644 --- a/web/tests/starred_messages.test.js +++ b/web/tests/starred_messages.test.js @@ -5,7 +5,7 @@ const {strict: assert} = require("assert"); const {mock_esm, with_overrides, zrequire} = require("./lib/namespace"); const {make_stub} = require("./lib/stub"); const {run_test} = require("./lib/test"); -const {page_params, user_settings} = require("./lib/zpage_params"); +const {user_settings} = require("./lib/zpage_params"); const top_left_corner = mock_esm("../src/top_left_corner", { update_starred_count() {}, @@ -83,8 +83,10 @@ run_test("initialize", () => { starred_messages.starred_ids.add(id); } - page_params.starred_messages = [4, 5, 6]; - starred_messages.initialize(); + const starred_messages_params = { + starred_messages: [4, 5, 6], + }; + starred_messages.initialize(starred_messages_params); assert.deepEqual(starred_messages.get_starred_msg_ids(), [4, 5, 6]); });