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.
This commit is contained in:
Tim Abbott 2023-06-08 09:41:41 -07:00
parent cabd0106f3
commit 81526936ab
4 changed files with 10 additions and 7 deletions

View File

@ -1,12 +1,11 @@
import * as message_store from "./message_store"; import * as message_store from "./message_store";
import {page_params} from "./page_params";
export const starred_ids = new Set(); export const starred_ids = new Set();
export function initialize() { export function initialize(starred_messages_params) {
starred_ids.clear(); starred_ids.clear();
for (const id of page_params.starred_messages) { for (const id of starred_messages_params.starred_messages) {
starred_ids.add(id); starred_ids.add(id);
} }
} }

View File

@ -101,6 +101,5 @@ export function confirm_unstar_all_messages_in_topic(stream_id, topic) {
} }
export function initialize() { export function initialize() {
starred_messages.initialize();
rerender_ui(); rerender_ui();
} }

View File

@ -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_sections from "./settings_sections";
import * as settings_toggle from "./settings_toggle"; import * as settings_toggle from "./settings_toggle";
import * as spoilers from "./spoilers"; import * as spoilers from "./spoilers";
import * as starred_messages from "./starred_messages";
import * as starred_messages_ui from "./starred_messages_ui"; import * as starred_messages_ui from "./starred_messages_ui";
import * as stream_data from "./stream_data"; import * as stream_data from "./stream_data";
import * as stream_edit from "./stream_edit"; import * as stream_edit from "./stream_edit";
@ -558,6 +559,7 @@ export function initialize_everything() {
const presence_params = pop_fields("presences", "server_timestamp"); const presence_params = pop_fields("presences", "server_timestamp");
const starred_messages_params = pop_fields("starred_messages");
const stream_data_params = pop_fields( const stream_data_params = pop_fields(
"subscriptions", "subscriptions",
"unsubscribed", "unsubscribed",
@ -599,6 +601,7 @@ export function initialize_everything() {
realm_user_settings_defaults.initialize(realm_settings_defaults_params); realm_user_settings_defaults.initialize(realm_settings_defaults_params);
people.initialize(page_params.user_id, people_params); people.initialize(page_params.user_id, people_params);
starred_messages.initialize(starred_messages_params);
let date_joined; let date_joined;
if (!page_params.is_spectator) { if (!page_params.is_spectator) {

View File

@ -5,7 +5,7 @@ const {strict: assert} = require("assert");
const {mock_esm, with_overrides, zrequire} = require("./lib/namespace"); const {mock_esm, with_overrides, zrequire} = require("./lib/namespace");
const {make_stub} = require("./lib/stub"); const {make_stub} = require("./lib/stub");
const {run_test} = require("./lib/test"); 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", { const top_left_corner = mock_esm("../src/top_left_corner", {
update_starred_count() {}, update_starred_count() {},
@ -83,8 +83,10 @@ run_test("initialize", () => {
starred_messages.starred_ids.add(id); starred_messages.starred_ids.add(id);
} }
page_params.starred_messages = [4, 5, 6]; const starred_messages_params = {
starred_messages.initialize(); starred_messages: [4, 5, 6],
};
starred_messages.initialize(starred_messages_params);
assert.deepEqual(starred_messages.get_starred_msg_ids(), [4, 5, 6]); assert.deepEqual(starred_messages.get_starred_msg_ids(), [4, 5, 6]);
}); });