Merge bug/messaging-stale-thread-on-account-switch
Fix: switching accounts no longer lands the new user on a stale chat thread inherited from the previous account (an empty self-thread where new messages never appeared). Clear _sub/_ov from history.state before the switch reload + guard partnerId===meId. User-confirmed on localdev with two real accounts.
This commit is contained in:
commit
16669dba5c
2 changed files with 11 additions and 1 deletions
|
|
@ -22,7 +22,9 @@ export default function Messages({ meId }: { meId: number }) {
|
||||||
// the module (open() pushes an entry; back() = history.back()).
|
// the module (open() pushes an entry; back() = history.back()).
|
||||||
const { view, open, back } = useHistorySubview<View>("list");
|
const { view, open, back } = useHistorySubview<View>("list");
|
||||||
|
|
||||||
if (typeof view === "object") {
|
// Guard against a stale sub-view whose partnerId is the current user's own id (you can't
|
||||||
|
// message yourself). This can be inherited across an account switch — fall back to the list.
|
||||||
|
if (typeof view === "object" && view.partnerId !== meId) {
|
||||||
return (
|
return (
|
||||||
<PageThread
|
<PageThread
|
||||||
meId={meId}
|
meId={meId}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,14 @@ export default function NavSidebar({
|
||||||
async function switchTo(id: number) {
|
async function switchTo(id: number) {
|
||||||
try {
|
try {
|
||||||
await api.switchAccount(id);
|
await api.switchAccount(id);
|
||||||
|
// Drop the previous account's in-module sub-view/overlay before the reload (which would
|
||||||
|
// otherwise preserve history.state across the swap). Otherwise the new account lands on a
|
||||||
|
// stale sub-view — e.g. an open chat thread whose partnerId belongs to the OLD identity
|
||||||
|
// (often the new account's own id → an empty self-thread). Start at the module root instead.
|
||||||
|
const st = { ...(window.history.state || {}) };
|
||||||
|
delete st._sub;
|
||||||
|
delete st._ov;
|
||||||
|
window.history.replaceState(st, "");
|
||||||
location.reload(); // cleanest way to reload all per-user state for the new account
|
location.reload(); // cleanest way to reload all per-user state for the new account
|
||||||
} catch {
|
} catch {
|
||||||
/* a revoked/removed account — leave the popover open */
|
/* a revoked/removed account — leave the popover open */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue