mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
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:
@@ -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');
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user