refactor: Stop using page_params.realm_default_streams.

We now only use `page_params.realm_default_streams` during
initialization, and then after that we use `stream_data`
APIs to get default stream ids and related info.  (And
for the event that replace the data, we just update our
internal data structures as well.)

Long term we should have the server just send us ids here,
since we are now hydrating info from stream data in all places.
This commit is contained in:
Steve Howell
2020-03-22 16:32:31 +00:00
committed by Tim Abbott
parent ba495e57eb
commit 2cd9c77979
3 changed files with 9 additions and 12 deletions

View File

@@ -746,7 +746,6 @@ run_test('remove_default_stream', () => {
stream_data.set_realm_default_streams([remove_me]); stream_data.set_realm_default_streams([remove_me]);
stream_data.remove_default_stream(remove_me.stream_id); stream_data.remove_default_stream(remove_me.stream_id);
assert(!stream_data.is_default_stream_id(remove_me.stream_id)); assert(!stream_data.is_default_stream_id(remove_me.stream_id));
assert.equal(page_params.realm_default_streams.length, 0);
}); });
run_test('canonicalized_name', () => { run_test('canonicalized_name', () => {
@@ -816,6 +815,9 @@ run_test('initialize', () => {
stream_id: 2003, stream_id: 2003,
}]; }];
params.realm_default_streams = [
];
return params; return params;
} }
@@ -857,6 +859,7 @@ run_test('filter inactives', () => {
params.unsubscribed = []; params.unsubscribed = [];
params.never_subscribed = []; params.never_subscribed = [];
params.subscriptions = []; params.subscriptions = [];
params.realm_default_streams = [];
stream_data.initialize(params); stream_data.initialize(params);
assert(!stream_data.is_filtering_inactives()); assert(!stream_data.is_filtering_inactives());

View File

@@ -584,7 +584,6 @@ exports.all_topics_in_cache = function (sub) {
}; };
exports.set_realm_default_streams = function (realm_default_streams) { exports.set_realm_default_streams = function (realm_default_streams) {
page_params.realm_default_streams = realm_default_streams;
default_stream_ids.clear(); default_stream_ids.clear();
realm_default_streams.forEach(function (stream) { realm_default_streams.forEach(function (stream) {
@@ -818,17 +817,14 @@ exports.initialize = function (params) {
const subscriptions = params.subscriptions; const subscriptions = params.subscriptions;
const unsubscribed = params.unsubscribed; const unsubscribed = params.unsubscribed;
const never_subscribed = params.never_subscribed; const never_subscribed = params.never_subscribed;
const realm_default_streams = params.realm_default_streams;
/* /*
We also consume some data directly from `page_params`. We also consume some data directly from `page_params`.
This data can be accessed by any other module, This data can be accessed by any other module,
and we consider the authoritative source to be and we consider the authoritative source to be
`page_params`. Some of this data should eventually `page_params`. Some of this data should eventually
be fully handled by stream_data. In particular, be fully handled by stream_data.
the way we handle `page_params.realm_default_streams`
is kinda janky, because we maintain our own data
structure, but then some legacy modules still
refer directly to `page_params`. We should fix that.
*/ */
color_data.claim_colors(subscriptions); color_data.claim_colors(subscriptions);
@@ -843,7 +839,7 @@ exports.initialize = function (params) {
}); });
} }
exports.set_realm_default_streams(page_params.realm_default_streams); exports.set_realm_default_streams(realm_default_streams);
populate_subscriptions(subscriptions, true, true); populate_subscriptions(subscriptions, true, true);
populate_subscriptions(unsubscribed, false, true); populate_subscriptions(unsubscribed, false, true);
@@ -869,9 +865,6 @@ exports.initialize = function (params) {
}; };
exports.remove_default_stream = function (stream_id) { exports.remove_default_stream = function (stream_id) {
page_params.realm_default_streams = page_params.realm_default_streams.filter(
stream => stream.stream_id !== stream_id
);
default_stream_ids.delete(stream_id); default_stream_ids.delete(stream_id);
}; };

View File

@@ -410,7 +410,8 @@ exports.initialize_everything = function () {
const stream_data_params = pop_fields( const stream_data_params = pop_fields(
'subscriptions', 'subscriptions',
'unsubscribed', 'unsubscribed',
'never_subscribed' 'never_subscribed',
'realm_default_streams'
); );
const user_groups_params = pop_fields( const user_groups_params = pop_fields(