Files
discord-decomp/modules/applications/installApplicationOnDemandIfNeeded.native.tsx
T
2026-11-01 12:12:55 +02:00

114 lines
3.5 KiB
TypeScript

// Metro module 11205 (f11206).
import ApplicationRecord from "../../records/ApplicationRecord";
import ApplicationStore from "./ApplicationStore";
import { AnalyticEvents } from "../../Constants";
import { shouldInstallApplicationOnDemand } from "./utils/ApplicationInstallUtils";
import { fetchApplication } from "./ApplicationActionCreators";
import { ApplicationIntegrationType } from "../../_bundle/Module8028";
import { trackWithMetadata } from "../app_analytics/AppAnalyticsUtils";
import { dismissKeyboard } from "../../utils/native/ChatInputUtils";
import { openOAuth2Modal } from "../../utils/native/ApplicationUtils";
function $mk116189($env) {
return (a0) => {
const r5 = $env;
let env31617 = {
$parent: $env
};
env31617[0] = a0;
dismissKeyboard();
openOAuth2Modal({
clientId: r5[0],
integrationType: r5[6],
scopes: r5[7],
callback: (a0) => {
if (a0.location != null) {
const r8 = env31617.$parent;
const r7 = r8[3];
if (r7 != null) {
const r12 = env31617.$parent.$parent;
(0, r12[0])(r12[1][7]).trackWithMetadata(r12[5].APP_LAUNCHER_OAUTH2_AUTHORIZE_SUCCEEDED, {
application_id: r8[0],
location: r7.location,
section_name: r7.sectionName,
source: r7.entrypoint
});
}
(0, env31617[0])({
isAuthorized: true
});
} else {
(0, env31617[0])({
isAuthorized: false
});
}
}
});
};
}
let env7585 = {};
export async function installApplicationOnDemandIfNeeded(c26970_0) {
let promise;
let c26970_1, c26970_2;
L21: {
let env30369;
const r29 = env7585;
c26970_2 = r29;
const r10 = env30369 = {
$parent: r29
};
c26970_1 = r10;
env30369[0] = void 0;
env30369[1] = void 0;
env30369[2] = void 0;
env30369[3] = void 0;
env30369[0] = c26970_0.applicationId;
env30369[1] = c26970_0.channel;
env30369[2] = c26970_0.commandIntegrationTypes;
env30369[3] = c26970_0.appLauncherContext;
env30369[4] = void 0;
env30369[5] = void 0;
env30369[6] = void 0;
env30369[7] = void 0;
await void 0;
if (shouldInstallApplicationOnDemand({
applicationId: env30369[0],
channel: env30369[1],
commandIntegrationTypes: env30369[2]
})) {
env30369[4] = ApplicationStore.getApplication(env30369[0]);
if (env30369[4] == null) {
env30369[5] = await fetchApplication(env30369[0]);
env30369[4] = ApplicationRecord.createFromServer(env30369[5]);
}
env30369[6] = ApplicationIntegrationType.USER_INSTALL;
const r91 = env30369[4];
const r93 = r91 == null;
let r94 = void 0;
if (!r93) {
const integrationTypesConfig = r91.integrationTypesConfig;
const r98 = integrationTypesConfig == null;
r94 = void 0;
if (!r98) {
const r101 = integrationTypesConfig[env30369[6]];
r94 = r101 == null ? void 0 : r101.oauth2InstallParams?.scopes;
}
}
env30369[7] = r94;
if (env30369[3] != null) {
trackWithMetadata(AnalyticEvents.APP_LAUNCHER_OAUTH2_AUTHORIZE_OPENED, {
application_id: env30369[0],
location: env30369[3].location,
section_name: env30369[3].sectionName,
source: env30369[3].entrypoint
});
}
promise = new Promise($mk116189(c26970_1));
break L21;
}
return Promise.resolve({
isAuthorized: true
});
}
return promise;
}