Add filter.is_for_only(operand).

This commit is contained in:
Steve Howell
2018-05-02 18:13:30 +00:00
committed by Tim Abbott
parent 7bc95efb41
commit ceee49c075
2 changed files with 53 additions and 0 deletions

View File

@@ -711,6 +711,37 @@ function make_sub(name, stream_id) {
assert.equal(filter.is_stream_only(), false);
assert.equal(filter.is_stream_topic_only(), false);
assert.equal(filter.is_pm_with_only(), true);
assert.equal(filter.is_for_only('mentioned'), false);
assert.equal(filter.is_for_only('private'), false);
terms = [
{operator: 'is', operand: 'private'},
];
filter = new Filter(terms);
assert.equal(filter.is_for_only('mentioned'), false);
assert.equal(filter.is_for_only('private'), true);
terms = [
{operator: 'is', operand: 'mentioned'},
];
filter = new Filter(terms);
assert.equal(filter.is_for_only('mentioned'), true);
assert.equal(filter.is_for_only('private'), false);
terms = [
{operator: 'is', operand: 'mentioned'},
{operator: 'is', operand: 'starred'},
];
filter = new Filter(terms);
assert.equal(filter.is_for_only('mentioned'), false);
assert.equal(filter.is_for_only('private'), false);
terms = [
{operator: 'is', operand: 'mentioned', negated: true},
];
filter = new Filter(terms);
assert.equal(filter.is_for_only('mentioned'), false);
assert.equal(filter.is_for_only('private'), false);
}());
(function test_update_email() {

View File

@@ -433,6 +433,28 @@ Filter.prototype = {
return (term.operator === 'pm-with');
},
is_for_only: function (operand) {
// Call as:
// filter.is_for_only('mentioned')
// filter.is_for_only('private')
// filter.is_for_only('starred')
if (this._operators.length !== 1) {
return false;
}
var term = this._operators[0];
if (term.negated) {
return false;
}
if (term.operator !== 'is') {
return false;
}
return (term.operand === operand);
},
update_email: function (user_id, new_email) {
_.each(this._operators, function (term) {
switch (term.operator) {