Remove legacy sessions support (#4369)

This commit is contained in:
Alexander Zinchuk 2024-03-22 13:05:57 +01:00
parent 7a32075b37
commit c23752a28e
7 changed files with 7 additions and 62 deletions

View File

@ -136,7 +136,7 @@ const App: FC<StateProps> = ({
activeKey = AppScreens.main; activeKey = AppScreens.main;
break; break;
} }
} else if (hasStoredSession(true)) { } else if (hasStoredSession()) {
page = 'main'; page = 'main';
activeKey = AppScreens.main; activeKey = AppScreens.main;
} else if (hasPasscode) { } else if (hasPasscode) {

View File

@ -33,7 +33,6 @@ export const INACTIVE_MARKER = '[Inactive]';
export const DEBUG_PAYMENT_SMART_GLOCAL = false; export const DEBUG_PAYMENT_SMART_GLOCAL = false;
export const SESSION_USER_KEY = 'user_auth'; export const SESSION_USER_KEY = 'user_auth';
export const LEGACY_SESSION_KEY = 'GramJs:sessionId';
export const PASSCODE_CACHE_NAME = 'tt-passcode'; export const PASSCODE_CACHE_NAME = 'tt-passcode';
export const GLOBAL_STATE_CACHE_DISABLED = false; export const GLOBAL_STATE_CACHE_DISABLED = false;

View File

@ -3,7 +3,6 @@ import { ManagementProgress } from '../../../types';
import { import {
CUSTOM_BG_CACHE_NAME, CUSTOM_BG_CACHE_NAME,
IS_TEST,
LANG_CACHE_NAME, LANG_CACHE_NAME,
LOCK_SCREEN_ANIMATION_DURATION_MS, LOCK_SCREEN_ANIMATION_DURATION_MS,
MEDIA_CACHE_NAME, MEDIA_CACHE_NAME,
@ -18,9 +17,7 @@ import { unsubscribe } from '../../../util/notifications';
import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode'; import { clearEncryptedSession, encryptSession, forgetPasscode } from '../../../util/passcode';
import { parseInitialLocationHash, resetInitialLocationHash, resetLocationHash } from '../../../util/routing'; import { parseInitialLocationHash, resetInitialLocationHash, resetLocationHash } from '../../../util/routing';
import { import {
clearLegacySessions,
clearStoredSession, clearStoredSession,
importLegacySession,
loadStoredSession, loadStoredSession,
storeSession, storeSession,
} from '../../../util/sessions'; } from '../../../util/sessions';
@ -39,12 +36,7 @@ import {
addUsers, clearGlobalForLockScreen, updateManagementProgress, updatePasscodeSettings, addUsers, clearGlobalForLockScreen, updateManagementProgress, updatePasscodeSettings,
} from '../../reducers'; } from '../../reducers';
addActionHandler('initApi', async (global, actions): Promise<void> => { addActionHandler('initApi', (global, actions): ActionReturnType => {
if (!IS_TEST) {
await importLegacySession();
void clearLegacySessions();
}
const initialLocationHash = parseInitialLocationHash(); const initialLocationHash = parseInitialLocationHash();
void initApi(actions.apiUpdate, { void initApi(actions.apiUpdate, {
@ -208,8 +200,6 @@ addActionHandler('reset', (global, actions): ActionReturnType => {
void cacheApi.clear(`${langCachePrefix}${i === 0 ? '' : i}`); void cacheApi.clear(`${langCachePrefix}${i === 0 ? '' : i}`);
} }
void clearLegacySessions();
updateAppBadge(0); updateAppBadge(0);
actions.initShared({ force: true }); actions.initShared({ force: true });

View File

@ -64,7 +64,7 @@ addActionHandler('switchMultitabRole', async (global, actions, payload): Promise
storeSession(session, session.userId); storeSession(session, session.userId);
} }
if (hasStoredSession(true)) { if (hasStoredSession()) {
setupCaching(); setupCaching();
} }

View File

@ -86,7 +86,7 @@ export function loadCache(initialState: GlobalState): GlobalState | undefined {
const cache = readCache(initialState); const cache = readCache(initialState);
if (cache.passcode.hasPasscode || hasStoredSession(true)) { if (cache.passcode.hasPasscode || hasStoredSession()) {
setupCaching(); setupCaching();
return cache; return cache;

View File

@ -1,19 +1,12 @@
import * as idb from 'idb-keyval';
import type { ApiSessionData } from '../api/types'; import type { ApiSessionData } from '../api/types';
import { import {
DEBUG, GLOBAL_STATE_CACHE_KEY, LEGACY_SESSION_KEY, SESSION_USER_KEY, DEBUG, GLOBAL_STATE_CACHE_KEY, SESSION_USER_KEY,
} from '../config'; } from '../config';
import * as cacheApi from './cacheApi';
const DC_IDS = [1, 2, 3, 4, 5]; const DC_IDS = [1, 2, 3, 4, 5];
export function hasStoredSession(withLegacy = false) { export function hasStoredSession() {
if (withLegacy && localStorage.getItem(LEGACY_SESSION_KEY)) {
return true;
}
if (checkSessionLocked()) { if (checkSessionLocked()) {
return true; return true;
} }
@ -102,43 +95,6 @@ export function loadStoredSession(): ApiSessionData | undefined {
}; };
} }
export async function importLegacySession() {
const sessionId = localStorage.getItem(LEGACY_SESSION_KEY);
if (!sessionId) return;
const sessionJson = await idb.get(`GramJs:${sessionId}`);
try {
const sessionData = JSON.parse(sessionJson) as ApiSessionData;
storeSession(sessionData);
} catch (err) {
if (DEBUG) {
// eslint-disable-next-line no-console
console.warn('Failed to load legacy session', err);
}
}
}
// Remove previously created IndexedDB and cache API sessions
export async function clearLegacySessions() {
try {
localStorage.removeItem(LEGACY_SESSION_KEY);
const idbKeys = await idb.keys();
await Promise.all<Promise<any>>([
cacheApi.clear('GramJs'),
...idbKeys
.filter((k) => typeof k === 'string' && k.startsWith('GramJs:GramJs-session-'))
.map((k) => idb.del(k)),
]);
} catch (err) {
if (DEBUG) {
// eslint-disable-next-line no-console
console.warn('Failed to clear legacy session', err);
}
}
}
export function importTestSession() { export function importTestSession() {
const sessionJson = process.env.TEST_SESSION!; const sessionJson = process.env.TEST_SESSION!;
try { try {

View File

@ -92,7 +92,7 @@ export function startWebsync() {
lastTimeout = setTimeout(() => { lastTimeout = setTimeout(() => {
const { authState } = getGlobal(); const { authState } = getGlobal();
const authed = authState === 'authorizationStateReady' || hasStoredSession(true); const authed = authState === 'authorizationStateReady' || hasStoredSession();
forceWebsync(authed); forceWebsync(authed);
}, Math.max(0, timeout * 1000)); }, Math.max(0, timeout * 1000));
} }