Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
hash_util: Add is_editing_stream helper.
Steve Howell1c54d44f979b
diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.jsindex a1239b17a54..ab3b1f51c8e 100644--- a/frontend_tests/node_tests/hash_util.js+++ b/frontend_tests/node_tests/hash_util.js@@ -110,13 +110,20 @@ run_test("build_reload_url", () => {assert.equal(hash_util.build_reload_url(), "+oldhash=");});-run_test("test_active_stream", () => {+run_test("test is_editing_stream", () => {window.location.hash = "#streams/1/announce";- assert.equal(hash_util.active_stream().id, 1);- assert.equal(hash_util.active_stream().name, "announce");+ assert.equal(hash_util.is_editing_stream(1), true);+ assert.equal(hash_util.is_editing_stream(2), false);++ // url is missing name at end+ window.location.hash = "#streams/1";+ assert.equal(hash_util.is_editing_stream(1), false);++ window.location.hash = "#streams/bogus/bogus";+ assert.equal(hash_util.is_editing_stream(1), false);window.location.hash = "#test/narrow";- assert.equal(hash_util.active_stream(), undefined);+ assert.equal(hash_util.is_editing_stream(1), false);});run_test("test_is_create_new_stream_narrow", () => {diff --git a/static/js/hash_util.js b/static/js/hash_util.jsindex 01c6b6cab76..949818bf77a 100644--- a/static/js/hash_util.js+++ b/static/js/hash_util.js@@ -249,19 +249,22 @@ export function is_overlay_hash(hash) {// this finds the stream that is actively open in the settings and focused in// the left side.-export function active_stream() {+export function is_editing_stream(desired_stream_id) {const hash_components = window.location.hash.slice(1).split(/\//);+ if (hash_components[0] !== "streams") {+ return false;+ }++ if (!hash_components[2]) {+ return false;+ }+// if the string casted to a number is valid, and another component// after exists then it's a stream name/id pair.- if (typeof Number.parseFloat(hash_components[1]) === "number" && hash_components[2]) {- return {- id: Number.parseFloat(hash_components[1]),- name: hash_components[2],- };- }+ const stream_id = Number.parseFloat(hash_components[1]);- return undefined;+ return stream_id === desired_stream_id;}export function is_create_new_stream_narrow() {diff --git a/static/js/stream_edit.js b/static/js/stream_edit.jsindex a0a928d0166..621ff32ec3d 100644--- a/static/js/stream_edit.js+++ b/static/js/stream_edit.js@@ -54,11 +54,7 @@ export function is_sub_settings_active(sub) {// currently being viewed/edited in the stream edit UI. This is// used to determine whether we need to rerender the stream edit// UI when a sub object is modified by an event.- const active_stream = hash_util.active_stream();- if (active_stream !== undefined && active_stream.id === sub.stream_id) {- return true;- }- return false;+ return hash_util.is_editing_stream(sub.stream_id);}export function get_retention_policy_text_for_subscription_type(sub) {