Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
people: Fix "#narrow/dm/undefined" links for unknown users.
Aman Agrawal6347a6a32b03
diff --git a/web/src/hash_util.ts b/web/src/hash_util.tsindex 39732ac1417..48008412c5b 100644--- a/web/src/hash_util.ts+++ b/web/src/hash_util.ts@@ -37,21 +37,18 @@ export function get_reload_hash(): string {}export function encode_operand(term: NarrowCanonicalTerm): string {- let slug: string | undefined;switch (term.operator) {case "dm-including":case "dm":- slug = people.user_ids_to_slug(term.operand);- break;+ return people.user_ids_to_slug(term.operand);case "sender":case "mentions":- slug = people.user_ids_to_slug([term.operand]);- break;+ return people.user_ids_to_slug([term.operand]);case "channel":return encode_stream_id(Number.parseInt(term.operand, 10));}- return slug ?? internal_url.encodeHashComponent(String(term.operand));+ return internal_url.encodeHashComponent(term.operand);}export function encode_stream_id(stream_id: number): string {diff --git a/web/src/people.ts b/web/src/people.tsindex f6decc4a0a8..c309931bff0 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -604,24 +604,20 @@ export function user_ids_to_full_names_array(user_ids: number[]): string[] {return names;}-export function user_ids_to_slug(user_ids: number[]): string | undefined {- if (user_ids.length === 0 || !is_valid_user_ids(user_ids)) {- return undefined;+export function user_ids_to_slug(user_ids: number[]): string {+ const ids = String(user_ids);+ if (user_ids.length > 1) {+ return ids + "-group";}- let slug = String(user_ids);- slug += "-";- if (user_ids.length === 1 && user_ids[0] !== undefined) {- const person = get_by_user_id(user_ids[0]);- assert(person !== undefined, "Unknown person in user_ids_string_to_slug");- slug += get_slug_from_full_name(person.full_name);- } else {- slug += "group";+ const user_id = user_ids[0];+ if (user_id === undefined || !is_valid_user_id(user_id)) {+ return ids;}- return slug;+ return ids + "-" + get_slug_from_full_name(get_by_user_id(user_id).full_name);}-export function user_ids_string_to_slug(user_ids_string: string): string | undefined {+export function user_ids_string_to_slug(user_ids_string: string): string {const user_ids = user_ids_string_to_ids_array(user_ids_string);return user_ids_to_slug(user_ids);}diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjsindex b9cb1f0e6e9..36f72b41f96 100644--- a/web/tests/filter.test.cjs+++ b/web/tests/filter.test.cjs@@ -2787,7 +2787,7 @@ test("navbar_helpers", ({override}) => {is_common_narrow: true,icon: undefined,title: "translated: Messages sent by unknown user",- redirect_url_with_search: "/#narrow/sender/undefined",+ redirect_url_with_search: "/#narrow/sender/9999",},{terms: is_starred,@@ -3005,7 +3005,7 @@ test("navbar_helpers", ({override}) => {is_common_narrow: true,zulip_icon: "user",title: "joe and translated: Unknown user (9999)",- redirect_url_with_search: "/#narrow/dm/undefined",+ redirect_url_with_search: "/#narrow/dm/9999," + joe.user_id + "-group",},{terms: has_reaction_sender_me,diff --git a/web/tests/hash_util.test.cjs b/web/tests/hash_util.test.cjsindex a0a39552406..461505120e8 100644--- a/web/tests/hash_util.test.cjs+++ b/web/tests/hash_util.test.cjs@@ -37,13 +37,20 @@ run_test("hash_util", () => {assert.equal(encode_result, expected_val);const new_operand = encode_result;const decode_result = hash_util.decode_operand(operator, new_operand);- assert.equal(decode_result, operand);+ assert.deepEqual(decode_result, operand);}let operator = "sender";let operand = hamlet.user_id;encode_decode_operand(operator, operand, "15-Hamlet");+ encode_decode_operand(operator, 9999, "9999");++ operator = "dm";+ operand = [hamlet.user_id];++ encode_decode_operand(operator, operand, "15-Hamlet");+ encode_decode_operand(operator, [hamlet.user_id, 9999], "15,9999-group");operator = "channel";operand = frontend.stream_id.toString();@@ -56,6 +63,11 @@ run_test("hash_util", () => {encode_decode_operand(operator, operand, "testing.20123");});+run_test("pm_with_url", () => {+ assert.equal(hash_util.pm_with_url("15"), "#narrow/dm/15-Hamlet");+ assert.equal(hash_util.pm_with_url("15,9999"), "#narrow/dm/15,9999-group");+});+run_test("test_get_hash_category", () => {assert.deepEqual(hash_parser.get_hash_category("channels/subscribed"), "channels");assert.deepEqual(hash_parser.get_hash_category("#settings/preferences"), "settings");diff --git a/web/tests/people.test.cjs b/web/tests/people.test.cjsindex e79b38c09f3..034389616e6 100644--- a/web/tests/people.test.cjs+++ b/web/tests/people.test.cjs@@ -987,7 +987,10 @@ run_test("multi_user_methods", () => {assert.equal(people.user_ids_string_to_slug("402"), "402-whatever-402");assert.equal(people.user_ids_to_slug([401, 402]), "401,402-group");assert.equal(people.user_ids_to_slug([402]), "402-whatever-402");- assert.equal(people.user_ids_to_slug([]), undefined);+ // An empty list has no IDs to write.+ assert.equal(people.user_ids_to_slug([]), "");+ assert.equal(people.user_ids_to_slug([9999]), "9999");+ assert.equal(people.user_ids_to_slug([401, 9999]), "401,9999-group");});run_test("user_ids_to_full_names_string", () => {