Logout: Fix last chat opening after logging out (#2827)

This commit is contained in:
Alexander Zinchuk 2023-03-19 22:31:49 -05:00
parent 5d1c4a8c87
commit f7ff7bf598
3 changed files with 21 additions and 8 deletions

View File

@ -30,7 +30,7 @@ import { forceWebsync } from '../../../util/websync';
import { addUsers, clearGlobalForLockScreen, updatePasscodeSettings } from '../../reducers';
import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode';
import { serializeGlobal } from '../../cache';
import { parseInitialLocationHash } from '../../../util/routing';
import { parseInitialLocationHash, resetInitialLocationHash } from '../../../util/routing';
import type { ActionReturnType } from '../../types';
import { getCurrentTabId } from '../../../util/establishMultitabRole';
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() });
try {
resetInitialLocationHash();
await unsubscribe();
await callApi('destroy');
await forceWebsync(false);

View File

@ -8,7 +8,6 @@ import { IS_IOS } from '../util/windowEnvironment';
import useSyncEffect from './useSyncEffect';
import useEffectOnce from './useEffectOnce';
export const LOCATION_HASH = window.location.hash;
const PATH_BASE = `${window.location.pathname}${window.location.search}`;
// Carefully selected by swiping and observing visual changes
// TODO: may be different on other devices such as iPad, maybe take dpi into account?

View File

@ -1,12 +1,24 @@
import type { MessageListType } from '../global/types';
import { MAIN_THREAD_ID } from '../api/types';
import { LOCATION_HASH } from '../hooks/useHistoryBack';
import { IS_MOCKED_CLIENT } from '../config';
let parsedInitialLocationHash: Record<string, string> | undefined;
let messageHash: string | undefined;
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 => {
const displayType = type === 'thread' ? undefined : type;
const parts = threadId === MAIN_THREAD_ID ? [chatId, displayType] : [chatId, threadId, displayType];
@ -55,21 +67,22 @@ export function parseInitialLocationHash() {
if (isAlreadyParsed) return undefined;
if (!LOCATION_HASH) return undefined;
const locationHash = getInitialLocationHash();
if (!locationHash) return undefined;
let parsedHash = LOCATION_HASH ? LOCATION_HASH.replace(/^#/, '') : undefined;
if (parsedHash?.includes('?')) {
let parsedHash = locationHash.replace(/^#/, '');
if (parsedHash.includes('?')) {
[messageHash, parsedHash] = parsedHash.split('?');
if (!IS_MOCKED_CLIENT) {
window.location.hash = messageHash;
}
} else if (parsedHash?.includes('=')) {
} else if (parsedHash.includes('=')) {
if (!IS_MOCKED_CLIENT) {
window.location.hash = '';
}
}
parsedInitialLocationHash = parsedHash?.includes('=') ? parsedHash?.split('&').reduce((acc, cur) => {
parsedInitialLocationHash = parsedHash.includes('=') ? parsedHash.split('&').reduce((acc, cur) => {
const [key, value] = cur.split('=');
acc[key] = value;
return acc;