mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
Supported negated terms in filter predicates (JS).
(imported from commit b50527620b5b451b4d6e0dc073de4036fe2b7e1f)
This commit is contained in:
parent
90bb689e13
commit
f4db89c7e9
@ -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;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@ -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';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user