message list: Render new messages only after "newest" is found.

If a user sends a message while the latest batch of
messages are being fetched, the new message recieved
from `server_events` gets displayed temporarily out of
order (just after the the current batch of messages)
for the current narrow.

We could just discard the new message events if we havent
recieved the last message i.e. when `found_newest` = False,
since we would recieve them on furthur fetching of that
narrow.
But this would create another bug where the new messages
sent while fetching the last batch of messages would not
get rendered. Because, `found_newest` = True and we would
no longer fetch messages for that narrow, thus the new
messages would not get fetched and are also discarded from
the events codepath.

Thus to resolve both these bugs we use the following approach:

* We do not add the new batch of messages for the current narrow
  while `has_found_newest` = False.
* We store the latest message id which should be displayed at the
  bottom of the narrow in `fetch_status`.
* Ideally `expected_max_message_id`'s value should be equal to the
  last item's id in `MessageListData`.
* So the messages received while `has_found_newest` = False,
  will be fetched later and also the `expected_max_message_id`
  value gets updated.
* And after fetching the last batch where `has_found_newest` = True,
  we would again fetch messages if the `expected_max_message_id` is
  greater than the last message's id found on fetching by refusing to
  update the server provided `has_found_newest` = True in `fetch_status`.

Another benefit of not discarding the events is that the
message gets processed not rendered i.e. we still get desktop
notifications and unread count updates.

Fixes #14017
This commit is contained in:
Ryan Rehman
2020-05-30 21:04:07 +05:30
committed by Tim Abbott
parent 59b68aaa98
commit 6637f2dbb7
5 changed files with 51 additions and 7 deletions

View File

@@ -83,7 +83,7 @@ function get_messages_success(data, opts) {
}
if (opts.num_after > 0) {
opts.msg_list.data.fetch_status.finish_newer_batch({
opts.msg_list.data.fetch_status.finish_newer_batch(data.messages, {
update_loading_indicator: update_loading_indicator,
found_newest: data.found_newest,
});
@@ -92,7 +92,7 @@ function get_messages_success(data, opts) {
// the fetch_status data structure for message_list.all,
// which is never rendered (and just used for
// prepopulating narrowed views).
message_list.all.data.fetch_status.finish_newer_batch({
message_list.all.data.fetch_status.finish_newer_batch(data.messages, {
update_loading_indicator: false,
found_newest: data.found_newest,
});