filters: Refactor filter_with_new_topic to expand its functionality.

This intent is that we'll be able to reuse this when editing streams
as well.

* Rename method: filter_with_new_topic to filter_with_new_param.
* Fix tests and method calls.
This commit is contained in:
Wbert Adrian Castro Vera 2020-03-05 13:01:38 -05:00 committed by Tim Abbott
parent 1c6435d4cc
commit 40a6602b09
3 changed files with 11 additions and 5 deletions

View File

@ -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']);

View File

@ -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;
});

View File

@ -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',