From d93c7545f63a9eae151e9ddbc95159e60267779b Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Thu, 7 Nov 2013 10:40:57 -0500 Subject: [PATCH] Revert rendering window changes related to summarization This reverts commit c10d9c1a0d23891acce88bf8d79866c08cb75681. This reverts commit 9259a246946cd968a8725c38ff5ef2d4b4793717. (imported from commit 50e9e0136c2487cc63d75ae2b78df0c70a1b0be1) --- static/js/message_list.js | 35 ---------------------- static/js/message_list_view.js | 25 +++++++++------- zerver/tests/frontend/node/message_list.js | 25 ---------------- 3 files changed, 14 insertions(+), 71 deletions(-) diff --git a/static/js/message_list.js b/static/js/message_list.js index f6cba1a844..bb9d2c4d64 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -297,41 +297,6 @@ MessageList.prototype = { return null; }, - // Counts the number of fully-displayed (not summarized, muted, or hidden) - // messages from array position idx1 to idx2 - count_full_messages_between: function (idx1, idx2) { - var i; - var count = 0; - for (i = idx1; i < idx2; i++) { - if (this.summary_adjective(this._items[i]) === null) { - count += 1; - } - } - return count; - }, - - // Adjusts an array index backwards by `count` fully-displayed messages - idx_full_messages_before: function (idx, count) { - while (idx > 0 && count > 0){ - idx -= 1; - if (this.summary_adjective(this._items[idx]) === null) { - count -= 1; - } - } - return idx; - }, - - // Advances an array index forward past `count` fully-displayed messages - idx_full_messages_after: function (idx, count) { - while (idx < this._items.length && count > 0){ - if (this.summary_adjective(this._items[idx]) === null) { - count -= 1; - } - idx += 1; - } - return idx; - }, - selected_idx: function MessageList_selected_idx() { return util.lower_bound(this._items, this._selected_id, function (a, b) { return a.id < b; }); diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index ebf539b202..936be68727 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -505,13 +505,14 @@ MessageListView.prototype = { }, update_render_window: function MessageListView__update_render_window(selected_idx, check_for_changed) { - var new_start = this.list.idx_full_messages_before(selected_idx, this._RENDER_WINDOW_SIZE / 2); + var new_start = Math.max(selected_idx - this._RENDER_WINDOW_SIZE / 2, 0); if (check_for_changed && new_start === this._render_win_start) { return false; } this._render_win_start = new_start; - this._render_win_end = this.list.idx_full_messages_after(selected_idx, this._RENDER_WINDOW_SIZE / 2); + this._render_win_end = Math.min(this._render_win_start + this._RENDER_WINDOW_SIZE, + this.list.num_items()); return true; }, @@ -524,15 +525,17 @@ MessageListView.prototype = { var selected_idx = this.list.selected_idx(); // We rerender under the following conditions: - // * The selected message is within this._RENDER_THRESHOLD visible - // messages of the top of the currently rendered window and the top - // of the window does not abut the beginning of the message list - // * The selected message is within this._RENDER_THRESHOLD visible - // messages of the bottom of the currently rendered window and the - // bottom of the window does not abut the end of the message list - if (! (((this.list.count_full_messages_between(this._render_win_start, selected_idx) < this._RENDER_THRESHOLD) + // * The selected message is within this._RENDER_THRESHOLD messages + // of the top of the currently rendered window and the top + // of the window does not abut the beginning of the message + // list + // * The selected message is within this._RENDER_THRESHOLD messages + // of the bottom of the currently rendered window and the + // bottom of the window does not abut the end of the + // message list + if (! (((selected_idx - this._render_win_start < this._RENDER_THRESHOLD) && (this._render_win_start !== 0)) || - ((this.list.count_full_messages_between(selected_idx, this._render_win_end) <= this._RENDER_THRESHOLD) + ((this._render_win_end - selected_idx <= this._RENDER_THRESHOLD) && (this._render_win_end !== this.list.num_items())))) { return false; @@ -571,7 +574,7 @@ MessageListView.prototype = { }, append: function MessageListView__append(messages, messages_are_new) { - var cur_window_size = this.list.count_full_messages_between(this._render_win_start, this._render_win_end); + var cur_window_size = this._render_win_end - this._render_win_start; if (cur_window_size < this._RENDER_WINDOW_SIZE) { var slice_to_render = messages.slice(0, this._RENDER_WINDOW_SIZE - cur_window_size); this.render(slice_to_render, 'bottom', messages_are_new); diff --git a/zerver/tests/frontend/node/message_list.js b/zerver/tests/frontend/node/message_list.js index adb001d8e8..d02f0f29de 100644 --- a/zerver/tests/frontend/node/message_list.js +++ b/zerver/tests/frontend/node/message_list.js @@ -114,28 +114,3 @@ var MessageList = require('js/message_list'); assert.equal(list.nth_most_recent_id(3), 10); assert.equal(list.nth_most_recent_id(4), -1); }()); - -(function test_message_counting() { - global.feature_flags.summarize_read_while_narrowed = true; - var list = new MessageList(undefined, {}, {summarize_read: 'home'}); - - var summarized_flags = ['summarize_in_home']; - var unsummarized_flags = []; - - list.append([ - {id: 10, flags: unsummarized_flags}, - {id: 20, flags: unsummarized_flags}, - {id: 30, flags: summarized_flags}, - {id: 40, flags: summarized_flags}, - {id: 50, flags: unsummarized_flags}, - {id: 60, flags: summarized_flags} - ]); - list.min_id_exempted_from_summaries = 10000; - - assert.equal(list.count_full_messages_between(1, 5), 2); - assert.equal(list.idx_full_messages_before(5, 2), 1); - assert.equal(list.idx_full_messages_before(5, 10), 0); - assert.equal(list.idx_full_messages_after(0, 3), 5); - assert.equal(list.idx_full_messages_after(0, 10), 6); - -}());