Files
discord-decomp/modules/multi_account/MultiAccountActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

182 lines
5.5 KiB
TypeScript

// Metro module 11512 (f11513).
import AuthenticationStore from "../../stores/AuthenticationStore";
import MultiAccountStore from "./MultiAccountStore";
import { Endpoints, AnalyticEvents } from "../../Constants";
import Logger from "../debug/Logger";
import { getToken } from "../../_bundle/setSecondaryToken";
import Dispatcher from "../../Dispatcher";
import { HTTP } from "../../_bundle/sendRequest";
import AnalyticsUtils from "../../utils/AnalyticsUtils";
import AuthenticationActionCreators from "../../actions/AuthenticationActionCreators";
let env7846 = {};
const c7846_9 = new Logger("MultiAccountActionCreators");
export function validateMultiAccountTokens() {
let env18915 = {
$parent: env7846
};
env18915[0] = AuthenticationStore.getId();
const users = MultiAccountStore.getUsers();
let c18916_0 = async (c30413_0) => {
let id, c30413_3, c30413_4;
let c30413_5 = 0;
let c31629_0, c31629_1, c31629_2, c31629_3, c31629_4, c31629_5, c31629_6;
const r17 = void 0;
L25: {
L21: {
try {
c30413_3 = r17;
c31629_0 = void 0;
c31629_0 = c30413_0.id;
c31629_1 = void 0;
c31629_2 = void 0;
c31629_3 = void 0;
c31629_4 = void 0;
c31629_5 = void 0;
await void 0;
c31629_1 = getToken(c31629_0);
if (c31629_1 != null) {
if (c31629_1 !== "") {
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_VALIDATE_TOKEN_REQUEST",
userId: c31629_0
});
c30413_5 = 1;
c31629_2 = await HTTP.get({
url: Endpoints.ME,
headers: {
authorization: c31629_1
},
retries: 3,
rejectWithError: false
});
c30413_5 = 0;
const id2 = c31629_2.body?.id;
id = id2;
if (id2 == null) {
id = null;
}
c31629_4 = id;
if (c31629_4 != null) {
if (c31629_4 !== c31629_0) {
c31629_5 = {
expected_user_id: c31629_0,
actual_user_id: c31629_4
};
c7846_9.log("Found per-user token authentication mismatch", c31629_5);
AnalyticsUtils.track(AnalyticEvents.MULTI_ACCOUNT_VALIDATE_TOKEN_USER_MISMATCH, c31629_5);
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_VALIDATE_TOKEN_FAILURE",
userId: c31629_0
});
break L21;
}
}
if (c30413_3.$parent[0] !== c31629_0) {
Dispatcher.dispatch({
type: "USER_UPDATE",
user: c31629_2.body
});
}
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_VALIDATE_TOKEN_SUCCESS",
userId: c31629_0
});
break L25;
}
}
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_VALIDATE_TOKEN_FAILURE",
userId: c31629_0
});
break L25;
} catch ($e) {
const r34 = $e;
let r7 = r34;
c30413_4 = r34;
if (c30413_5 !== 0) {
while (true) {
try {
const r199 = c30413_4;
c30413_5 = 0;
c31629_6 = r199;
c31629_3 = c31629_6?.status === 401 || c31629_6?.status === 403;
Dispatcher.dispatch({
type: c31629_3 ? "MULTI_ACCOUNT_VALIDATE_TOKEN_FAILURE" : "MULTI_ACCOUNT_VALIDATE_TOKEN_SUCCESS",
userId: c31629_0
});
} catch (r196) {
r7 = r196;
c30413_4 = r196;
if (c30413_5 === 0) {
break;
}
continue;
}
return void 0;
}
}
throw r7;
}
}
return void 0;
}
};
users.forEach(function() {
return c18916_0.apply(this, arguments);
});
}
export function switchAccount(a0, a1, a2) {
let r30;
c7846_9.log(`Switching account to ${a0}`, {
switchSynchronously: a1
});
const token = getToken(a0);
if (token == null) {
c7846_9.log("Switching accounts failed because there was no token");
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_VALIDATE_TOKEN_FAILURE",
userId: a0
});
r30 = Promise.resolve();
} else {
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_SWITCH_START",
targetUserId: a0,
location: a2 == null ? null : a2
});
r30 = AuthenticationActionCreators.switchAccountToken(token, a1);
}
return r30;
}
export function moveAccount(a0, a1) {
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_MOVE_ACCOUNT",
from: a0,
to: a1
});
}
export function removeAccount(a0) {
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_REMOVE_ACCOUNT",
userId: a0
});
}
export function updatePushSyncToken(a0, a1) {
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_UPDATE_PUSH_SYNC_TOKEN",
userId: a0,
pushSyncToken: a1
});
}
export function invalidatePushSyncTokens(a0) {
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_INVALIDATE_PUSH_SYNC_TOKENS",
invalidPushSyncTokens: a0
});
}
export function reportAccountSwitchTimeout() {
Dispatcher.dispatch({
type: "MULTI_ACCOUNT_SWITCH_TIMEOUT"
});
}