Add filter.is_stream_topic_only().

This commit is contained in:
Steve Howell
2018-05-02 11:23:30 +00:00
committed by Tim Abbott
parent 08307c0e87
commit 2a70f0dba4
2 changed files with 33 additions and 0 deletions

View File

@@ -669,6 +669,31 @@ function make_sub(name, stream_id) {
assert.equal(Filter.describe(narrow), string); assert.equal(Filter.describe(narrow), string);
}()); }());
(function test_is_functions() {
var terms = [
{operator: 'stream', operand: 'My Stream'},
];
var filter = new Filter(terms);
assert.equal(filter.is_stream_only(), true);
assert.equal(filter.is_stream_topic_only(), false);
terms = [
{operator: 'stream', operand: 'My Stream'},
{operator: 'topic', operand: 'My Topic'},
];
filter = new Filter(terms);
assert.equal(filter.is_stream_only(), false);
assert.equal(filter.is_stream_topic_only(), true);
terms = [
{operator: 'stream', operand: 'My Stream', negated: true},
{operator: 'topic', operand: 'My Topic'},
];
filter = new Filter(terms);
assert.equal(filter.is_stream_only(), false);
assert.equal(filter.is_stream_topic_only(), false);
}());
(function test_update_email() { (function test_update_email() {
var terms = [ var terms = [
{operator: 'pm-with', operand: 'steve@foo.com'}, {operator: 'pm-with', operand: 'steve@foo.com'},

View File

@@ -411,6 +411,14 @@ Filter.prototype = {
return (term.operator === 'stream'); return (term.operator === 'stream');
}, },
is_stream_topic_only: function () {
if (this._operators.length !== 2) {
return false;
}
return this.has_operator('stream') && this.has_operator('topic');
},
update_email: function (user_id, new_email) { update_email: function (user_id, new_email) {
_.each(this._operators, function (term) { _.each(this._operators, function (term) {
switch (term.operator) { switch (term.operator) {