From ceee49c075e77b9c0e8ec290e20400115257243f Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 2 May 2018 18:13:30 +0000 Subject: [PATCH] Add filter.is_for_only(operand). --- frontend_tests/node_tests/filter.js | 31 +++++++++++++++++++++++++++++ static/js/filter.js | 22 ++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 658cded01e..7ce5665ed7 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -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() { diff --git a/static/js/filter.js b/static/js/filter.js index 714823d2aa..231657197f 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -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) {