Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
hash_parser: Add utility function to dynamically detect hash.
PieterCKd882d90857dc
diff --git a/web/src/hash_parser.ts b/web/src/hash_parser.tsindex 16e8d7032b5..c51cb0ecb97 100644--- a/web/src/hash_parser.ts+++ b/web/src/hash_parser.ts@@ -111,6 +111,11 @@ export function is_subscribers_section_opened_for_stream(): boolean {return hash_components[3] === "subscribers";}+export function is_in_specified_hash_category(hash_categories: string[]): boolean {+ const main_hash = get_hash_category(window.location.hash);+ return hash_categories.includes(main_hash);+}+export const allowed_web_public_narrows = ["channels","channel",diff --git a/web/tests/hash_util.test.js b/web/tests/hash_util.test.jsindex ae0ec5eb0d4..149fb24ee1d 100644--- a/web/tests/hash_util.test.js+++ b/web/tests/hash_util.test.js@@ -178,6 +178,26 @@ run_test("test_is_subscribers_section_opened_for_stream", () => {assert.equal(hash_parser.is_subscribers_section_opened_for_stream(), false);});+run_test("test_is_in_specified_hash_category", () => {+ window.location.hash = "#channels/1/Design/subscribers";+ assert.equal(hash_parser.is_in_specified_hash_category(["channels", "channel"]), true);++ window.location.hash = "#channels/99/.EC.A1.B0.EB.A6.AC.EB.B2.95.20.F0.9F.98.8E/subscribers";+ assert.equal(hash_parser.is_in_specified_hash_category(["channels", "channel"]), true);++ window.location.hash = "#gro/channels/channel";+ assert.equal(hash_parser.is_in_specified_hash_category(["stream", "channel", "group"]), false);++ window.location.hash = "#some/stream/channel/group";+ assert.equal(hash_parser.is_in_specified_hash_category(["stream", "channel", "group"]), false);++ window.location.hash = "#some/stream/channel/group";+ assert.equal(hash_parser.is_in_specified_hash_category([""]), false);++ window.location.hash = "#some/stream/channel/group";+ assert.equal(hash_parser.is_in_specified_hash_category([]), false);+});+run_test("test_parse_narrow", () => {assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend"]), [{negated: false, operator: "stream", operand: "frontend"},