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

273 lines
7.7 KiB
TypeScript

// Metro module 5516 (f5517).
import ApplicationDirectoryApplicationsStore from "../global_discovery_apps/stores/ApplicationDirectoryApplicationsStore";
import ApplicationRecord from "../../records/ApplicationRecord";
import ApplicationStore from "./ApplicationStore";
import { QueryIds, Endpoints, NOOP } from "../../Constants";
import Dispatcher from "../../Dispatcher";
import { HTTP, rejectWithMigratedError } from "../../_bundle/sendRequest";
import { createFetchStore, useStateFromStores } from "../../_bundle/Module589";
function $mk114729($env) {
return (a0) => !$env[3].has(a0);
}
let c3389_11;
let env3389 = {};
export async function fetchApplication(c25484_0, c25484_1, c25484_2) {
let body;
let c25484_5;
let c25484_6 = 0;
let c29513_1, c29513_2, c29513_0, c29513_3, c29513_4;
try {
c29513_1 = void 0;
c29513_2 = void 0;
c29513_0 = c25484_0;
if (c25484_1 !== void 0) {
c29513_1 = c25484_1;
c29513_2 = c25484_2;
c29513_3 = void 0;
} else {
c29513_1 = false;
c29513_2 = c25484_2;
c29513_3 = void 0;
}
await void 0;
Dispatcher.dispatch({
type: "APPLICATION_FETCH",
applicationId: c29513_0
});
c25484_6 = 1;
c29513_3 = await HTTP.get({
url: Endpoints.APPLICATION_PUBLIC(c29513_0),
query: {
with_guild: c29513_1
},
oldFormErrors: true,
signal: c29513_2,
rejectWithError: rejectWithMigratedError()
});
Dispatcher.dispatch({
type: "APPLICATION_FETCH_SUCCESS",
application: c29513_3.body,
isHydrated: true
});
body = c29513_3.body;
c25484_6 = 0;
} catch ($e) {
const r31 = $e;
let r8 = r31;
c25484_5 = r31;
if (c25484_6 !== 0) {
while (true) {
try {
const r115 = c25484_5;
c25484_6 = 0;
c29513_4 = r115;
Dispatcher.dispatch({
type: "APPLICATION_FETCH_FAIL",
applicationId: c29513_0
});
throw c29513_4;
} catch (r111) {
r8 = r111;
c25484_5 = r111;
if (c25484_6 === 0) {
break;
}
}
}
}
throw r8;
}
return body;
}
const r28 = {
createApplication: async ({ name, guildId, type, teamId }) => {
let c25485_1;
c25485_1 = void 0;
let c29514_0 = (await HTTP.post({
url: Endpoints.APPLICATIONS,
body: {
name,
type,
guild_id: guildId,
team_id: teamId
},
rejectWithError: rejectWithMigratedError()
})).body;
if (guildId != null && type != null) {
Dispatcher.dispatch({
type: "APPLICATION_FETCH_SUCCESS",
application: c29514_0
});
}
return c29514_0;
},
getApplicationsForGuild: async function getApplicationsForGuild(c14892_0, r6 = {}) {
const { includeTeam, ...rest } = r6;
let c14892_2 = rest;
let c25486_1;
c25486_1 = void 0;
let c29515_0 = (await HTTP.get({
url: Endpoints.GUILD_APPLICATIONS(c14892_0),
query: {
...c14892_2,
include_team: includeTeam
},
rejectWithError: rejectWithMigratedError()
})).body;
Dispatcher.dispatch({
type: "APPLICATIONS_FETCH_SUCCESS",
applications: c29515_0
});
return c29515_0;
},
transferApplication: async ({ applicationId, teamId: teamId2 }) => {
let c25487_1;
c25487_1 = void 0;
let c29516_0 = (await HTTP.post({
url: Endpoints.APPLICATION_OWNER_TRANSFER(applicationId),
body: {
team_id: teamId2
},
rejectWithError: rejectWithMigratedError()
})).body;
Dispatcher.dispatch({
type: "APPLICATION_FETCH_SUCCESS",
application: c29516_0
});
return c29516_0;
},
fetchApplications: async function fetchApplications(c14894_0, r4 = true) {
let c14894_1 = r4;
let c25488_0, c25488_1, c25488_2;
let c25488_3 = 0;
const r16 = void 0;
const r15 = env3389;
L15: {
try {
let env29517;
c25488_1 = r16;
const r21 = env29517 = {
$parent: r15
};
c25488_0 = r21;
env29517[1] = void 0;
env29517[2] = void 0;
env29517[3] = void 0;
env29517[4] = void 0;
env29517[0] = c14894_0;
let applicationIds = c14894_0;
if (!c14894_1) {
const r40 = c14894_0.filter(function(item) {
const r9 = ApplicationStore.getApplication(item) != null && ApplicationStore.isHydrated(item);
return (r9 ? !r9 : !ApplicationStore.isFetchingApplication(item)) && !ApplicationStore.didFetchingApplicationFail(item) && item.length > 0;
});
env29517[0] = r40;
applicationIds = r40;
}
if (applicationIds.length > 0) {
Dispatcher.dispatch({
type: "APPLICATIONS_FETCH",
applicationIds
});
c25488_3 = 1;
const r74 = await HTTP.get({
url: Endpoints.APPLICATIONS_PUBLIC,
query: new URLSearchParams(applicationIds.map((applicationId) => ["application_ids", applicationId])).toString(),
oldFormErrors: true,
rejectWithError: rejectWithMigratedError()
});
const r87 = c25488_0;
env29517[1] = r74;
c25488_3 = 0;
env29517[2] = env29517[1].body;
env29517[3] = new Set(env29517[2].map((item) => item.id));
env29517[4] = env29517[0].filter($mk114729(r87));
Dispatcher.dispatch({
type: "APPLICATIONS_FETCH_SUCCESS",
applications: env29517[1].body,
unknownApplicationIds: env29517[4],
isHydrated: true
});
break L15;
}
} catch ($e) {
const r35 = $e;
let r12 = r35;
c25488_2 = r35;
if (c25488_3 !== 0) {
while (true) {
try {
const r122 = c25488_2;
c25488_3 = 0;
env29517[5] = r122;
if (env29517[5].status !== 429) {
Dispatcher.dispatch({
type: "APPLICATIONS_FETCH_FAIL",
applicationIds: env29517[0]
});
}
throw env29517[5];
} catch (r119) {
r12 = r119;
c25488_2 = r119;
if (c25488_3 === 0) {
break;
}
}
}
}
throw r12;
}
return void 0;
}
},
fetchApplication
};
const fetchStore = createFetchStore(ApplicationStore, {
getQueryId: QueryIds.APPLICATIONS,
get: (a0) => {
const r1 = a0 != null;
let r2 = null;
if (r1) {
const isHydrated = ApplicationStore.isHydrated(a0);
r2 = null;
if (isHydrated) {
let r9 = ApplicationStore.getApplication(a0);
if (r9 == null) {
r9 = null;
}
r2 = r9;
}
}
return r2;
},
load: (a0) => a0 != null ? fetchApplication(a0, false).then(NOOP) : Promise.resolve(),
getIsLoading: (a0) => a0 != null && ApplicationStore.isFetchingApplication(a0)
});
c3389_11 = fetchStore;
export default r28;
export { fetchStore as useApplication };
export function useApplicationWithLoggedOutContext(a0) {
const r12 = c3389_11(a0);
const { data, isLoading } = r12;
let error = r12.error;
const r20 = {
app: useStateFromStores([ApplicationDirectoryApplicationsStore], () => {
if (data == null) {
const application = ApplicationDirectoryApplicationsStore.getApplication(a0);
if (application != null) {
return ApplicationRecord.createFromServer(application);
}
}
return data;
}, [a0, data]),
isLoading,
error: null
};
if (error == null) {
error = void 0;
}
r20.error = error;
return r20;
}