Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
reload: Use hash_util to get current hash encoded.
Aman Agrawalc6a934da4c8a
diff --git a/frontend_tests/node_tests/hash_util.js b/frontend_tests/node_tests/hash_util.jsindex 179b7dfc00e..1f59c3b54d9 100644--- a/frontend_tests/node_tests/hash_util.js+++ b/frontend_tests/node_tests/hash_util.js@@ -105,6 +105,20 @@ run_test("test_get_hash_section", () => {assert.deepEqual(hash_util.get_current_hash_section(), "your-account");});+run_test("build_reload_url", () => {+ location.hash = "#settings/your-account";+ assert.equal(hash_util.build_reload_url(), "+oldhash=settings%2Fyour-account");++ location.hash = "#test";+ assert.equal(hash_util.build_reload_url(), "+oldhash=test");++ location.hash = "#";+ assert.equal(hash_util.build_reload_url(), "+oldhash=");++ location.hash = "";+ assert.equal(hash_util.build_reload_url(), "+oldhash=");+});+run_test("test_parse_narrow", () => {assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend"]), [{negated: false, operator: "stream", operand: "frontend"},diff --git a/static/js/hash_util.js b/static/js/hash_util.jsindex ad40d9a8160..3ef0a1e660e 100644--- a/static/js/hash_util.js+++ b/static/js/hash_util.js@@ -45,6 +45,14 @@ export function encodeHashComponent(str) {return encodeURIComponent(str).replace(/[%().]/g, (matched) => hashReplacements.get(matched));}+export function build_reload_url() {+ let hash = window.location.hash;+ if (hash.length !== 0 && hash[0] === "#") {+ hash = hash.slice(1);+ }+ return "+oldhash=" + encodeURIComponent(hash);+}+export function encode_operand(operator, operand) {if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {const slug = people.emails_to_slug(operand);diff --git a/static/js/reload.js b/static/js/reload.jsindex 3b5908fdfeb..1848805cc12 100644--- a/static/js/reload.js+++ b/static/js/reload.js@@ -6,6 +6,7 @@ import * as compose from "./compose";import * as compose_actions from "./compose_actions";import * as compose_state from "./compose_state";import {csrf_token} from "./csrf";+import * as hash_util from "./hash_util";import * as hashchange from "./hashchange";import {localstorage} from "./localstorage";import * as message_list from "./message_list";@@ -78,11 +79,7 @@ function preserve_state(send_after_reload, save_pointer, save_narrow, save_compo}}- let oldhash = window.location.hash;- if (oldhash.length !== 0 && oldhash[0] === "#") {- oldhash = oldhash.slice(1);- }- url += "+oldhash=" + encodeURIComponent(oldhash);+ url += hash_util.build_reload_url();const ls = localstorage();// Delete all the previous preserved states.