message_list: Fix selecting the first message when previously empty.

There two situations where we might add messages to a previously empty
message list. The first is when a new message comes in; in that case,
the previous logic of just selecting the first message would work.

But in the case where we're instead adding a bunch of (previously
read) messages via a backfill API request, which can occur in a few
cases, including a stream narrow where all the topics with recent
messages are muted, we should use our standard rules to pick a message
to select, namely the first unread message (if any) or last message if
none are unread.
This commit is contained in:
Tim Abbott 2023-05-01 18:28:16 -07:00
parent 8f27a6fb73
commit 8f1c3a0fa1
1 changed files with 6 additions and 2 deletions

View File

@ -124,8 +124,12 @@ export class MessageList {
} }
if (this.narrowed && !this.empty() && this.selected_id() === -1) { if (this.narrowed && !this.empty() && this.selected_id() === -1) {
// And also select the newly arrived message. // The message list was previously empty, but now isn't
this.select_id(this.selected_id(), {then_scroll: true, use_closest: true}); // due to adding these messages, and we need to select a
// message. Regardless of whether the messages are new or
// old, we want to select a message as though we just
// entered this view.
this.select_id(this.first_unread_message_id(), {then_scroll: true, use_closest: true});
} }
return render_info; return render_info;