diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js index 5c9f8f0c69..b117fe7ac5 100644 --- a/frontend_tests/node_tests/filter.js +++ b/frontend_tests/node_tests/filter.js @@ -396,7 +396,10 @@ run_test('topic_stuff', () => { assert(!filter.has_topic('wrong', 'old topic')); assert(!filter.has_topic('foo', 'wrong')); - const new_filter = filter.filter_with_new_topic('new topic'); + const new_filter = filter.filter_with_new_params({ + operator: 'topic', + operand: 'new topic', + }); assert.deepEqual(new_filter.operands('stream'), ['foo']); assert.deepEqual(new_filter.operands('topic'), ['new topic']); diff --git a/static/js/filter.js b/static/js/filter.js index 2e10be37c4..1da86e8990 100644 --- a/static/js/filter.js +++ b/static/js/filter.js @@ -486,11 +486,11 @@ Filter.prototype = { return operators_mixed_case.map(tuple => Filter.canonicalize_term(tuple)); }, - filter_with_new_topic: function (new_topic) { + filter_with_new_params: function (params) { const terms = this._operators.map(term => { const new_term = { ...term }; - if (new_term.operator === 'topic' && !new_term.negated) { - new_term.operand = new_topic; + if (new_term.operator === params.operator && !new_term.negated) { + new_term.operand = params.operand; } return new_term; }); diff --git a/static/js/message_events.js b/static/js/message_events.js index 1f0ee66f03..401b5ba44d 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -166,7 +166,10 @@ exports.update_messages = function update_messages(events) { if (selection_changed_topic) { if (current_filter && stream_name) { if (current_filter.has_topic(stream_name, orig_topic)) { - const new_filter = current_filter.filter_with_new_topic(new_topic); + const new_filter = current_filter.filter_with_new_params({ + operator: 'topic', + operand: new_topic, + }); const operators = new_filter.operators(); const opts = { trigger: 'topic change',