message_list: Fix message list missing messages.

Since we allow calling `add_messages` without checking fetch status,
it can lead to non-contiguous message history due to latest message
being added to a message list without previous messages being
fetched.

To fix it, we only allow adding new messages via message_fetch
which properly sets `anchor` to the last message in the list
before fetching and adding messages to the list.
This commit is contained in:
Aman Agrawal
2024-12-18 22:13:10 +05:30
committed by Tim Abbott
parent 9e519f8c18
commit 525ae3aaff
12 changed files with 67 additions and 79 deletions

View File

@@ -153,6 +153,7 @@ function process_result(data: MessageFetchResponse, opts: MessageFetchOptions):
// messages not tracked in unread.ts during this fetching process.
message_util.do_unread_count_updates(messages, true);
const ignore_found_newest = true;
if (messages.length > 0) {
if (opts.msg_list) {
if (opts.validate_filter_topic_post_fetch) {
@@ -160,9 +161,9 @@ function process_result(data: MessageFetchResponse, opts: MessageFetchOptions):
}
// Since this adds messages to the MessageList and renders MessageListView,
// we don't need to call it if msg_list was not defined by the caller.
message_util.add_old_messages(messages, opts.msg_list);
opts.msg_list.add_messages(messages, {}, ignore_found_newest);
} else {
opts.msg_list_data.add_messages(messages);
opts.msg_list_data.add_messages(messages, ignore_found_newest);
}
}