filter: Remove redundant is:private operators.

If we have a pm-with, then is:private is redundant
and just forces us to write confusing/verbose code
in various places.
This commit is contained in:
Steve Howell
2020-01-08 12:38:37 +00:00
committed by Tim Abbott
parent 04bb26be3a
commit c7948a7960
2 changed files with 43 additions and 1 deletions

View File

@@ -414,6 +414,28 @@ run_test('public_operators', () => {
assert_same_operators(filter.public_operators(), []);
});
run_test('redundancies', () => {
let terms;
let filter;
terms = [
{ operator: 'pm-with', operand: 'joe@example.com,' },
{ operator: 'is', operand: 'private' },
];
filter = new Filter(terms);
assert(filter.is_exactly('pm-with'));
terms = [
{ operator: 'pm-with',
operand: 'joe@example.com,',
negated: true,
},
{ operator: 'is', operand: 'private' },
];
filter = new Filter(terms);
assert(filter.is_exactly('is-private', 'not-pm-with'));
});
run_test('canonicalizations', () => {
assert.equal(Filter.canonicalize_operator('Is'), 'is');
assert.equal(Filter.canonicalize_operator('Stream'), 'stream');

View File

@@ -152,7 +152,7 @@ function Filter(operators) {
if (operators === undefined) {
this._operators = [];
} else {
this._operators = this._canonicalize_operators(operators);
this._operators = this.fix_operators(operators);
}
}
@@ -454,6 +454,26 @@ Filter.prototype = {
return true;
},
fix_operators: function (operators) {
operators = this._canonicalize_operators(operators);
operators = this._fix_redundant_is_private(operators);
return operators;
},
_fix_redundant_is_private: function (terms) {
const is_pm_with = (term) => {
return Filter.term_type(term) === 'pm-with';
};
if (!_.any(terms, is_pm_with)) {
return terms;
}
return _.reject(terms, (term) => {
return Filter.term_type(term) === 'is-private';
});
},
_canonicalize_operators: function (operators_mixed_case) {
return _.map(operators_mixed_case, function (tuple) {
return Filter.canonicalize_term(tuple);