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,32 +699,34 @@ test("message_unread", () => {
test("server_counts", () => {
// note that user_id 30 is "me"
page_params.unread_msgs = {
pms: [
{
other_user_id: 101,
// sender_id is deprecated.
sender_id: 101,
unread_message_ids: [31, 32, 60, 61, 62, 63],
},
],
huddles: [
{
user_ids_string: "4,6,30,101",
unread_message_ids: [34, 50],
},
],
streams: [
{
stream_id: 1,
topic: "test",
unread_message_ids: [33, 35, 36],
},
],
mentions: [31, 34, 40, 41],
const unread_params = {
unread_msgs: {
pms: [
{
other_user_id: 101,
// sender_id is deprecated.
sender_id: 101,
unread_message_ids: [31, 32, 60, 61, 62, 63],
},
],
huddles: [
{
user_ids_string: "4,6,30,101",
unread_message_ids: [34, 50],
},
],
streams: [
{
stream_id: 1,
topic: "test",
unread_message_ids: [33, 35, 36],
},
],
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("4,6,101"), 2);

View File

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

View File

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