Supported negated terms in filter predicates (JS).

(imported from commit b50527620b5b451b4d6e0dc073de4036fe2b7e1f)
This commit is contained in:
Steve Howell 2014-02-11 14:45:54 -05:00
parent 90bb689e13
commit f4db89c7e9
2 changed files with 18 additions and 1 deletions

View File

@ -131,6 +131,7 @@ Filter.canonicalize_operator = function (operator) {
};
Filter.canonicalize_term = function (opts) {
var negated = opts.negated;
var operator = opts.operator;
var operand = opts.operand;
@ -169,6 +170,7 @@ Filter.canonicalize_term = function (opts) {
// We may want to consider allowing mixed-case operators at some point
return {
negated: negated,
operator: operator,
operand: operand
};
@ -327,7 +329,11 @@ Filter.prototype = {
return function (message) {
return _.all(operators, function (term) {
return message_matches_search_term(message, term.operator, term.operand);
var ok = message_matches_search_term(message, term.operator, term.operand);
if (term.negated) {
ok = !ok;
}
return ok;
});
};
}

View File

@ -184,6 +184,17 @@ function get_predicate(operators) {
assert(!predicate({type: 'private', reply_to: 'steve@foo.com'}));
}());
(function test_negated_predicates() {
var predicate;
var narrow;
narrow = [
{operator: 'stream', operand: 'social', negated: true}
];
predicate = new Filter(narrow).predicate();
assert(predicate({type: 'stream', stream: 'devel'}));
assert(!predicate({type: 'stream', stream: 'social'}));
}());
(function test_mit_exceptions() {
global.page_params.domain = 'mit.edu';