Logout: Fix last chat opening after logging out (#2827)
This commit is contained in:
parent
5d1c4a8c87
commit
f7ff7bf598
@ -30,7 +30,7 @@ import { forceWebsync } from '../../../util/websync';
|
|||||||
import { addUsers, clearGlobalForLockScreen, updatePasscodeSettings } from '../../reducers';
|
import { addUsers, clearGlobalForLockScreen, updatePasscodeSettings } from '../../reducers';
|
||||||
import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode';
|
import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode';
|
||||||
import { serializeGlobal } from '../../cache';
|
import { serializeGlobal } from '../../cache';
|
||||||
import { parseInitialLocationHash } from '../../../util/routing';
|
import { parseInitialLocationHash, resetInitialLocationHash } from '../../../util/routing';
|
||||||
import type { ActionReturnType } from '../../types';
|
import type { ActionReturnType } from '../../types';
|
||||||
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
import { getCurrentTabId } from '../../../util/establishMultitabRole';
|
||||||
import { buildCollectionByKey } from '../../../util/iteratees';
|
import { buildCollectionByKey } from '../../../util/iteratees';
|
||||||
@ -157,6 +157,7 @@ addActionHandler('signOut', async (global, actions, payload): Promise<void> => {
|
|||||||
if ('leaveGroupCall' in actions) actions.leaveGroupCall({ tabId: getCurrentTabId() });
|
if ('leaveGroupCall' in actions) actions.leaveGroupCall({ tabId: getCurrentTabId() });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
resetInitialLocationHash();
|
||||||
await unsubscribe();
|
await unsubscribe();
|
||||||
await callApi('destroy');
|
await callApi('destroy');
|
||||||
await forceWebsync(false);
|
await forceWebsync(false);
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import { IS_IOS } from '../util/windowEnvironment';
|
|||||||
import useSyncEffect from './useSyncEffect';
|
import useSyncEffect from './useSyncEffect';
|
||||||
import useEffectOnce from './useEffectOnce';
|
import useEffectOnce from './useEffectOnce';
|
||||||
|
|
||||||
export const LOCATION_HASH = window.location.hash;
|
|
||||||
const PATH_BASE = `${window.location.pathname}${window.location.search}`;
|
const PATH_BASE = `${window.location.pathname}${window.location.search}`;
|
||||||
// Carefully selected by swiping and observing visual changes
|
// Carefully selected by swiping and observing visual changes
|
||||||
// TODO: may be different on other devices such as iPad, maybe take dpi into account?
|
// TODO: may be different on other devices such as iPad, maybe take dpi into account?
|
||||||
|
|||||||
@ -1,12 +1,24 @@
|
|||||||
import type { MessageListType } from '../global/types';
|
import type { MessageListType } from '../global/types';
|
||||||
import { MAIN_THREAD_ID } from '../api/types';
|
import { MAIN_THREAD_ID } from '../api/types';
|
||||||
import { LOCATION_HASH } from '../hooks/useHistoryBack';
|
|
||||||
import { IS_MOCKED_CLIENT } from '../config';
|
import { IS_MOCKED_CLIENT } from '../config';
|
||||||
|
|
||||||
let parsedInitialLocationHash: Record<string, string> | undefined;
|
let parsedInitialLocationHash: Record<string, string> | undefined;
|
||||||
let messageHash: string | undefined;
|
let messageHash: string | undefined;
|
||||||
let isAlreadyParsed = false;
|
let isAlreadyParsed = false;
|
||||||
|
|
||||||
|
let LOCATION_HASH: string | undefined = window.location.hash;
|
||||||
|
|
||||||
|
export function getInitialLocationHash() {
|
||||||
|
return LOCATION_HASH;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resetInitialLocationHash() {
|
||||||
|
LOCATION_HASH = undefined;
|
||||||
|
isAlreadyParsed = false;
|
||||||
|
messageHash = undefined;
|
||||||
|
parsedInitialLocationHash = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export const createLocationHash = (chatId: string, type: MessageListType, threadId: number): string => {
|
export const createLocationHash = (chatId: string, type: MessageListType, threadId: number): string => {
|
||||||
const displayType = type === 'thread' ? undefined : type;
|
const displayType = type === 'thread' ? undefined : type;
|
||||||
const parts = threadId === MAIN_THREAD_ID ? [chatId, displayType] : [chatId, threadId, displayType];
|
const parts = threadId === MAIN_THREAD_ID ? [chatId, displayType] : [chatId, threadId, displayType];
|
||||||
@ -55,21 +67,22 @@ export function parseInitialLocationHash() {
|
|||||||
|
|
||||||
if (isAlreadyParsed) return undefined;
|
if (isAlreadyParsed) return undefined;
|
||||||
|
|
||||||
if (!LOCATION_HASH) return undefined;
|
const locationHash = getInitialLocationHash();
|
||||||
|
if (!locationHash) return undefined;
|
||||||
|
|
||||||
let parsedHash = LOCATION_HASH ? LOCATION_HASH.replace(/^#/, '') : undefined;
|
let parsedHash = locationHash.replace(/^#/, '');
|
||||||
if (parsedHash?.includes('?')) {
|
if (parsedHash.includes('?')) {
|
||||||
[messageHash, parsedHash] = parsedHash.split('?');
|
[messageHash, parsedHash] = parsedHash.split('?');
|
||||||
if (!IS_MOCKED_CLIENT) {
|
if (!IS_MOCKED_CLIENT) {
|
||||||
window.location.hash = messageHash;
|
window.location.hash = messageHash;
|
||||||
}
|
}
|
||||||
} else if (parsedHash?.includes('=')) {
|
} else if (parsedHash.includes('=')) {
|
||||||
if (!IS_MOCKED_CLIENT) {
|
if (!IS_MOCKED_CLIENT) {
|
||||||
window.location.hash = '';
|
window.location.hash = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedInitialLocationHash = parsedHash?.includes('=') ? parsedHash?.split('&').reduce((acc, cur) => {
|
parsedInitialLocationHash = parsedHash.includes('=') ? parsedHash.split('&').reduce((acc, cur) => {
|
||||||
const [key, value] = cur.split('=');
|
const [key, value] = cur.split('=');
|
||||||
acc[key] = value;
|
acc[key] = value;
|
||||||
return acc;
|
return acc;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user