mirror of https://github.com/zulip/zulip.git
Attach Filters to MessageLists
This should allow us to stop special-casing the narrowed message list as much. (imported from commit 1eb7216fbd8aa16b796c239a189d6ce0008344f9)
This commit is contained in:
parent
4f4e982ed1
commit
8474675076
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 = {};
|
||||
|
|
Loading…
Reference in New Issue