From 570306fa69a991ded5e2e03aa44e8a189a0fd85c Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Mon, 15 Mar 2021 08:25:22 +0000 Subject: [PATCH] subs: Use hash_util to get stream id. Active stream's hash look like this - `#streams/1/announce` Since the stream_id is present where typically hash section is for all other hashes, get_current_hash_section should return the same result. --- frontend_tests/node_tests/subs.js | 6 +++--- static/js/subs.js | 10 +--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/frontend_tests/node_tests/subs.js b/frontend_tests/node_tests/subs.js index cfdeaf4eb4..4c62122f12 100644 --- a/frontend_tests/node_tests/subs.js +++ b/frontend_tests/node_tests/subs.js @@ -15,13 +15,13 @@ const ui = mock_esm("../../static/js/ui", { get_scroll_element: (element) => element, }); -set_global("location", { - hash: `#streams/${denmark_stream_id}/announce`, -}); mock_esm("../../static/js/hash_util", { by_stream_uri: () => {}, + get_current_hash_section: () => denmark_stream_id, }); +set_global("page_params", {}); + const stream_data = zrequire("stream_data"); const subs = zrequire("subs"); diff --git a/static/js/subs.js b/static/js/subs.js index 23bdb7d9ac..f0faa98077 100644 --- a/static/js/subs.js +++ b/static/js/subs.js @@ -116,14 +116,6 @@ export function get_active_data() { }; } -function get_hash_safe() { - if (typeof window.location.hash === "string") { - return window.location.hash.slice(1); - } - - return ""; -} - function selectText(element) { let range; let sel; @@ -316,7 +308,7 @@ export function update_settings_for_subscribed(sub) { } export function show_active_stream_in_left_panel() { - const selected_row = get_hash_safe().split(/\//)[1]; + const selected_row = hash_util.get_current_hash_section(); if (Number.parseFloat(selected_row)) { const sub_row = row_for_stream_id(selected_row);