mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
ui_init: Handle page_params more cleanly.
This cleans up the handoff of page_params data between ui_init and modules that take over ownership of page_params-derived data. Read the long comment in ui_init for a bit more context. Most of this diff is actually test cleanup. And a lot of the diff to "real" code is just glorified `s/page_params/params/` in the `initialize` functions. One little oddity is that we don't actually surrender ownership of `page_params.user_id` to `people.js`. We could plausibly sweep the rest of the codebase to just use `people.my_user_id()` consistently, but it's not a super high priority thing to fix, since the value never changes. The stream_data situation is a bit messy, since we consume `page_params` data in the initialize() function in addition to the `params` data we "own". I added a comment there and intend to follow up. I tried to mostly avoid the "word soup" by extracting three locals at the top. Finally, I don't touch `alert_words` yet, despite it also doing the delete-page-params-data dance. The problem is that `alert_words` doesn't have a proper `initialize()`. We should clean that up and have it use a `Map` internally, too.
This commit is contained in:
@@ -1188,27 +1188,23 @@ exports.is_my_user_id = function (user_id) {
|
||||
return user_id === my_user_id;
|
||||
};
|
||||
|
||||
exports.initialize = function () {
|
||||
for (const person of page_params.realm_users) {
|
||||
exports.initialize = function (my_user_id, params) {
|
||||
for (const person of params.realm_users) {
|
||||
exports.add_in_realm(person);
|
||||
}
|
||||
|
||||
for (const person of page_params.realm_non_active_users) {
|
||||
for (const person of params.realm_non_active_users) {
|
||||
exports.add(person);
|
||||
}
|
||||
|
||||
for (const person of page_params.cross_realm_bots) {
|
||||
for (const person of params.cross_realm_bots) {
|
||||
if (!people_dict.has(person.email)) {
|
||||
exports.add(person);
|
||||
}
|
||||
cross_realm_dict.set(person.user_id, person);
|
||||
}
|
||||
|
||||
exports.initialize_current_user(page_params.user_id);
|
||||
|
||||
delete page_params.realm_users; // We are the only consumer of this.
|
||||
delete page_params.realm_non_active_users;
|
||||
delete page_params.cross_realm_bots;
|
||||
exports.initialize_current_user(my_user_id);
|
||||
};
|
||||
|
||||
window.people = exports;
|
||||
|
||||
Reference in New Issue
Block a user