Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
filter: Name the -1 for invalid user slugs UNKNOWN_USER_ID.
Aman Agrawal0ba52b2d9685
diff --git a/web/src/filter_util.ts b/web/src/filter_util.tsindex 5b16344160f..9e5fc3d7db3 100644--- a/web/src/filter_util.ts+++ b/web/src/filter_util.ts@@ -5,6 +5,9 @@ import {} from "./state_data.ts";import * as util from "./util.ts";+// Stands in for a user that a narrow URL's slug fails to identify.+export const UNKNOWN_USER_ID = -1;+export function canonicalize_operator(operator: NarrowTerm["operator"]): NarrowCanonicalOperator {if (operator === "pm-with") {// "pm-with:" was renamed to "dm:"diff --git a/web/src/hash_util.ts b/web/src/hash_util.tsindex 48008412c5b..81b9ba794e2 100644--- a/web/src/hash_util.ts+++ b/web/src/hash_util.ts@@ -80,12 +80,12 @@ export function decode_operand(if (user_ids?.length !== 1) {// User mistyped the URL since we don't support// group operand for `sender` or `mentions` narrow.- // Returning -1 will lead to us showing a proper+ // Returning UNKNOWN_USER_ID will lead to us showing a proper// user doesn't exist message in the UI.// Other options is to throw an error which will// lead to us showing a "Invalid URL" banner which// is not very nice looking.- return -1;+ return filter_util.UNKNOWN_USER_ID;}return util.the(user_ids);}diff --git a/web/tests/hash_util.test.cjs b/web/tests/hash_util.test.cjsindex 461505120e8..a2b703470db 100644--- a/web/tests/hash_util.test.cjs+++ b/web/tests/hash_util.test.cjs@@ -9,6 +9,7 @@ const {make_user} = require("./lib/example_user.cjs");const {zrequire} = require("./lib/namespace.cjs");const {run_test} = require("./lib/test.cjs");+const {UNKNOWN_USER_ID} = zrequire("filter_util");const hash_parser = zrequire("hash_parser");const hash_util = zrequire("hash_util");const stream_data = zrequire("stream_data");@@ -45,6 +46,7 @@ run_test("hash_util", () => {encode_decode_operand(operator, operand, "15-Hamlet");encode_decode_operand(operator, 9999, "9999");+ encode_decode_operand(operator, UNKNOWN_USER_ID, "-1");operator = "dm";operand = [hamlet.user_id];