message_fetch: Refactor logic for constructing data.narrow.

This refactoring should have no functional effect for any call points,
but makes the function behave more naturally.  The comments explain
the situation, but specifically:

* There's the page_params.narrow hack that affects both narrows and
  home_msg_list.

* There's the shared data for home_msg_list and all_msg_list that
  requires we modify the query from home_msg_list.data.public_operators().

And otherwise the logic should just use the operators associated with
the message_list.data object (allowing us to remove the force_fetch
hack added in the last commit).

Hopefully in some future refactoring, we'll be able to migrate those
hacks to live in the Filter object construction and eliminate this
block of conditionals entirely.
This commit is contained in:
Tim Abbott
2020-11-20 11:44:01 -08:00
parent ec3df8cb4f
commit d3ebfce4ae

View File

@@ -178,16 +178,28 @@ exports.load_messages = function (opts) {
} }
let data = {anchor: opts.anchor, num_before: opts.num_before, num_after: opts.num_after}; let data = {anchor: opts.anchor, num_before: opts.num_before, num_after: opts.num_after};
if ((opts.msg_list.narrowed && narrow_state.active()) || opts.force_fetch) { // This block is a hack; structurally, we want to set
// data.narrow = opts.msg_list.data.filter.public_operators()
//
// But support for the message_list.all sharing of data with
// home_msg_list and the (hacky) page_params.narrow feature
// requires a somewhat ugly bundle of conditionals.
if (opts.msg_list === home_msg_list) {
if (page_params.narrow_stream !== undefined) {
data.narrow = JSON.stringify(page_params.narrow);
}
// Otherwise, we don't pass narrow for home_msg_list; this is
// required because it shares its data with all_msg_list, and
// so we need the server to send us message history from muted
// streams and topics even though home_msg_list's in:home
// operators will filter those.
} else {
let operators = opts.msg_list.data.filter.public_operators(); let operators = opts.msg_list.data.filter.public_operators();
if (page_params.narrow !== undefined) { if (page_params.narrow !== undefined) {
operators = operators.concat(page_params.narrow); operators = operators.concat(page_params.narrow);
} }
data.narrow = JSON.stringify(operators); data.narrow = JSON.stringify(operators);
} }
if (opts.msg_list === home_msg_list && page_params.narrow_stream !== undefined) {
data.narrow = JSON.stringify(page_params.narrow);
}
let update_loading_indicator = opts.msg_list === current_msg_list; let update_loading_indicator = opts.msg_list === current_msg_list;
if (opts.num_before > 0) { if (opts.num_before > 0) {
@@ -458,7 +470,6 @@ exports.initialize = function () {
num_before: consts.recent_topics_initial_fetch_size, num_before: consts.recent_topics_initial_fetch_size,
num_after: 0, num_after: 0,
msg_list: recent_topics_message_list, msg_list: recent_topics_message_list,
force_fetch: true,
}); });
}; };