Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
narrow: Update hash for moved message even if hash change in progress.
Lauryn Menardd5126528095d
diff --git a/web/src/narrow.js b/web/src/narrow.jsindex 3fc457959a1..a8d52a9b9e8 100644--- a/web/src/narrow.js+++ b/web/src/narrow.js@@ -74,20 +74,25 @@ export function reset_ui_state() {compose_banner.clear_message_sent_banners();}-export function changehash(newhash) {+export function changehash(newhash, trigger) {if (browser_history.state.changing_hash) {+ // If we retargeted the narrow operation because a message was moved,+ // we want to have the current narrow hash in the browser history.+ if (trigger === "retarget message location") {+ window.location.replace(newhash);+ }return;}message_viewport.stop_auto_scrolling();browser_history.set_hash(newhash);}-export function save_narrow(terms) {- if (browser_history.state.changing_hash) {+export function save_narrow(terms, trigger) {+ if (browser_history.state.changing_hash && trigger !== "retarget message location") {return;}const new_hash = hash_util.search_terms_to_hash(terms);- changehash(new_hash);+ changehash(new_hash, trigger);}export function activate(raw_terms, opts) {@@ -282,6 +287,7 @@ export function activate(raw_terms, opts) {...opts,// Update the URL fragment to reflect the redirect.change_hash: true,+ trigger: "retarget message location",});return;}@@ -314,6 +320,7 @@ export function activate(raw_terms, opts) {...opts,// Update the URL fragment to reflect the redirect.change_hash: true,+ trigger: "retarget message location",});return;}@@ -587,9 +594,10 @@ export function activate(raw_terms, opts) {// Put the narrow terms in the URL fragment.// Disabled when the URL fragment was the source- // of this narrow.+ // of this narrow, but not if the fragment had+ // a target message ID that has been moved.if (opts.change_hash) {- save_narrow(terms);+ save_narrow(terms, opts.trigger);}handle_post_view_change(msg_list);diff --git a/web/src/reload_setup.js b/web/src/reload_setup.jsindex e116ffced0e..ac05148183c 100644--- a/web/src/reload_setup.js+++ b/web/src/reload_setup.js@@ -15,6 +15,7 @@ export function initialize() {return;}const hash_fragment = location.hash.slice("#".length);+ const trigger = "reload";// Using the token, recover the saved pre-reload data from local// storage. Afterwards, we clear the reload entry from local@@ -27,7 +28,7 @@ export function initialize() {// exist, but be log it so that it's available for future// debugging if an exception happens later.blueslip.info("Invalid hash change reload token");- narrow.changehash("");+ narrow.changehash("", trigger);return;}ls.remove(hash_fragment);@@ -82,5 +83,5 @@ export function initialize() {});activity.set_new_user_input(false);- narrow.changehash(vars.oldhash);+ narrow.changehash(vars.oldhash, trigger);}