message_fetch: Raise fatal error in an impossible case.

When fetching older/new messages, we used to resort to the pointer
to act as anchor when message list was empty.

This appears to be an impossible case, as
`fetch_status.can_load_newer_messages`
should be false in this case and user cannot be scrolling an
empty message_list in the first case.

Hence, we raise a fatal error to inform user of the same.
This commit is contained in:
Aman Agrawal
2020-06-06 20:05:50 +05:30
committed by Tim Abbott
parent 872d43713a
commit 77bbbf7ae0
2 changed files with 68 additions and 22 deletions

View File

@@ -252,18 +252,19 @@ exports.load_messages_for_narrow = function (opts) {
};
exports.get_backfill_anchor = function (msg_list) {
let oldest_message_id;
if (msg_list === home_msg_list) {
msg_list = message_list.all;
}
if (msg_list.first() === undefined) {
oldest_message_id = page_params.pointer;
} else {
oldest_message_id = msg_list.first().id;
const oldest_msg = msg_list.first();
if (oldest_msg) {
return oldest_msg.id;
}
return oldest_message_id;
// msg_list is empty, which is an impossible
// case, raise a fatal error.
blueslip.fatal("There are no message available to backfill.");
return;
};
exports.get_frontfill_anchor = function (msg_list) {
@@ -277,7 +278,13 @@ exports.get_frontfill_anchor = function (msg_list) {
return last_msg.id;
}
return page_params.pointer;
// Although it is impossible that we reach here since we
// are already checking `msg_list.fetch_status.can_load_newer_messages`
// and user cannot be scrolling down on an empty message_list to
// fetch more data, and if user is, then the available data is wrong
// and we raise a fatal error.
blueslip.fatal("There are no message available to frontfill.");
return;
};
exports.maybe_load_older_messages = function (opts) {
@@ -315,7 +322,7 @@ exports.do_backfill = function (opts) {
};
exports.maybe_load_newer_messages = function (opts) {
// This function gets called when you scroll to the top
// This function gets called when you scroll to the bottom
// of your window, and you want to get messages newer
// than what the browsers originally fetched.
const msg_list = opts.msg_list;