From 8474675076ce9b32e296defdf2935e83ebf9bdee Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Thu, 25 Apr 2013 15:13:06 -0400 Subject: [PATCH] Attach Filters to MessageLists This should allow us to stop special-casing the narrowed message list as much. (imported from commit 1eb7216fbd8aa16b796c239a189d6ce0008344f9) --- zephyr/static/js/message_list.js | 6 +++++- zephyr/static/js/narrow.js | 15 +++++++++++++-- zephyr/static/js/zephyr.js | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/zephyr/static/js/message_list.js b/zephyr/static/js/message_list.js index 0c7723629f..01be0d60e3 100644 --- a/zephyr/static/js/message_list.js +++ b/zephyr/static/js/message_list.js @@ -1,9 +1,10 @@ /*jslint nomen: true */ -function MessageList(table_name, opts) { +function MessageList(table_name, filter, opts) { $.extend(this, {collapse_messages: true}, opts); this._items = []; this._hash = {}; this.table_name = table_name; + this.filter = filter; this._selected_id = -1; this._message_groups = []; // Half-open interval of the indices that define the current render window @@ -13,6 +14,9 @@ function MessageList(table_name, opts) { if (this.table_name) { this._clear_table(); } + if (this.filter === undefined) { + this.filter = new narrow.Filter(); + } this.narrowed = false; if (this.table_name === "zfilt") { this.narrowed = true; diff --git a/zephyr/static/js/narrow.js b/zephyr/static/js/narrow.js index b027ce9770..f0a5215baa 100644 --- a/zephyr/static/js/narrow.js +++ b/zephyr/static/js/narrow.js @@ -3,7 +3,11 @@ var narrow = (function () { var exports = {}; function Filter(operators) { - this._operators = this._canonicalize_operators(operators); + if (operators === undefined) { + this._operators = []; + } else { + this._operators = this._canonicalize_operators(operators); + } } Filter.prototype = { @@ -56,6 +60,10 @@ Filter.prototype = { _build_predicate: function Filter__build_predicate() { var operators = this._operators; + if (! this.can_apply_locally()) { + return function () { return true; }; + } + // FIXME: This is probably pretty slow. // We could turn it into something more like a compiler: // build JavaScript code in a string and then eval() it. @@ -117,6 +125,8 @@ Filter.prototype = { } }; +exports.Filter = Filter; + var current_filter; exports.active = function () { @@ -353,7 +363,8 @@ exports.activate = function (operators, opts) { } }); - narrowed_msg_list = new MessageList('zfilt', {collapse_messages: collapse_messages}); + narrowed_msg_list = new MessageList('zfilt', current_filter, + {collapse_messages: collapse_messages}); current_msg_list = narrowed_msg_list; function maybe_select_closest() { diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 1fddc91829..c4a982e67c 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -1,5 +1,5 @@ var all_msg_list = new MessageList(); -var home_msg_list = new MessageList('zhome'); +var home_msg_list = new MessageList('zhome', new narrow.Filter([["in", "home"]])); var narrowed_msg_list; var current_msg_list = home_msg_list; var subject_dict = {};