mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
message scrolling: Fix "Scroll down to view" warning.
We recently added a feature to warn users that they
may need to scroll down to view messages that they
just sent, but it was broken due to various complexities
in the rendering code path.
Now we compute it a bit more rigorously.
It requires us to pass some info about rendering up
and down the stack, which is why it's kind of a long
commit, but the bulk of the logic is in these JS files:
* message_list_view.js
* notifications.js
I choose to pass structs around instead of booleans,
because I anticipate we may eventually add more metadata
about rendering to it, plus bools are just kinda brittle.
(The exceptions are that `_maybe_autoscroll`, which
is at the bottom of the stack, just passes back a simple
boolean, and `notify_local_mixes`, also at the bottom
of the stack, just accepts a simple boolean.)
This errs on the side of warning the user, even if the
new message is partially visible.
Fixes #11138
This commit is contained in:
@@ -45,6 +45,12 @@ exports.MessageList.prototype = {
|
||||
var bottom_messages = info.bottom_messages;
|
||||
var interior_messages = info.interior_messages;
|
||||
|
||||
// Currently we only need data back from rendering to
|
||||
// tell us whether users needs to scroll, which only
|
||||
// applies for `append_to_view`, but this may change over
|
||||
// time.
|
||||
var render_info;
|
||||
|
||||
if (interior_messages.length > 0) {
|
||||
self.view.rerender_the_whole_thing();
|
||||
return true;
|
||||
@@ -54,7 +60,7 @@ exports.MessageList.prototype = {
|
||||
}
|
||||
|
||||
if (bottom_messages.length > 0) {
|
||||
self.append_to_view(bottom_messages, opts);
|
||||
render_info = self.append_to_view(bottom_messages, opts);
|
||||
}
|
||||
|
||||
if (self === exports.narrowed && !self.empty()) {
|
||||
@@ -69,6 +75,8 @@ exports.MessageList.prototype = {
|
||||
// And also select the newly arrived message.
|
||||
self.select_id(self.selected_id(), {then_scroll: true, use_closest: true});
|
||||
}
|
||||
|
||||
return render_info;
|
||||
},
|
||||
|
||||
get: function (id) {
|
||||
@@ -283,7 +291,8 @@ exports.MessageList.prototype = {
|
||||
opts = _.extend({messages_are_new: false}, opts);
|
||||
|
||||
this.num_appends += 1;
|
||||
this.view.append(messages, opts.messages_are_new);
|
||||
var render_info = this.view.append(messages, opts.messages_are_new);
|
||||
return render_info;
|
||||
},
|
||||
|
||||
remove_and_rerender: function MessageList_remove_and_rerender(messages) {
|
||||
|
||||
Reference in New Issue
Block a user