Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
filter: Canonicalize term to simplify type resolution.
Aman Agrawal446c2e928fd7
diff --git a/web/src/filter.ts b/web/src/filter.tsindex 615d7e4a889..fe32675f44e 100644--- a/web/src/filter.ts+++ b/web/src/filter.ts@@ -939,17 +939,17 @@ export class Filter {}for (const term of raw_terms) {- const adjusted_term = {...term};+ const adjusted_term = Filter.canonicalize_term(term);if (- Filter.canonicalize_operator(term.operator) === "channel" &&+ adjusted_term.operator === "channel" &&term.operand !== message.stream_id.toString()) {adjusted_term.operand = message.stream_id.toString();terms_changed = true;}if (- Filter.canonicalize_operator(term.operator) === "topic" &&- !util.lower_same(term.operand, message.topic)+ adjusted_term.operator === "topic" &&+ !util.lower_same(adjusted_term.operand, message.topic)) {adjusted_term.operand = message.topic;terms_changed = true;diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjsindex 66aaf8286c0..e616eeab85c 100644--- a/web/tests/filter.test.cjs+++ b/web/tests/filter.test.cjs@@ -3049,7 +3049,9 @@ run_test("adjusted_terms_if_moved", ({override}) => {display_recipient: "general",topic: "discussion",};- let expected = [{operator: "channel", operand: general_sub.stream_id.toString()}];+ let expected = [+ {negated: false, operator: "channel", operand: general_sub.stream_id.toString()},+ ];result = Filter.adjusted_terms_if_moved(raw_terms, message);assert.deepStrictEqual(result, expected);@@ -3061,7 +3063,7 @@ run_test("adjusted_terms_if_moved", ({override}) => {display_recipient: "general",topic: "discussion",};- expected = [{operator: "topic", operand: "discussion"}];+ expected = [{negated: false, operator: "topic", operand: "discussion"}];result = Filter.adjusted_terms_if_moved(raw_terms, message);assert.deepStrictEqual(result, expected);@@ -3077,8 +3079,8 @@ run_test("adjusted_terms_if_moved", ({override}) => {topic: "discussion",};expected = [- {operator: "channel", operand: general_sub.stream_id.toString()},- {operator: "topic", operand: "discussion"},+ {negated: false, operator: "channel", operand: general_sub.stream_id.toString()},+ {negated: false, operator: "topic", operand: "discussion"},];result = Filter.adjusted_terms_if_moved(raw_terms, message);assert.deepStrictEqual(result, expected);@@ -3096,9 +3098,9 @@ run_test("adjusted_terms_if_moved", ({override}) => {topic: "discussion",};expected = [- {operator: "channel", operand: general_sub.stream_id.toString()},- {operator: "topic", operand: "discussion"},- {operator: "sender", operand: "alice"},+ {negated: false, operator: "channel", operand: general_sub.stream_id.toString()},+ {negated: false, operator: "topic", operand: "discussion"},+ {negated: false, operator: "sender", operand: "alice"},];result = Filter.adjusted_terms_if_moved(raw_terms, message);assert.deepStrictEqual(result, expected);