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;
break;
}
} else if (hasStoredSession(true)) {
} else if (hasStoredSession()) {
page = 'main';
activeKey = AppScreens.main;
} else if (hasPasscode) {

View File

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

View File

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

View File

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

View File

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

View File

@ -1,19 +1,12 @@
import * as idb from 'idb-keyval';
import type { ApiSessionData } from '../api/types';
import {
DEBUG, GLOBAL_STATE_CACHE_KEY, LEGACY_SESSION_KEY, SESSION_USER_KEY,
DEBUG, GLOBAL_STATE_CACHE_KEY, SESSION_USER_KEY,
} from '../config';
import * as cacheApi from './cacheApi';
const DC_IDS = [1, 2, 3, 4, 5];
export function hasStoredSession(withLegacy = false) {
if (withLegacy && localStorage.getItem(LEGACY_SESSION_KEY)) {
return true;
}
export function hasStoredSession() {
if (checkSessionLocked()) {
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() {
const sessionJson = process.env.TEST_SESSION!;
try {

View File

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