message_fetch: Extract part of post message fetch process.

This will be useful to separately call when restoring msg list
from cached msg list data.
This commit is contained in:
Aman Agrawal
2024-11-02 12:05:23 +05:30
committed by Tim Abbott
parent dc70e50643
commit 3fef305557

View File

@@ -103,6 +103,36 @@ export function load_messages_around_anchor(
}); });
} }
export function fetch_more_if_required_for_current_msg_list(
has_found_oldest: boolean,
has_found_newest: boolean,
looking_for_new_msgs: boolean,
looking_for_old_msgs: boolean,
): void {
assert(message_lists.current !== undefined);
if (message_lists.current.is_combined_feed_view) {
return;
}
if (has_found_oldest && has_found_newest) {
// Even after loading more messages, we have
// no messages to display in this narrow.
narrow_banner.show_empty_narrow_message();
compose_closed_ui.update_buttons_for_private();
compose_recipient.check_posting_policy_for_compose_box();
}
if (looking_for_old_msgs && !has_found_oldest) {
maybe_load_older_messages({
msg_list: message_lists.current,
msg_list_data: message_lists.current.data,
});
}
if (looking_for_new_msgs && !has_found_newest) {
maybe_load_newer_messages({msg_list: message_lists.current});
}
}
function process_result(data: MessageFetchResponse, opts: MessageFetchOptions): void { function process_result(data: MessageFetchResponse, opts: MessageFetchOptions): void {
const raw_messages = data.messages; const raw_messages = data.messages;
@@ -136,29 +166,22 @@ function process_result(data: MessageFetchResponse, opts: MessageFetchOptions):
if ( if (
message_lists.current !== undefined && message_lists.current !== undefined &&
opts.msg_list === message_lists.current && opts.msg_list === message_lists.current &&
!opts.msg_list.is_combined_feed_view &&
opts.msg_list.visibly_empty()
) {
// The view appears to be empty. However, because in stream // The view appears to be empty. However, because in stream
// narrows, we fetch messages including those that might be // narrows, we fetch messages including those that might be
// hidden by topic muting, it's possible that we received all // hidden by topic muting, it's possible that we received all
// the messages we requested, and all of them are in muted // the messages we requested, and all of them are in muted
// topics, but there are older messages for this stream that // topics, but there are older messages for this stream that
// we need to ask the server for. // we need to ask the server for.
if (has_found_oldest && has_found_newest) { message_lists.current.visibly_empty()
// Even after loading more messages, we have ) {
// no messages to display in this narrow. const looking_for_new_msgs = opts.num_after > 0;
narrow_banner.show_empty_narrow_message(); const looking_for_old_msgs = opts.num_before > 0;
compose_closed_ui.update_buttons_for_private(); fetch_more_if_required_for_current_msg_list(
compose_recipient.check_posting_policy_for_compose_box(); has_found_oldest,
} has_found_newest,
looking_for_new_msgs,
if (opts.num_before > 0 && !has_found_oldest) { looking_for_old_msgs,
maybe_load_older_messages({msg_list: opts.msg_list, msg_list_data: opts.msg_list.data}); );
}
if (opts.num_after > 0 && !has_found_newest) {
maybe_load_newer_messages({msg_list: opts.msg_list});
}
} }
if (opts.cont !== undefined) { if (opts.cont !== undefined) {