Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
hash_util: Use canonical term type for search_terms_to_hash.
Aman Agrawal9d86650ef18e
diff --git a/web/src/hash_util.ts b/web/src/hash_util.tsindex e54db4af1e5..4bc2c443ba0 100644--- a/web/src/hash_util.ts+++ b/web/src/hash_util.ts@@ -17,7 +17,7 @@ import {narrow_operator_schema,realm,} from "./state_data.ts";-import type {NarrowCanonicalTerm, NarrowTerm} from "./state_data.ts";+import type {NarrowCanonicalTerm} from "./state_data.ts";import * as stream_data from "./stream_data.ts";import * as sub_store from "./sub_store.ts";import type {StreamSubscription} from "./sub_store.ts";@@ -115,7 +115,7 @@ export function by_stream_topic_url(stream_id: number, topic: string): string {// Encodes a term list into the// corresponding hash: the # component// of the narrow URL-export function search_terms_to_hash(terms?: NarrowTerm[]): string {+export function search_terms_to_hash(terms?: NarrowCanonicalTerm[]): string {// Note: This does not return the correct hash for combined feed, recent and inbox view.// These views can have multiple hashes that lead to them, so this function cannot support them.let hash = "#";@@ -124,17 +124,13 @@ export function search_terms_to_hash(terms?: NarrowTerm[]): string {hash = "#narrow";for (const term of terms) {- // Support legacy tuples.- const operator = util.canonicalize_channel_synonyms(term.operator);- const operand = term.operand;-const sign = term.negated ? "-" : "";hash +="/" +sign +- internal_url.encodeHashComponent(operator) ++ internal_url.encodeHashComponent(term.operator) +"/" +- encode_operand(operator, operand);+ encode_operand(term.operator, term.operand);}}@@ -180,8 +176,8 @@ export function group_edit_url(group: UserGroup, right_side_tab: string): stringreturn hash;}-export function search_public_streams_notice_url(terms: NarrowTerm[]): string {- const public_operator: NarrowTerm = {operator: "channels", operand: "public"};+export function search_public_streams_notice_url(terms: NarrowCanonicalTerm[]): string {+ const public_operator: NarrowCanonicalTerm = {operator: "channels", operand: "public"};return search_terms_to_hash([public_operator, ...terms]);}diff --git a/web/src/util.ts b/web/src/util.tsindex 4132b65cb13..65df33e640a 100644--- a/web/src/util.ts+++ b/web/src/util.ts@@ -273,9 +273,12 @@ export function is_channels_synonym(text: string): boolean {export function canonicalize_channel_synonyms(text: string): string {if (is_channel_synonym(text.toLowerCase())) {+ // Function is removed in later commits.+ /* istanbul ignore next */return "channel";}if (is_channels_synonym(text.toLowerCase())) {+ /* istanbul ignore next */return "channels";}return text;diff --git a/web/tests/hashchange.test.cjs b/web/tests/hashchange.test.cjsindex bf1ea95fd79..63fdb67651d 100644--- a/web/tests/hashchange.test.cjs+++ b/web/tests/hashchange.test.cjs@@ -60,7 +60,7 @@ run_test("terms_round_trip", () => {let narrow;terms = [- {operator: "stream", operand: devel_id.toString()},+ {operator: "channel", operand: devel_id.toString()},{operator: "topic", operand: "algol"},];hash = hash_util.search_terms_to_hash(terms);@@ -73,7 +73,7 @@ run_test("terms_round_trip", () => {]);terms = [- {operator: "stream", operand: devel_id.toString()},+ {operator: "channel", operand: devel_id.toString()},{operator: "topic", operand: "visual c++", negated: true},];hash = hash_util.search_terms_to_hash(terms);@@ -92,7 +92,7 @@ run_test("terms_round_trip", () => {stream_id: florida_id,};stream_data.add_sub_for_tests(florida_stream);- terms = [{operator: "stream", operand: florida_id.toString()}];+ terms = [{operator: "channel", operand: florida_id.toString()}];hash = hash_util.search_terms_to_hash(terms);assert.equal(hash, "#narrow/channel/987-Florida.2C-USA");narrow = hash_util.parse_narrow(hash.split("/"));@@ -109,7 +109,7 @@ run_test("stream_to_channel_rename", () => {// Confirm searches with "stream" and "streams" return URLs and// Filter objects with the new "channel" and "channels" operators.- terms = [{operator: "stream", operand: devel_id.toString()}];+ terms = [{operator: "channel", operand: devel_id.toString()}];hash = hash_util.search_terms_to_hash(terms);assert.equal(hash, "#narrow/channel/100-devel");narrow = hash_util.parse_narrow(hash.split("/"));@@ -119,7 +119,7 @@ run_test("stream_to_channel_rename", () => {{operator: "channel", operand: devel_id.toString(), negated: false},]);- terms = [{operator: "streams", operand: "public"}];+ terms = [{operator: "channels", operand: "public"}];hash = hash_util.search_terms_to_hash(terms);assert.equal(hash, "#narrow/channels/public");narrow = hash_util.parse_narrow(hash.split("/"));