mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 08:33:43 +00:00
reload: Use hash_util to get current hash encoded.
We do this change to limit the use of window in other modules, specifically window.location.hash.
This commit is contained in:
@@ -105,6 +105,20 @@ run_test("test_get_hash_section", () => {
|
|||||||
assert.deepEqual(hash_util.get_current_hash_section(), "your-account");
|
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", () => {
|
run_test("test_parse_narrow", () => {
|
||||||
assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend"]), [
|
assert.deepEqual(hash_util.parse_narrow(["narrow", "stream", "99-frontend"]), [
|
||||||
{negated: false, operator: "stream", operand: "frontend"},
|
{negated: false, operator: "stream", operand: "frontend"},
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ export function encodeHashComponent(str) {
|
|||||||
return encodeURIComponent(str).replace(/[%().]/g, (matched) => hashReplacements.get(matched));
|
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) {
|
export function encode_operand(operator, operand) {
|
||||||
if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
|
if (operator === "group-pm-with" || operator === "pm-with" || operator === "sender") {
|
||||||
const slug = people.emails_to_slug(operand);
|
const slug = people.emails_to_slug(operand);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import * as compose from "./compose";
|
|||||||
import * as compose_actions from "./compose_actions";
|
import * as compose_actions from "./compose_actions";
|
||||||
import * as compose_state from "./compose_state";
|
import * as compose_state from "./compose_state";
|
||||||
import {csrf_token} from "./csrf";
|
import {csrf_token} from "./csrf";
|
||||||
|
import * as hash_util from "./hash_util";
|
||||||
import * as hashchange from "./hashchange";
|
import * as hashchange from "./hashchange";
|
||||||
import {localstorage} from "./localstorage";
|
import {localstorage} from "./localstorage";
|
||||||
import * as message_list from "./message_list";
|
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;
|
url += hash_util.build_reload_url();
|
||||||
if (oldhash.length !== 0 && oldhash[0] === "#") {
|
|
||||||
oldhash = oldhash.slice(1);
|
|
||||||
}
|
|
||||||
url += "+oldhash=" + encodeURIComponent(oldhash);
|
|
||||||
|
|
||||||
const ls = localstorage();
|
const ls = localstorage();
|
||||||
// Delete all the previous preserved states.
|
// Delete all the previous preserved states.
|
||||||
|
|||||||
Reference in New Issue
Block a user