203 lines
6.8 KiB
TypeScript
203 lines
6.8 KiB
TypeScript
// Metro module 12772 (f12773).
|
|
import MultiAccountStore from "./MultiAccountStore";
|
|
import { AnalyticEvents } from "../../Constants";
|
|
import Logger from "../debug/Logger";
|
|
import { getLastFastConnectIdentifyUserId } from "../gateway/native/fast_connect";
|
|
import * as _setSecondaryToken from "../../_bundle/setSecondaryToken";
|
|
import { removeToken, getToken } from "../../_bundle/setSecondaryToken";
|
|
import AnalyticsUtils from "../../utils/AnalyticsUtils";
|
|
import Module589 from "../../_bundle/Module589";
|
|
import Dispatcher from "../../Dispatcher";
|
|
function $mk90387() {
|
|
return (a0) => a0.id;
|
|
}
|
|
let c8803_6 = new Logger("MultiAccountSwitchStore");
|
|
const id = null;
|
|
const id2 = null;
|
|
const targetUserId = null;
|
|
const location2 = null;
|
|
let c8803_11 = false;
|
|
let has_ever_connected = false;
|
|
let navigateHome = false;
|
|
let c8803_14 = null;
|
|
class MultiAccountSwitchStore extends Module589.Store {
|
|
static displayName = "MultiAccountSwitchStore";
|
|
initialize() {
|
|
this.waitFor(MultiAccountStore);
|
|
}
|
|
getIsSwitchingAccount() {
|
|
return c8803_11;
|
|
}
|
|
getSwitchResult() {
|
|
return c8803_14;
|
|
}
|
|
}
|
|
const multiAccountSwitchStore = new MultiAccountSwitchStore(Dispatcher, {
|
|
MULTI_ACCOUNT_SWITCH_START: function handleSwitchStart(a0) {
|
|
targetUserId = a0.targetUserId;
|
|
location2 = a0.location;
|
|
},
|
|
MULTI_ACCOUNT_SWITCH_TIMEOUT: function handleSwitchTimeout() {
|
|
AnalyticsUtils.track(AnalyticEvents.MULTI_ACCOUNT_SWITCH_TIMEOUT, {
|
|
from_user_id: id2,
|
|
to_user_id: targetUserId,
|
|
linked_user_ids: MultiAccountStore.getUsers().map((item) => item.id),
|
|
has_ever_connected,
|
|
switch_origin: location2
|
|
});
|
|
return false;
|
|
},
|
|
LOGOUT: function handleLogout(a0) {
|
|
c8803_11 = !!a0.isSwitchingAccount;
|
|
if (a0.isSwitchingAccount) {
|
|
id2 = id;
|
|
navigateHome = !!a0.goHomeAfterSwitching;
|
|
c8803_6.log("logout from account switch", {
|
|
current_user_id: id,
|
|
expected_user_id: targetUserId,
|
|
fast_connect_user_id: getLastFastConnectIdentifyUserId(),
|
|
switch_origin: location2
|
|
});
|
|
} else {
|
|
navigateHome = false;
|
|
removeToken(id);
|
|
}
|
|
},
|
|
CONNECTION_OPEN: function handleConnectionOpen({ user }) {
|
|
if (c8803_11) {
|
|
const id5 = user.id;
|
|
const r22 = c8803_11 && true;
|
|
L14: {
|
|
if (r22) {
|
|
const token2 = getToken(id5);
|
|
const token3 = getToken();
|
|
const is_user_mismatch = targetUserId != null && id5 !== targetUserId;
|
|
const is_token_mismatch = token2 != null && token3 != null && token2 !== token3;
|
|
if (!is_token_mismatch && !is_user_mismatch) {
|
|
break L14;
|
|
}
|
|
const r32 = {
|
|
...{
|
|
from_user_id: id2,
|
|
to_user_id: targetUserId,
|
|
actual_user_id: id5,
|
|
fast_connect_user_id: getLastFastConnectIdentifyUserId(),
|
|
linked_user_ids: MultiAccountStore.getUsers().map($mk90387()),
|
|
has_ever_connected,
|
|
switch_origin: location2
|
|
},
|
|
user_token_exists: token2 != null,
|
|
main_token_exists: token3 != null,
|
|
is_token_mismatch,
|
|
is_user_mismatch
|
|
};
|
|
c8803_6.log("Token mismatch on account switch connection open", r32);
|
|
AnalyticsUtils.track(AnalyticEvents.MULTI_ACCOUNT_SWITCH_READY_MISMATCH, r32);
|
|
}
|
|
}
|
|
const success = id2 !== user.id;
|
|
const r64 = {
|
|
from_user_id: id2,
|
|
to_user_id: targetUserId,
|
|
actual_user_id: user.id,
|
|
fast_connect_user_id: getLastFastConnectIdentifyUserId(),
|
|
linked_user_ids: MultiAccountStore.getUsers().map($mk90387()),
|
|
has_ever_connected,
|
|
switch_origin: location2
|
|
};
|
|
if (success) {
|
|
AnalyticsUtils.track(AnalyticEvents.MULTI_ACCOUNT_SWITCH_SUCCESS, r64);
|
|
if (c8803_11 && true) {
|
|
c8803_6.log("Account switch success", r64);
|
|
}
|
|
} else {
|
|
AnalyticsUtils.track(AnalyticEvents.MULTI_ACCOUNT_SWITCH_FAILURE, r64);
|
|
if (c8803_11 && true) {
|
|
c8803_6.log("Account switch failure", r64);
|
|
}
|
|
}
|
|
c8803_14 = {
|
|
success,
|
|
navigateHome
|
|
};
|
|
} else {
|
|
c8803_14 = null;
|
|
}
|
|
const token4 = getToken();
|
|
if (token4 != null && token4 !== "") {
|
|
const id3 = user.id;
|
|
const token = token4;
|
|
if (c8803_11 && true) {
|
|
const colliding_user_ids = MultiAccountStore.getUsers().map((item) => item.id).filter((item) => item !== id3 && getToken(item) === token);
|
|
if (colliding_user_ids.length !== 0) {
|
|
let is_already_corrupted = getToken(id3) === token;
|
|
const r131 = colliding_user_ids.length >= 2;
|
|
const r132 = {
|
|
...{
|
|
from_user_id: id2,
|
|
to_user_id: targetUserId,
|
|
actual_user_id: id3,
|
|
fast_connect_user_id: getLastFastConnectIdentifyUserId(),
|
|
linked_user_ids: MultiAccountStore.getUsers().map($mk90387()),
|
|
has_ever_connected,
|
|
switch_origin: location2
|
|
},
|
|
colliding_user_ids
|
|
};
|
|
if (!is_already_corrupted) {
|
|
is_already_corrupted = r131;
|
|
}
|
|
r132.is_already_corrupted = is_already_corrupted;
|
|
c8803_6.log("setToken about to introduce per-user token collision", r132);
|
|
AnalyticsUtils.track(AnalyticEvents.MULTI_ACCOUNT_SWITCH_TOKEN_COLLISION_WRITE, r132);
|
|
}
|
|
}
|
|
_setSecondaryToken.setToken(token, user.id);
|
|
}
|
|
let c20209_1;
|
|
const id4 = user.id;
|
|
c20209_1 = void 0;
|
|
if (c8803_11 && true) {
|
|
const map = new Map();
|
|
c20209_1 = map;
|
|
MultiAccountStore.getUsers().forEach(({ id: id5 }) => {
|
|
const token2 = getToken(id5);
|
|
if (token2 != null && token2 !== "") {
|
|
let r15 = c20209_1.get(token2);
|
|
if (r15 == null) {
|
|
r15 = [];
|
|
}
|
|
r15.push(id5);
|
|
c20209_1.set(token2, r15);
|
|
}
|
|
});
|
|
map.forEach((item) => {
|
|
if (!(item.length < 2)) {
|
|
const r6 = {
|
|
...{
|
|
from_user_id: id2,
|
|
to_user_id: targetUserId,
|
|
actual_user_id: id4,
|
|
fast_connect_user_id: getLastFastConnectIdentifyUserId(),
|
|
linked_user_ids: MultiAccountStore.getUsers().map($mk90387()),
|
|
has_ever_connected,
|
|
switch_origin: location2
|
|
},
|
|
colliding_user_ids: item
|
|
};
|
|
c8803_6.log("Per-user token collision detected", r6);
|
|
AnalyticsUtils.track(AnalyticEvents.MULTI_ACCOUNT_SWITCH_TOKEN_COLLISION, r6);
|
|
}
|
|
});
|
|
}
|
|
id2 = null;
|
|
targetUserId = null;
|
|
location2 = null;
|
|
c8803_11 = false;
|
|
navigateHome = false;
|
|
has_ever_connected = true;
|
|
id = user.id;
|
|
}
|
|
});
|
|
export default multiAccountSwitchStore;
|