js: Move current_msg_list, home_msg_list to ES6 module message_lists.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-03-29 17:21:21 -07:00
committed by Tim Abbott
parent fbf5ff26af
commit d43ac7357a
61 changed files with 409 additions and 363 deletions

View File

@@ -5,6 +5,7 @@ import {Filter} from "./filter";
import * as huddle_data from "./huddle_data";
import * as message_helper from "./message_helper";
import * as message_list from "./message_list";
import * as message_lists from "./message_lists";
import * as message_scroll from "./message_scroll";
import * as message_store from "./message_store";
import * as message_util from "./message_util";
@@ -40,7 +41,7 @@ function process_result(data, opts) {
if (
messages.length === 0 &&
current_msg_list === message_list.narrowed &&
message_lists.current === message_list.narrowed &&
message_list.narrowed.empty()
) {
// Even after trying to load more messages, we have no
@@ -61,9 +62,9 @@ function process_result(data, opts) {
message_util.do_unread_count_updates(messages);
// If we're loading more messages into the home view, save them to
// the message_list.all as well, as the home_msg_list is reconstructed
// the message_list.all as well, as the message_lists.home is reconstructed
// from message_list.all.
if (opts.msg_list === home_msg_list) {
if (opts.msg_list === message_lists.home) {
message_util.add_old_messages(messages, message_list.all);
}
@@ -84,15 +85,15 @@ function process_result(data, opts) {
}
function get_messages_success(data, opts) {
const update_loading_indicator = opts.msg_list === current_msg_list;
const update_loading_indicator = opts.msg_list === message_lists.current;
if (opts.num_before > 0) {
opts.msg_list.data.fetch_status.finish_older_batch({
update_loading_indicator,
found_oldest: data.found_oldest,
history_limited: data.history_limited,
});
if (opts.msg_list === home_msg_list) {
// When we update home_msg_list, we need to also update
if (opts.msg_list === message_lists.home) {
// When we update message_lists.home, we need to also update
// the fetch_status data structure for message_list.all,
// which is never rendered (and just used for
// prepopulating narrowed views).
@@ -110,8 +111,8 @@ function get_messages_success(data, opts) {
update_loading_indicator,
found_newest: data.found_newest,
});
if (opts.msg_list === home_msg_list) {
// When we update home_msg_list, we need to also update
if (opts.msg_list === message_lists.home) {
// When we update message_lists.home, we need to also update
// the fetch_status data structure for message_list.all,
// which is never rendered (and just used for
// prepopulating narrowed views).
@@ -125,7 +126,7 @@ function get_messages_success(data, opts) {
}
}
if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
if (opts.msg_list.narrowed && opts.msg_list !== message_lists.current) {
// We unnarrowed before receiving new messages so
// don't bother processing the newly arrived messages.
return;
@@ -198,16 +199,16 @@ export function load_messages(opts) {
// 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
// message_lists.home and the (hacky) page_params.narrow feature
// requires a somewhat ugly bundle of conditionals.
if (opts.msg_list === home_msg_list) {
if (opts.msg_list === message_lists.home) {
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
// Otherwise, we don't pass narrow for message_lists.home; 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
// streams and topics even though message_lists.home's in:home
// operators will filter those.
} else {
let operators = opts.msg_list.data.filter.public_operators();
@@ -217,12 +218,12 @@ export function load_messages(opts) {
data.narrow = JSON.stringify(operators);
}
let update_loading_indicator = opts.msg_list === current_msg_list;
let update_loading_indicator = opts.msg_list === message_lists.current;
if (opts.num_before > 0) {
opts.msg_list.data.fetch_status.start_older_batch({
update_loading_indicator,
});
if (opts.msg_list === home_msg_list) {
if (opts.msg_list === message_lists.home) {
message_list.all.data.fetch_status.start_older_batch({
update_loading_indicator,
});
@@ -235,7 +236,7 @@ export function load_messages(opts) {
opts.msg_list.data.fetch_status.start_newer_batch({
update_loading_indicator,
});
if (opts.msg_list === home_msg_list) {
if (opts.msg_list === message_lists.home) {
message_list.all.data.fetch_status.start_newer_batch({
update_loading_indicator,
});
@@ -253,7 +254,7 @@ export function load_messages(opts) {
get_messages_success(data, opts);
},
error(xhr) {
if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
if (opts.msg_list.narrowed && opts.msg_list !== message_lists.current) {
// We unnarrowed before getting an error so don't
// bother trying again or doing further processing.
return;
@@ -294,7 +295,7 @@ export function load_messages_for_narrow(opts) {
}
export function get_backfill_anchor(msg_list) {
if (msg_list === home_msg_list) {
if (msg_list === message_lists.home) {
msg_list = message_list.all;
}
@@ -309,7 +310,7 @@ export function get_backfill_anchor(msg_list) {
}
export function get_frontfill_anchor(msg_list) {
if (msg_list === home_msg_list) {
if (msg_list === message_lists.home) {
msg_list = message_list.all;
}
@@ -376,8 +377,8 @@ export function maybe_load_newer_messages(opts) {
const anchor = get_frontfill_anchor(msg_list);
function load_more(data, args) {
if (args.fetch_again && args.msg_list === current_msg_list) {
maybe_load_newer_messages({msg_list: current_msg_list});
if (args.fetch_again && args.msg_list === message_lists.current) {
maybe_load_newer_messages({msg_list: message_lists.current});
}
}
@@ -397,7 +398,7 @@ export function start_backfilling_messages() {
onIdle() {
do_backfill({
num_before: consts.backfill_batch_size,
msg_list: home_msg_list,
msg_list: message_lists.home,
});
},
});
@@ -408,11 +409,11 @@ export function initialize(home_view_loaded) {
function load_more(data) {
// If we haven't selected a message in the home view yet, and
// the home view isn't empty, we select the anchor message here.
if (home_msg_list.selected_id() === -1 && !home_msg_list.empty()) {
if (message_lists.home.selected_id() === -1 && !message_lists.home.empty()) {
// We fall back to the closest selected id, as the user
// may have removed a stream from the home view while we
// were loading data.
home_msg_list.select_id(data.anchor, {
message_lists.home.select_id(data.anchor, {
then_scroll: true,
use_closest: true,
target_scroll_offset: page_params.initial_offset,
@@ -435,7 +436,7 @@ export function initialize(home_view_loaded) {
anchor: latest_id,
num_before: 0,
num_after: consts.catch_up_batch_size,
msg_list: home_msg_list,
msg_list: message_lists.home,
cont: load_more,
});
}
@@ -454,7 +455,7 @@ export function initialize(home_view_loaded) {
anchor,
num_before: consts.num_before_home_anchor,
num_after: consts.num_after_home_anchor,
msg_list: home_msg_list,
msg_list: message_lists.home,
cont: load_more,
});