Fix first message in narrowed views never appearing.

The message list data structure never had the rendered_idx values
initiatized except via _maybe_rerender (called when a message is
selected).  For the narrowed message list for streams with no messages
yet, we didn't select a message (as there was none to select); the end
result is that msg_list.append() will never rerender because it tries
to subtract undefined from undefined and gets NaN in its test for
whether it needs to rerender.

So fix this by initializing _min_rendered_idx and _max_rendered_idx to
valid values for the empty message list (the closed interval from 0 to -1).

(imported from commit 6afecb1569185a842a3a9108cedba7e88f8befad)
This commit is contained in:
Tim Abbott 2013-03-07 11:30:21 -05:00
parent 68e7a052cb
commit c88684d1f5
1 changed files with 9 additions and 11 deletions

View File

@ -6,6 +6,8 @@ function MessageList(table_name, opts) {
this.table_name = table_name; this.table_name = table_name;
this._selected_id = -1; this._selected_id = -1;
this._message_groups = []; this._message_groups = [];
this._min_rendered_idx = 0;
this._max_rendered_idx = -1;
if (this.table_name) { if (this.table_name) {
this._clear_table(); this._clear_table();
@ -173,10 +175,9 @@ MessageList.prototype = {
var selected_idx = util.lower_bound(this._items, this._selected_id, var selected_idx = util.lower_bound(this._items, this._selected_id,
function (a, b) { return a.id < b; }); function (a, b) { return a.id < b; });
var new_min_idx = -1; var new_min_idx;
// We rerender under the following conditions: // We rerender under the following conditions:
// * This is the first render
// * The selected message is within this._RENDER_THRESHOLD messages // * The selected message is within this._RENDER_THRESHOLD messages
// of the top of the currently rendered window and the top // of the top of the currently rendered window and the top
// of the window does not abut the beginning of the message // of the window does not abut the beginning of the message
@ -185,11 +186,10 @@ MessageList.prototype = {
// of the bottom of the currently rendered window and the // of the bottom of the currently rendered window and the
// bottom of the window does not abut the end of the // bottom of the window does not abut the end of the
// message list // message list
if (! (this._min_rendered_idx === undefined if (! (((selected_idx - this._min_rendered_idx < this._RENDER_THRESHOLD)
|| ((selected_idx - this._min_rendered_idx < this._RENDER_THRESHOLD) && (this._min_rendered_idx !== 0)) ||
&& (this._min_rendered_idx !== 0)) ((this._max_rendered_idx - selected_idx < this._RENDER_THRESHOLD)
|| ((this._max_rendered_idx - selected_idx < this._RENDER_THRESHOLD) && (this._max_rendered_idx !== this._items.length - 1))))
&& (this._max_rendered_idx !== this._items.length - 1))))
{ {
return false; return false;
} }
@ -376,10 +376,8 @@ MessageList.prototype = {
this._items = messages.concat(this._items); this._items = messages.concat(this._items);
this._add_to_hash(messages); this._add_to_hash(messages);
if (this._min_rendered_idx !== undefined) { this._min_rendered_idx += messages.length;
this._min_rendered_idx += messages.length; this._max_rendered_idx += messages.length;
this._max_rendered_idx += messages.length;
}
}, },
all: function MessageList_all() { all: function MessageList_all() {