From 2a70f0dba436b58a2ccf64b0d1f2fa0c05d14a11 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 2 May 2018 11:23:30 +0000 Subject: [PATCH] Add filter.is_stream_topic_only(). --- frontend_tests/node_tests/filter.js | 25 +++++++++++++++++++++++++ static/js/filter.js | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 25433206c5..19d9242cd3 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -669,6 +669,31 @@ function make_sub(name, stream_id) { 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() { var terms = [ {operator: 'pm-with', operand: 'steve@foo.com'}, diff --git a/static/js/filter.js b/static/js/filter.js index 7267539160..464e3b9960 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -411,6 +411,14 @@ Filter.prototype = { 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) { _.each(this._operators, function (term) { switch (term.operator) {