Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

narrow: Update hash for moved message even if hash change in progress. #29864

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions web/src/narrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
timabbott marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions web/src/reload_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -82,5 +83,5 @@ export function initialize() {
});

activity.set_new_user_input(false);
narrow.changehash(vars.oldhash);
narrow.changehash(vars.oldhash, trigger);
}