mirror of
https://github.com/zulip/zulip.git
synced 2025-11-15 19:31:58 +00:00
message_fetch: Deduplicate logic for finish_older_batch.
Previously, each individual caller of load_messages that passed num_before > 0 would do its own manual management of fetch_status; now, we just do it inside load_messages.
This commit is contained in:
@@ -48,11 +48,13 @@ run_test('basics', () => {
|
|||||||
can_load_history();
|
can_load_history();
|
||||||
has_not_found_newest();
|
has_not_found_newest();
|
||||||
|
|
||||||
fetch_status.finish_initial_narrow({
|
var data = {
|
||||||
found_oldest: true,
|
found_oldest: true,
|
||||||
found_newest: true,
|
found_newest: true,
|
||||||
history_limited: true,
|
history_limited: true,
|
||||||
});
|
};
|
||||||
|
fetch_status.finish_initial_narrow(data);
|
||||||
|
fetch_status.finish_older_batch(data);
|
||||||
|
|
||||||
has_found_newest();
|
has_found_newest();
|
||||||
blocked_newer();
|
blocked_newer();
|
||||||
@@ -67,11 +69,13 @@ run_test('basics', () => {
|
|||||||
blocked_older();
|
blocked_older();
|
||||||
can_load_history();
|
can_load_history();
|
||||||
|
|
||||||
fetch_status.finish_initial_narrow({
|
data = {
|
||||||
found_oldest: false,
|
found_oldest: false,
|
||||||
found_newest: false,
|
found_newest: false,
|
||||||
history_limited: false,
|
history_limited: false,
|
||||||
});
|
};
|
||||||
|
fetch_status.finish_initial_narrow(data);
|
||||||
|
fetch_status.finish_older_batch(data);
|
||||||
|
|
||||||
can_load_older();
|
can_load_older();
|
||||||
can_load_newer();
|
can_load_newer();
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ var FetchStatus = function () {
|
|||||||
|
|
||||||
self.finish_initial_narrow = function (opts) {
|
self.finish_initial_narrow = function (opts) {
|
||||||
loading_newer = false;
|
loading_newer = false;
|
||||||
loading_older = false;
|
|
||||||
found_oldest = opts.found_oldest;
|
|
||||||
found_newest = opts.found_newest;
|
found_newest = opts.found_newest;
|
||||||
history_limited = opts.history_limited;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.start_older_batch = function () {
|
self.start_older_batch = function () {
|
||||||
|
|||||||
@@ -56,11 +56,24 @@ function process_result(data, opts) {
|
|||||||
stream_list.maybe_scroll_narrow_into_view();
|
stream_list.maybe_scroll_narrow_into_view();
|
||||||
|
|
||||||
if (opts.cont !== undefined) {
|
if (opts.cont !== undefined) {
|
||||||
opts.cont(data, opts);
|
opts.cont(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_messages_success(data, opts) {
|
function get_messages_success(data, opts) {
|
||||||
|
if (opts.num_before > 0) {
|
||||||
|
opts.msg_list.fetch_status.finish_older_batch({
|
||||||
|
found_oldest: data.found_oldest,
|
||||||
|
history_limited: data.history_limited,
|
||||||
|
});
|
||||||
|
if (opts.msg_list === home_msg_list) {
|
||||||
|
message_list.all.fetch_status.finish_older_batch({
|
||||||
|
found_oldest: data.found_oldest,
|
||||||
|
history_limited: data.history_limited,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
|
if (opts.msg_list.narrowed && opts.msg_list !== current_msg_list) {
|
||||||
// We unnarrowed before receiving new messages so
|
// We unnarrowed before receiving new messages so
|
||||||
// don't bother processing the newly arrived messages.
|
// don't bother processing the newly arrived messages.
|
||||||
@@ -223,17 +236,7 @@ exports.do_backfill = function (opts) {
|
|||||||
num_before: opts.num_before,
|
num_before: opts.num_before,
|
||||||
num_after: 0,
|
num_after: 0,
|
||||||
msg_list: msg_list,
|
msg_list: msg_list,
|
||||||
cont: function (data) {
|
cont: function () {
|
||||||
msg_list.fetch_status.finish_older_batch({
|
|
||||||
found_oldest: data.found_oldest,
|
|
||||||
history_limited: data.history_limited,
|
|
||||||
});
|
|
||||||
if (msg_list === home_msg_list) {
|
|
||||||
message_list.all.fetch_status.finish_older_batch({
|
|
||||||
found_oldest: data.found_oldest,
|
|
||||||
history_limited: data.history_limited,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (opts.cont) {
|
if (opts.cont) {
|
||||||
opts.cont();
|
opts.cont();
|
||||||
}
|
}
|
||||||
@@ -291,7 +294,7 @@ exports.start_backfilling_messages = function () {
|
|||||||
|
|
||||||
exports.initialize = function () {
|
exports.initialize = function () {
|
||||||
// get the initial message list
|
// get the initial message list
|
||||||
function load_more(data, opts) {
|
function load_more(data) {
|
||||||
// If we received the initially selected message, select it on the client side,
|
// If we received the initially selected message, select it on the client side,
|
||||||
// but not if the user has already selected another one during load.
|
// but not if the user has already selected another one during load.
|
||||||
//
|
//
|
||||||
@@ -303,19 +306,6 @@ exports.initialize = function () {
|
|||||||
target_scroll_offset: page_params.initial_offset});
|
target_scroll_offset: page_params.initial_offset});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.num_before > 0) {
|
|
||||||
// Only the initial call with num_before=consts.num_before_pointer
|
|
||||||
// has an older batch to finish.
|
|
||||||
home_msg_list.fetch_status.finish_older_batch({
|
|
||||||
found_oldest: data.found_oldest,
|
|
||||||
history_limited: data.history_limited,
|
|
||||||
});
|
|
||||||
message_list.all.fetch_status.finish_older_batch({
|
|
||||||
found_oldest: data.found_oldest,
|
|
||||||
history_limited: data.history_limited,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
home_msg_list.fetch_status.finish_newer_batch({
|
home_msg_list.fetch_status.finish_newer_batch({
|
||||||
found_newest: data.found_newest,
|
found_newest: data.found_newest,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user