Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
hash_util: Move encode_stream_id to shared.
Austin Riba9f1c184311be
diff --git a/frontend_tests/node_tests/internal_url.js b/frontend_tests/node_tests/internal_url.jsindex dd5f1871281..013c28493b0 100644--- a/frontend_tests/node_tests/internal_url.js+++ b/frontend_tests/node_tests/internal_url.js@@ -32,3 +32,9 @@ run_test("test stream_id_to_slug failed lookup", () => {const result = internal_url.stream_id_to_slug(123, maybe_get_stream_name);assert.equal(result, "123-unknown");});++run_test("test encode_stream_id", () => {+ const maybe_get_stream_name = () => "stream (with brackets)";+ const result = internal_url.encode_stream_id(123, maybe_get_stream_name);+ assert.equal(result, "123-stream-.28with-brackets.29");+});diff --git a/static/js/hash_util.js b/static/js/hash_util.jsindex 9573fc218cb..dd641e538b3 100644--- a/static/js/hash_util.js+++ b/static/js/hash_util.js@@ -51,14 +51,6 @@ export function encode_operand(operator, operand) {return internal_url.encodeHashComponent(operand);}-export function encode_stream_id(stream_id) {- // stream_data appends the stream name, but it does not do the- // URI encoding piece- const slug = internal_url.stream_id_to_slug(stream_id, stream_data.maybe_get_stream_name);-- return internal_url.encodeHashComponent(slug);-}-export function encode_stream_name(operand) {// stream_data prefixes the stream id, but it does not do the// URI encoding piece@@ -85,13 +77,16 @@ export function decode_operand(operator, operand) {}export function by_stream_uri(stream_id) {- return "#narrow/stream/" + encode_stream_id(stream_id);+ return (+ "#narrow/stream/" ++ internal_url.encode_stream_id(stream_id, stream_data.maybe_get_stream_name)+ );}export function by_stream_topic_uri(stream_id, topic) {return ("#narrow/stream/" +- encode_stream_id(stream_id) ++ internal_url.encode_stream_id(stream_id, stream_data.maybe_get_stream_name) +"/topic/" +internal_url.encodeHashComponent(topic));diff --git a/static/shared/js/internal_url.js b/static/shared/js/internal_url.jsindex 185cde03a57..e7a41929944 100644--- a/static/shared/js/internal_url.js+++ b/static/shared/js/internal_url.js@@ -30,3 +30,11 @@ export function stream_id_to_slug(stream_id, maybe_get_stream_name) {return stream_id + "-" + name;}++export function encode_stream_id(stream_id, maybe_get_stream_name) {+ // stream_id_to_slug appends the stream name, but it does not do the+ // URI encoding piece.+ const slug = stream_id_to_slug(stream_id, maybe_get_stream_name);++ return encodeHashComponent(slug);+}