Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

subs: Move active_stream function to hash_util.

Aman Agrawalb6f14c54e59a
diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.js
index 1f59c3b54d9..4f82dc47f87 100644
--- a/frontend_tests/node_tests/hash_util.js
+++ b/frontend_tests/node_tests/hash_util.js
@@ -119,6 +119,15 @@ run_test("build_reload_url", () => {
assert.equal(hash_util.build_reload_url(), "+oldhash=");
});
+run_test("test_active_stream", () => {
+ location.hash = "#streams/1/announce";
+ assert.equal(hash_util.active_stream().id, 1);
+ assert.equal(hash_util.active_stream().name, "announce");
+
+ location.hash = "#test/narrow";
+ assert.equal(hash_util.active_stream(), undefined);
+});
+
run_test("test_parse_narrow", () => {
assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend"]), [
{negated: false, operator: "stream", operand: "frontend"},
diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js
index 46e6097147d..a720f78a34b 100644
--- a/frontend_tests/node_tests/stream_edit.js
+++ b/frontend_tests/node_tests/stream_edit.js
@@ -21,6 +21,7 @@ mock_esm("../../static/js/browser_history", {update: noop});
mock_esm("../../static/js/hash_util", {
stream_edit_uri: noop,
by_stream_uri: noop,
+ active_stream: noop,
});
mock_esm("../../static/js/list_widget", {
create: () => ({init: noop}),
diff --git a/static/js/hash_util.js b/static/js/hash_util.js
index 3ef0a1e660e..d880eb9c207 100644
--- a/static/js/hash_util.js
+++ b/static/js/hash_util.js
@@ -249,3 +249,20 @@ export function is_overlay_hash(hash) {
return overlay_list.includes(main_hash);
}
+
+// this finds the stream that is actively open in the settings and focused in
+// the left side.
+export function active_stream() {
+ const hash_components = window.location.hash.slice(1).split(/\//);
+
+ // 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],
+ };
+ }
+
+ return undefined;
+}
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index e80c92aa01a..ba22ddc7ac9 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -78,7 +78,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 = subs.active_stream();
+ const active_stream = hash_util.active_stream();
if (active_stream !== undefined && active_stream.id === sub.stream_id) {
return true;
}
diff --git a/static/js/subs.js b/static/js/subs.js
index dd88563f91e..070b75e883b 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -145,23 +145,6 @@ function should_list_all_streams() {
return !page_params.realm_is_zephyr_mirror_realm;
}
-// this finds the stream that is actively open in the settings and focused in
-// the left side.
-export function active_stream() {
- const hash_components = window.location.hash.slice(1).split(/\//);
-
- // 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],
- };
- }
-
- return undefined;
-}
-
export function set_muted(sub, is_muted, status_element) {
stream_muting.update_is_muted(sub, is_muted);
stream_edit.set_stream_property(sub, "is_muted", sub.is_muted, status_element);