Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

filter: Redirect `mentions:me` to `is:mentioned`.

Aman Agrawaldb94b3779e5d
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 8c2f484a695..0701b49df36 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -472,8 +472,14 @@ export class Filter {
}
}
- if (for_pills && operator === "sender" && operand.toLowerCase() === "me") {
- operand = String(people.my_current_user_id());
+ if (for_pills && operand.toLowerCase() === "me") {
+ if (operator === "sender") {
+ operand = String(people.my_current_user_id());
+ } else if (operator === "mentions") {
+ // mentions:me is equivalent to is:mentioned.
+ operator = "is";
+ operand = "mentioned";
+ }
}
// Check if the operator is known, if not then we treat
@@ -562,6 +568,15 @@ export class Filter {
break;
}
case "mentions": {
+ // mentions:me is equivalent to is:mentioned.
+ if (suggestion.operand.toLowerCase() === "me") {
+ potential_narrow_term = {
+ operator: "is",
+ operand: "mentioned",
+ negated: suggestion.negated,
+ };
+ break;
+ }
const result = convert_single_user_id_suggestion_to_term(
suggestion,
canonical_operator,
diff --git a/web/src/hash_util.ts b/web/src/hash_util.ts
index 69251955345..d8f94072386 100644
--- a/web/src/hash_util.ts
+++ b/web/src/hash_util.ts
@@ -235,10 +235,17 @@ export function parse_narrow(hash: string[]): NarrowCanonicalTerm[] | undefined
return undefined;
}
- const canonical_operator = filter_util.canonicalize_operator(
+ let canonical_operator = filter_util.canonicalize_operator(
narrow_operator_schema.parse(operator),
);
- const operand = decode_operand(canonical_operator, raw_operand);
+ let operand = decode_operand(canonical_operator, raw_operand);
+
+ // mentions:me is equivalent to is:mentioned.
+ if (canonical_operator === "mentions" && raw_operand === "me") {
+ canonical_operator = "is";
+ operand = "mentioned";
+ }
+
terms.push({
negated,
operator: canonical_operator,
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index c03fa6fb631..1b694a84c77 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -1052,6 +1052,11 @@ test("canonicalization", () => {
assert.equal(term.operator, "sender");
assert.equal(term.operand, me.user_id);
+ // mentions:me redirects to is:mentioned
+ term = Filter.convert_suggestion_to_term({operator: "mentions", operand: "me"});
+ assert.equal(term.operator, "is");
+ assert.equal(term.operand, "mentioned");
+
// "pm-with" was renamed to "dm"
term = Filter.convert_suggestion_to_term({operator: "pm-with", operand: "me"});
assert.equal(term.operator, "dm");
@@ -1664,6 +1669,14 @@ test("parse", () => {
terms = [{operator: "sender", operand: `${me.user_id}`, negated: true}];
_test(true);
+ string = "mentions:me";
+ terms = [{operator: "is", operand: "mentioned"}];
+ _test(true);
+
+ string = "-mentions:me";
+ terms = [{operator: "is", operand: "mentioned", negated: true}];
+ _test(true);
+
string = "https://www.google.com";
terms = [{operator: "search", operand: "https://www.google.com"}];
_test();
@@ -2258,6 +2271,7 @@ test("convert_suggestion_to_term", () => {
[`dm:${[alice.user_id, -1]}`, false],
[`dm:${[alice.user_id, joe.user_id]}`, true],
[`mentions:${alice.user_id}`, true],
+ ["mentions:me", true],
["mentions:-1", false],
["mentions:invalid", false],
];
diff --git a/web/tests/hash_util.test.cjs b/web/tests/hash_util.test.cjs
index 0fd9440afe1..a0a39552406 100644
--- a/web/tests/hash_util.test.cjs
+++ b/web/tests/hash_util.test.cjs
@@ -203,6 +203,15 @@ run_test("test_parse_narrow", () => {
hash_util.parse_narrow(["narrow", "stream", "99-frontend", "topic", "", "near", ""]),
undefined,
);
+
+ // mentions:me in URL is converted to is:mentioned.
+ assert.deepEqual(hash_util.parse_narrow(["narrow", "mentions", "me"]), [
+ {negated: false, operator: "is", operand: "mentioned"},
+ ]);
+
+ assert.deepEqual(hash_util.parse_narrow(["narrow", "-mentions", "me"]), [
+ {negated: true, operator: "is", operand: "mentioned"},
+ ]);
});
run_test("test_channels_settings_edit_url", () => {