SHA256
Откат мультисессии: возвращен один активный сеанс
This commit is contained in:
@@ -3,7 +3,6 @@ import { listStoredMessages, putStoredMessage } from './services/message-store.j
|
||||
|
||||
const clone = (value) => JSON.parse(JSON.stringify(value));
|
||||
const SESSION_STORAGE_KEY = 'shine-ui-current-session-v1';
|
||||
const ACCOUNTS_STORAGE_KEY = 'shine-ui-accounts-v1';
|
||||
const REACTIONS_STORAGE_KEY = 'shine-ui-message-reactions-v2';
|
||||
const WEB_PUSH_SUBSCRIPTION_KEY = 'shine-ui-webpush-subscription-v1';
|
||||
const ENTRY_SETTINGS_STORAGE_KEY = 'shine-ui-entry-settings-v1';
|
||||
@@ -117,33 +116,6 @@ function loadStoredSession() {
|
||||
}
|
||||
}
|
||||
|
||||
function loadStoredAccounts() {
|
||||
try {
|
||||
const raw = localStorage.getItem(ACCOUNTS_STORAGE_KEY);
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw);
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
return parsed
|
||||
.map((item) => ({
|
||||
login: String(item?.login || '').trim(),
|
||||
sessionId: String(item?.sessionId || '').trim(),
|
||||
updatedAtMs: Number(item?.updatedAtMs || Date.now()),
|
||||
}))
|
||||
.filter((item) => item.login && item.sessionId);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function persistStoredAccounts(accounts) {
|
||||
try {
|
||||
const payload = Array.isArray(accounts) ? accounts : [];
|
||||
localStorage.setItem(ACCOUNTS_STORAGE_KEY, JSON.stringify(payload));
|
||||
} catch {
|
||||
// ignore storage errors
|
||||
}
|
||||
}
|
||||
|
||||
function loadStoredReactions() {
|
||||
try {
|
||||
const raw = localStorage.getItem(REACTIONS_STORAGE_KEY);
|
||||
@@ -216,7 +188,6 @@ function persistEntrySettings(settings) {
|
||||
function clearBrowserClientData() {
|
||||
const localKeys = [
|
||||
SESSION_STORAGE_KEY,
|
||||
ACCOUNTS_STORAGE_KEY,
|
||||
REACTIONS_STORAGE_KEY,
|
||||
WEB_PUSH_SUBSCRIPTION_KEY,
|
||||
CHANNEL_NOTIFY_KEY,
|
||||
@@ -239,7 +210,6 @@ function clearBrowserClientData() {
|
||||
|
||||
function createInitialState({ withStoredSession = true } = {}) {
|
||||
const storedSession = withStoredSession ? loadStoredSession() : null;
|
||||
const storedAccounts = loadStoredAccounts();
|
||||
const storedReactions = loadStoredReactions();
|
||||
const storedEntrySettings = loadStoredEntrySettings();
|
||||
const initialShineServer = LOCAL_WS_OVERRIDE_URL || DEFAULT_SHINE_SERVER;
|
||||
@@ -259,9 +229,6 @@ function createInitialState({ withStoredSession = true } = {}) {
|
||||
sessionId: storedSession?.sessionId || '',
|
||||
storagePwdInMemory: '',
|
||||
},
|
||||
accounts: storedAccounts,
|
||||
activeAccountLogin: String(storedSession?.login || ''),
|
||||
accountAddingMode: false,
|
||||
startHint: '',
|
||||
entrySettings: {
|
||||
language: String(storedEntrySettings?.language || 'ru'),
|
||||
@@ -731,19 +698,6 @@ export function authorizeSession({
|
||||
login,
|
||||
sessionId,
|
||||
});
|
||||
const loginKey = String(login || '').trim().toLowerCase();
|
||||
const nextAccounts = [
|
||||
{
|
||||
login: String(login || '').trim(),
|
||||
sessionId: String(sessionId || '').trim(),
|
||||
updatedAtMs: Date.now(),
|
||||
},
|
||||
...state.accounts.filter((item) => String(item?.login || '').trim().toLowerCase() !== loginKey),
|
||||
];
|
||||
state.accounts = nextAccounts;
|
||||
state.activeAccountLogin = String(login || '').trim();
|
||||
state.accountAddingMode = false;
|
||||
persistStoredAccounts(nextAccounts);
|
||||
state.startHint = '';
|
||||
if (onSessionAuthorized) {
|
||||
onSessionAuthorized();
|
||||
@@ -767,20 +721,6 @@ export async function refreshSessions() {
|
||||
return state.sessions;
|
||||
}
|
||||
|
||||
export async function switchToAccount(login) {
|
||||
const targetLogin = String(login || '').trim();
|
||||
if (!targetLogin) throw new Error('Не передан логин аккаунта.');
|
||||
const account = (state.accounts || []).find((item) => String(item?.login || '').trim().toLowerCase() === targetLogin.toLowerCase());
|
||||
if (!account?.sessionId) throw new Error('Сессия аккаунта не найдена.');
|
||||
const resumed = await authService.resumeSession(account.login, account.sessionId);
|
||||
authorizeSession({
|
||||
login: resumed.login || account.login,
|
||||
sessionId: resumed.sessionId || account.sessionId,
|
||||
storagePwd: resumed.storagePwd || state.session.storagePwdInMemory,
|
||||
});
|
||||
return resumed;
|
||||
}
|
||||
|
||||
function resetStateForSignedOut() {
|
||||
const next = createInitialState({ withStoredSession: false });
|
||||
state.chats = next.chats;
|
||||
@@ -792,9 +732,6 @@ function resetStateForSignedOut() {
|
||||
state.notificationsTab = next.notificationsTab;
|
||||
state.pageLabelCollapsed = next.pageLabelCollapsed;
|
||||
state.session = next.session;
|
||||
state.accounts = next.accounts;
|
||||
state.activeAccountLogin = next.activeAccountLogin;
|
||||
state.accountAddingMode = next.accountAddingMode;
|
||||
state.startHint = next.startHint;
|
||||
state.entrySettings = next.entrySettings;
|
||||
state.registrationDraft = next.registrationDraft;
|
||||
@@ -811,10 +748,6 @@ function resetStateForSignedOut() {
|
||||
}
|
||||
|
||||
export async function terminateCurrentSession({ infoMessage = '' } = {}) {
|
||||
const currentLogin = String(state.session.login || '').trim().toLowerCase();
|
||||
const nextAccounts = (state.accounts || []).filter((item) => String(item?.login || '').trim().toLowerCase() !== currentLogin);
|
||||
state.accounts = nextAccounts;
|
||||
persistStoredAccounts(nextAccounts);
|
||||
clearStoredSession();
|
||||
resetStateForSignedOut();
|
||||
authService.close();
|
||||
@@ -849,14 +782,6 @@ export async function closeCurrentSessionAndSignOut({ infoMessage = '' } = {}) {
|
||||
await terminateCurrentSession({ infoMessage });
|
||||
}
|
||||
|
||||
export function beginAddAccountFlow() {
|
||||
state.accountAddingMode = true;
|
||||
}
|
||||
|
||||
export function cancelAddAccountFlow() {
|
||||
state.accountAddingMode = false;
|
||||
}
|
||||
|
||||
export function refreshRegistrationBalance() {
|
||||
const next = (0.005 + Math.random() * 0.03).toFixed(4);
|
||||
state.registrationPayment.balanceSOL = next;
|
||||
|
||||
Reference in New Issue
Block a user