recent_view_ui: Avoid non-contiguous rows in recent view.

Fixes #27207

The recent view's data sources are mainly all_messages_data,
but if you click into a stream via the left sidebar that has
no recent conversation history, one can reliably reproduce that
some of those conversations will end up being displayed in the
recent view, despite not being temporally contiguous with what
it has data for.

To avoid it, we only process messages fetched for all message data.
This commit is contained in:
Aman Agrawal 2023-10-14 07:47:47 +00:00 committed by Tim Abbott
parent 2d4d4b86eb
commit 2348d6f1f9
2 changed files with 15 additions and 8 deletions

View File

@ -61,9 +61,11 @@ function process_result(data, opts) {
}
}
if (messages.length > 0 && opts.msg_list === message_lists.home) {
// We keep track of how far back we've fetched messages for, for messaging in
// the recent view. This assumes `data.messages` is already sorted.
if (messages.length > 0 && (opts.msg_list === message_lists.home || opts.is_recent_view_data)) {
recent_view_ui.process_messages(messages);
// Update the recent view UI's understanding of which messages
// we have available for the recent view.
const oldest_timestamp = all_messages_data.first().timestamp;
recent_view_ui.set_oldest_message_date(
oldest_timestamp,
@ -73,7 +75,6 @@ function process_result(data, opts) {
}
huddle_data.process_loaded_messages(messages);
recent_view_ui.process_messages(messages);
stream_list.update_streams_sidebar();
stream_list.maybe_scroll_narrow_into_view();
@ -591,6 +592,7 @@ export function initialize(home_view_loaded) {
num_before: consts.recent_view_initial_fetch_size,
num_after: 0,
msg_list_data: recent_view_message_list_data,
is_recent_view_data: true,
cont: recent_view_ui.hide_loading_indicator,
});
}

View File

@ -370,10 +370,15 @@ export function hide_loading_indicator() {
}
export function process_messages(messages) {
// While this is inexpensive and handles all the cases itself,
// the UX can be bad if user wants to scroll down the list as
// the UI will be returned to the beginning of the list on every
// update.
// This code path processes messages from 3 sources:
// 1. Newly sent messages from the server_events system. This is safe to
// process because we always will have the latest previously sent messages.
// 2. Messages in all_messages_data, the main cache of contiguous
// message history that the client maintains.
// 3. Latest messages fetched specifically for Recent view when
// the browser first loads. We will be able to remove this once
// all_messages_data is fetched in a better order.
let conversation_data_updated = false;
if (messages.length > 0) {
for (const msg of messages) {