unread: Pop unread_msgs from page_params for initialization.

This change is made so that we are not accessing the global page_params
directly. Note that we also rename unread_msgs to params to match other
modules that follow this pattern.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li 2022-10-27 00:15:43 -04:00 committed by Tim Abbott
parent b9f7edb58a
commit 79b8219797
3 changed files with 31 additions and 27 deletions

View File

@ -699,7 +699,8 @@ test("message_unread", () => {
test("server_counts", () => { test("server_counts", () => {
// note that user_id 30 is "me" // note that user_id 30 is "me"
page_params.unread_msgs = { const unread_params = {
unread_msgs: {
pms: [ pms: [
{ {
other_user_id: 101, other_user_id: 101,
@ -722,9 +723,10 @@ test("server_counts", () => {
}, },
], ],
mentions: [31, 34, 40, 41], mentions: [31, 34, 40, 41],
},
}; };
unread.initialize(); unread.initialize(unread_params);
assert.equal(unread.num_unread_for_user_ids_string("101"), 6); assert.equal(unread.num_unread_for_user_ids_string("101"), 6);
assert.equal(unread.num_unread_for_user_ids_string("4,6,101"), 2); assert.equal(unread.num_unread_for_user_ids_string("4,6,101"), 2);

View File

@ -558,6 +558,8 @@ export function initialize_everything() {
const user_groups_params = pop_fields("realm_user_groups"); const user_groups_params = pop_fields("realm_user_groups");
const unread_params = pop_fields("unread_msgs");
const user_status_params = pop_fields("user_status"); const user_status_params = pop_fields("user_status");
const i18n_params = pop_fields("language_list"); const i18n_params = pop_fields("language_list");
const user_settings_params = pop_fields("user_settings"); const user_settings_params = pop_fields("user_settings");
@ -648,7 +650,7 @@ export function initialize_everything() {
search_pill_widget.initialize(); search_pill_widget.initialize();
reload.initialize(); reload.initialize();
user_groups.initialize(user_groups_params); user_groups.initialize(user_groups_params);
unread.initialize(); unread.initialize(unread_params);
bot_data.initialize(bot_params); // Must happen after people.initialize() bot_data.initialize(bot_params); // Must happen after people.initialize()
message_fetch.initialize(server_events.home_view_loaded); message_fetch.initialize(server_events.home_view_loaded);
message_scroll.initialize(); message_scroll.initialize();

View File

@ -793,8 +793,8 @@ export function get_msg_ids_for_starred() {
return []; return [];
} }
export function initialize() { export function initialize(params) {
const unread_msgs = page_params.unread_msgs; const unread_msgs = params.unread_msgs;
unread_pm_counter.set_huddles(unread_msgs.huddles); unread_pm_counter.set_huddles(unread_msgs.huddles);
unread_pm_counter.set_pms(unread_msgs.pms); unread_pm_counter.set_pms(unread_msgs.pms);