// Metro module 16767 (f16768). import { applicationReady } from "../../app_startup/native/NativeAppStartup"; import ExperimentStore from "../../experiments/ExperimentStore"; import { addPostConnectionCallback } from "../../gateway/PostConnectionCallbackStore"; import AuthenticationStore from "../../../stores/AuthenticationStore"; import ChannelStore from "../../../stores/ChannelStore"; import GuildStore from "../../../stores/GuildStore"; import Logger from "../../debug/Logger"; import Module4047 from "../../../_bundle/Module4047"; import * as _ComponentProfiler from "../../profiling/ComponentProfiler"; import Module16236 from "../../../_bundle/Module16236"; import Dispatcher from "../../../Dispatcher"; import ProcessUtils_native from "../../../utils/ProcessUtils.native"; import * as _ClientInfoUtils from "../../../utils/native/ClientInfoUtils"; import * as _AnalyticsUtils from "../../../utils/AnalyticsUtils"; import AuthenticationActionCreators from "../../../actions/AuthenticationActionCreators"; import InstantInviteActionCreators from "../../../actions/InstantInviteActionCreators"; import { transitionToChannel } from "../../routing/transitionToChannel"; import { writeCaches } from "../../cache/CacheActionCreators"; import { base64decode } from "../../../_bundle/Module1307"; import { HermesBuiltin } from "../../../_hermes/prelude"; function $mk100456($env) { return function handler(a0) { const r1 = $env; r1[0].unsubscribe(r1[1], r1[3]); return (0, r1[2])(a0); }; } function $mk117480($env) { return (a0, a1) => { let env31843 = { $parent: $env }; env31843[0] = a0; env31843[1] = a1; const r4 = $mk118588($env.$parent); for (const item of ["LOGIN_MFA_STEP", "LOGIN_SUSPENDED_USER", "LOGIN_ACCOUNT_SCHEDULED_FOR_DELETION", "LOGIN_ACCOUNT_DISABLED", "LOGIN_PHONE_IP_AUTHORIZATION_REQUIRED", "LOGIN_FAILURE"]) { r4(item, (a0) => { env31843[1](new Error(`Unable to login ${env31843.$parent[2]}. Login failed with event '${a0}'`)); }); } r4("LOGIN_SUCCESS", () => (0, env31843[0])()); }; } function $mk117481($env) { return (a0) => (0, addPostConnectionCallback)(a0); } function $mk117482($env) { return (a0) => (0, addPostConnectionCallback)(a0); } function $mk117484($env) { return (a0, a1) => { let env31844 = { $parent: $env }; env31844[0] = a0; env31844[1] = setTimeout(a1, 15000); GuildStore.addConditionalChangeListener(() => { const r1 = env31844.$parent.$parent; const r5 = r1[10]; const r2 = env31844.$parent; if (r5.getGuild(r2[0].invite.expectedGuildId) != null) { if (!r2[1]) { r1[11].log("Invited guild available in the store"); const r19 = JSON.stringify({ type: "status", message: "Invited guild available in the store" }); (0, r1[1])(r1[2][8]).logToDevice(r19); } clearTimeout(env31844[1]); (0, env31844[0])(); return false; } }); }; } function $mk117487($env) { return (a0) => (0, addPostConnectionCallback)(a0); } function $mk117488($env) { return (a0, a1) => { let env31845 = { $parent: $env }; env31845[0] = a0; env31845[1] = a1; const _loop = function _loop(a0) { let env32082; const r2 = env31845.$parent.$parent; const r8 = (0, r2[1])(r2[2][11]); const r5 = env32082 = {}; env32082[0] = r8; env32082[1] = a0; env32082[2] = () => { env31845[1](new Error(`Unable to login ${env31845.$parent[0]}. Login failed with action '${a0}'`)); }; const r11 = $mk100456(r5); env32082[3] = r11; r8.subscribe(a0, r11); }; for (const item of ["LOGIN_FAILURE", "PASSWORDLESS_FAILURE", "LOGIN_ACCOUNT_SCHEDULED_FOR_DELETION", "LOGIN_ACCOUNT_DISABLED", "LOGIN_PHONE_IP_AUTHORIZATION_REQUIRED"]) { _loop(item); } const r28 = $env; subscribeOnce2(Dispatcher, "LOGIN_SUCCESS", (a0) => (0, env31845[0])(a0.token)); AuthenticationActionCreators.login({ login: r28[0], password: r28[1] }); }; } function $mk117489($env) { return (a0) => (0, addPostConnectionCallback)(a0); } function $mk118588($env) { return function subscribeOnce(a0, a1) { let env32080 = { $parent: $env }; env32080[0] = a0; env32080[1] = a1; const handler2 = function handler() { const r2 = env32080[1]; const r4 = env32080[0]; r2(r4); const r6 = env32080.$parent; (0, r6[1])(r6[2][11]).unsubscribe(r4, env32080[2]); }; env32080[2] = handler2; Dispatcher.subscribe(a0, handler2); }; } let sendStatus, getErrorDetails, setupTTITest, apiLogin, subscribeOnce2, c12076_11, c12076_3, c12076_12; let c12077_0; let env12076 = {}; const sendReply = function sendReply(a0, a1, a2) { Module4047.logToDevice(JSON.stringify({ type: "response", status: a0, message: a1, ...a2 })); }; sendStatus = function sendStatus(a0) { c12076_11.log(a0); Module4047.logToDevice(JSON.stringify({ type: "status", message: a0 })); }; getErrorDetails = function getErrorDetails(a0) { let r21, set; if (a0 != null && typeof a0 === "object") { L8: { set = new Set(); let r25 = a0; if (a0 != null) { loop3: while (true) { let r27 = Object.getOwnPropertyNames(r25)[Symbol.iterator](); const next = r27.next; const r29 = r25; while (true) { const r10 = r27 === void 0 ? void 0 : (r21 = next.call(r27)).done ? r27 = void 0 : r21.value; if (r27 === void 0) { r25 = Object.getPrototypeOf(r29); if (r25 != null) { continue loop3; } break L8; } try { set.add(r10); } catch (r33) { if (r27 !== void 0 && typeof r27.return === "function") { try { r27.return(); } catch {} } throw r33; } } } } } const r36 = {}; for (const item of set) { r36[item] = a0[item]; } return r36; } return a0; }; setupTTITest = async function setupTTITest(c28528_0, c28528_1) { let c28528_2, c28528_3, c28528_4; let c28528_5 = 0; const r36 = env12076; L86: { try { let env31121; c28528_3 = r36; const r83 = env31121 = { $parent: r36 }; c28528_2 = r83; env31121[1] = void 0; env31121[0] = c28528_0; if (c28528_1 !== void 0) { env31121[1] = c28528_1; env31121[2] = void 0; env31121[3] = void 0; env31121[4] = void 0; env31121[5] = void 0; env31121[6] = void 0; env31121[7] = void 0; } else { env31121[1] = false; env31121[2] = void 0; env31121[3] = void 0; env31121[4] = void 0; env31121[5] = void 0; env31121[6] = void 0; env31121[7] = void 0; } await void 0; if (env31121[0].user != null) { env31121[2] = env31121[0].user.email; env31121[3] = env31121[0].user.password; env31121[4] = env31121[0].user.expectedId; c28528_5 = 1; const r156 = AuthenticationStore.getId() != null && AuthenticationStore.getId() !== env31121[4]; L22: { if (r156) { (0, sendStatus)("Logging out old user"); await AuthenticationActionCreators.logout("TTI_test"); if (AuthenticationStore.getId() === env31121[4]) { break L22; } } else if (AuthenticationStore.getId() === env31121[4]) { break L22; } const r178 = c28528_2; (0, sendStatus)("Logging in new user"); env31121[5] = new Promise($mk117480(r178)); await AuthenticationActionCreators.login({ login: env31121[2], password: env31121[3] }); await env31121[5]; (0, sendStatus)("Waiting for socket connection"); await new Promise($mk117481(env12076)); env31121[6] = AuthenticationStore.getId(); if (env31121[6] !== env31121[4]) { throw new Error(`Unable to login ${env31121[2]}, expected id ${env31121[4]} after login but was ${env31121[6]}`); } } c28528_5 = 0; } (0, sendStatus)("Waiting for socket connection"); await new Promise($mk117482(env12076)); await new Promise((resolve) => setTimeout(resolve, 1000)); const r505 = env31121[0].invite != null && GuildStore.getGuild(env31121[0].invite.expectedGuildId) == null; L60: { L61: { L58: { if (r505) { if (!env31121[1]) { (0, sendStatus)("Inviting to target guild"); } await InstantInviteActionCreators.acceptInvite({ inviteKey: env31121[0].invite.code, context: { location: "tti_tests" }, skipOnboarding: true }); if (!env31121[1]) { (0, sendStatus)("Invite API call finished"); } await new Promise($mk117484(c28528_2)); if (env31121[0].channelId != null) { break L58; } } else if (env31121[0].channelId != null) { break L58; } if (env31121[1]) { break L60; } break L61; } if (ChannelStore.getChannel(env31121[0].channelId) == null) { env31121[7] = new Error(`Unable to switch to channel ${env31121[0].channelId} because it does not exist on the client`); if (env31121[1]) { throw env31121[7]; } (0, sendReply)("error", env31121[7].message); break L86; } if (!env31121[1]) { (0, sendStatus)("Switching to desired channel"); } transitionToChannel(env31121[0].channelId); await new Promise((resolve) => setTimeout(resolve, 1000)); if (env31121[1]) { break L60; } } (0, sendStatus)("Writing caches"); } await writeCaches(); await new Promise((resolve) => setTimeout(resolve, 1000)); if (!env31121[1]) { (0, sendStatus)("Sending reply"); (0, sendReply)("success", "Setup Complete"); } } catch ($e) { const r81 = $e; let r8 = r81; c28528_4 = r81; if (c28528_5 !== 0) { while (true) { try { const r852 = c28528_4; c28528_5 = 0; env31121[8] = r852; if (env31121[1]) { throw r852; } (0, sendReply)("error", r852.message); } catch (r849) { r8 = r849; c28528_4 = r849; if (c28528_5 === 0) { break; } continue; } return void 0; } } throw r8; } return void 0; } }; apiLogin = async function apiLogin(c28529_0, c28529_1, c28529_2, c28529_3) { let r56, r105, r109, r147, r229, token; let c28529_4, c28529_5; L24: { L34: { L13: { L12: { let env31122; const r11 = env12076; c28529_5 = r11; const r45 = env31122 = { $parent: r11 }; c28529_4 = r45; env31122[0] = c28529_0; env31122[1] = c28529_1; env31122[2] = c28529_2; env31122[3] = c28529_3; env31122[4] = void 0; if (AuthenticationStore.getId() === c28529_3) { if (env31122[2] != null) { r56 = env31122[2]; break L13; } token = AuthenticationStore.getToken(); if (token != null) { break L12; } } L20: { L27: { if (AuthenticationStore.getId() != null) { await AuthenticationActionCreators.logout("TTI_test"); if (env31122[2] == null) { break L27; } if (!(await fetch("https://discord.com/api/users/@me/settings-proto/2", { method: "HEAD", headers: { Authorization: env31122[2] } })).ok) { break L27; } } else { if (env31122[2] == null) { env31122[2] = await new Promise($mk117488(c28529_4)); const r104 = Promise; r105 = Object.create(r104.prototype); r109 = new r104($mk117489(env12076)); break L20; } if (!(await fetch("https://discord.com/api/users/@me/settings-proto/2", { method: "HEAD", headers: { Authorization: env31122[2] } })).ok) { break L27; } } await AuthenticationActionCreators.loginToken(env31122[2], false); await new Promise($mk117487(env12076)); if (AuthenticationStore.getId() === env31122[3]) { r229 = env31122[2]; break L34; } } env31122[2] = await new Promise($mk117488(c28529_4)); const r246 = Promise; r105 = Object.create(r246.prototype); r109 = new r246($mk117489(env12076)); } await r109; env31122[4] = AuthenticationStore.getId(); if (env31122[4] !== env31122[3]) { throw new Error(`Unable to login ${env31122[0]}, expected id ${env31122[3]} after login but was ${env31122[4]}`); } r147 = env31122[2]; break L24; } return token; } return r56; } return r229; } return r147; }; subscribeOnce2 = function subscribeOnce(a0, a1, a2) { let env23408; const r4 = env23408 = {}; env23408[0] = a0; env23408[1] = "LOGIN_SUCCESS"; env23408[2] = a2; const subscribe = a0.subscribe; const r5 = $mk100456(r4); env23408[3] = r5; return subscribe.call(a0, "LOGIN_SUCCESS", r5); }; c12076_11 = new Logger("TTITestAction"); c12076_3 = async (c23409_0) => { let args, c23409_2, c23409_3, value, c23409_5, c23409_6, c23409_7, c23409_8, c23409_10; let c23409_9 = 0; const r17 = env12076; L15: { try { let env28530; c23409_8 = r17; const r24 = env28530 = {}; c23409_7 = r24; env28530[0] = void 0; env28530[1] = void 0; env28530[2] = void 0; env28530[0] = c23409_0.reply; const { source, args: args2 } = c23409_0; const r25 = { ClientInfoUtils: { getConstants: _ClientInfoUtils.getConstants }, ComponentProfiler: { resetComponentProfiler: _ComponentProfiler.resetComponentProfiler, resumeComponentProfiler: _ComponentProfiler.resumeComponentProfiler, pauseComponentProfiler: _ComponentProfiler.pauseComponentProfiler, dumpStats: _ComponentProfiler.dumpStats }, Dispatcher, ExperimentStore, NativeJankStats: Module16236, ProcessUtils: ProcessUtils_native, AnalyticsUtils: { startRecordingAnalyticsEvents: _AnalyticsUtils.startRecordingAnalyticsEvents, stopRecordingAnalyticsEvents: _AnalyticsUtils.stopRecordingAnalyticsEvents, getAnalyticsEventsRecording: _AnalyticsUtils.getAnalyticsEventsRecording, clearAnalyticsEventsRecording: _AnalyticsUtils.clearAnalyticsEventsRecording }, TTITestAction: { apiLogin, setupTTITest } }; const constructor = (async () => {}).constructor; const r93 = {}; env28530[1] = r93; args = args2; if (args2 == null) { args = {}; } const r97 = Object.keys(r25); const r100 = Object.values(r25); const r30 = Object.keys(args); const r105 = Object.values(args); c23409_9 = 2; c23409_2 = 0; const r106 = [, ,]; const r107 = HermesBuiltin.arraySpread(r106, r97, 0); c23409_2 = r107; r106[r107] = "imports"; const r109 = c23409_2 + 1; c23409_2 = r109; c23409_2 = HermesBuiltin.arraySpread(r106, r30, r109); r106[c23409_2] = String(source); c23409_2 = c23409_2 + 1; const r122 = constructor.apply(void 0, r106); c23409_5 = r93; c23409_3 = 0; const r123 = [,]; const r127 = HermesBuiltin.arraySpread(r123, r100, 0); c23409_3 = r127; r123[r127] = r97; const r129 = c23409_3 + 1; c23409_3 = r129; c23409_3 = HermesBuiltin.arraySpread(r123, r105, r129); value = await r122.apply(void 0, r123); c23409_5.result = value; c23409_9 = 1; c23409_9 = 0; if (typeof env28530[0] === "string") { env28530[2] = await fetch(env28530[0], { method: "PUT", body: JSON.stringify(env28530[1]), headers: { "Content-Type": "application/json" } }); if (env28530[2].ok) { (0, sendReply)("success", "Backchannel reply sent"); } else { (0, sendReply)("error", "Failed to send backchannel reply", { status: env28530[2].status }); } } } catch ($e) { const r45 = $e; let r7 = r45; c23409_10 = r45; let r46 = c23409_9; if (r46 !== 0) { while (true) { if (r46 === 1) { try { c23409_6 = c23409_10; c23409_9 = 0; if (typeof env28530[0] === "string") { env28530[2] = await fetch(env28530[0], { method: "PUT", body: JSON.stringify(env28530[1]), headers: { "Content-Type": "application/json" } }); if (env28530[2].ok) { (0, sendReply)("success", "Backchannel reply sent"); } else { (0, sendReply)("error", "Failed to send backchannel reply", { status: env28530[2].status }); } } throw c23409_6; } catch (r282) { r7 = r282; c23409_10 = r282; r46 = c23409_9; if (r46 === 0) { break; } } } else { try { const r221 = c23409_10; c23409_9 = 1; env28530[3] = r221; env28530[1].error = { details: (0, getErrorDetails)(r221), string: String(env28530[3]) }; c23409_9 = 0; if (typeof env28530[0] === "string") { env28530[2] = await fetch(env28530[0], { method: "PUT", body: JSON.stringify(env28530[1]), headers: { "Content-Type": "application/json" } }); if (env28530[2].ok) { (0, sendReply)("success", "Backchannel reply sent"); break L15; } (0, sendReply)("error", "Failed to send backchannel reply", { status: env28530[2].status }); break L15; } break L15; } catch (r218) { r7 = r218; c23409_10 = r218; r46 = c23409_9; if (r46 === 0) { break; } } } } } throw r7; } } }; c12076_12 = { "setup-test": setupTTITest, ping: () => { Module4047.logToDevice(JSON.stringify({ type: "pong" })); }, "reset-component-profiler": () => { _ComponentProfiler.resetComponentProfiler(); Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "reset-component-profiler", ...void 0 })); }, "pause-component-profiler": () => { _ComponentProfiler.pauseComponentProfiler(); Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "pause-component-profiler", ...void 0 })); }, "resume-component-profiler": () => { _ComponentProfiler.resumeComponentProfiler(); Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "resume-component-profiler", ...void 0 })); }, "dump-component-profiler-stats": () => { Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "dump-component-profiler-stats", ...{ stats: _ComponentProfiler.dumpStats() } })); }, "dump-jank-stats": () => { Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "dump-jank-stats", ...{ report: Module16236 == null ? void 0 : Module16236.requestReport() } })); }, "set-jank-multiplier": (a0) => { if (Module16236 != null) { Module16236.setJankHeuristicMultiplier(a0.multiplier); } Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "set-jank-multiplier", ...void 0 })); }, "start-jank-stats": () => { if (Module16236 != null) { Module16236.startTracking(); } Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "start-jank-stats", ...void 0 })); }, "flux-dispatch": (a0) => { Dispatcher.dispatch(a0.action); Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "flux-dispatch", ...void 0 })); }, "get-token": () => { Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "get-token", ...{ token: AuthenticationStore.getToken() } })); }, "get-resource-usage": () => { Module4047.logToDevice(JSON.stringify({ type: "response", status: "success", message: "get-resource-usage", ...{ cumulativeCPU: ProcessUtils_native.getCumulativeCPUUsage(), currentMemoryUsage: ProcessUtils_native.getCurrentMemoryUsageKB() } })); }, backchannel: function() { return c12076_3.apply(this, arguments); } }; c12077_0 = void 0; c12077_0 = async (c28531_0) => { let c28531_2; c28531_2 = void 0; const r41 = JSON.parse(new TextDecoder("utf-8").decode(base64decode(c28531_0.actionData))); let c31124_0 = r41; c12076_11.log("Received TTI Test Action", { ...r41, user: r41.user == null ? void 0 : "redacted" }); await applicationReady.promise; c12076_12[c31124_0.type](c31124_0); return Promise.resolve(); }; module.exports = function(a0) { const apply = c12077_0.apply; return c12077_0.apply(this, arguments); };