Files
discord-decomp/actions/GamesActionCreators.native.tsx
T
2026-11-01 12:12:55 +02:00

187 lines
6.6 KiB
TypeScript

// Metro module 10957 (f10958).
import { Endpoints, ActivityFlags, WebBrowserType, DiscordConnectDeeplinks } from "../Constants";
import { ActivityIntent } from "../modules/activities/Constants";
import * as _ConstantsIOS from "../ConstantsIOS";
import { DISCORD_CONNECT_EXAMPLE_APP_APPLICATION_ID } from "../ConstantsIOS";
import hasFlag from "../modules/activities/utils/hasFlag";
import Linking from "../lib/native/Linking";
import Dispatcher from "../Dispatcher";
import { HTTP } from "../_bundle/sendRequest";
import { canLaunchFrame } from "../modules/frames/utils/canLaunchFrame";
import FramesActionCreators_native from "../modules/frames/FramesActionCreators.native";
import handleJoinEmbeddedActivity from "../modules/activities/handleJoinEmbeddedActivity";
function $mk85963($env) {
return (a0) => (0, $env[0])(a0);
}
function $mk85964($env) {
return () => {
const r1 = $env.$parent;
(0, r1[1])(r1[2][6]).dispatch({
type: "ACTIVITY_JOIN_FAILED",
applicationId: $env[1]
});
return false;
};
}
let env7380 = {};
const fetchJoinSecret = function fetchJoinSecret(a0, a1) {
let env18393;
const r2 = env18393 = {
$parent: env7380
};
env18393[0] = a1;
const { userId, sessionId, application: application2, channelId: channelId2, messageId, remotePartyId } = a0;
const id = application2.id;
env18393[1] = id;
const query = channelId2 != null && messageId != null ? {
channel_id: channelId2,
message_id: messageId,
headless: true
} : void 0;
Dispatcher.dispatch({
type: "ACTIVITY_JOIN_LOADING",
applicationId: id,
remotePartyId
});
const r32 = HTTP.get({
url: Endpoints.USER_ACTIVITY_JOIN(userId, sessionId, id),
retries: 3,
query,
oldFormErrors: true,
rejectWithError: true
});
const r34 = $mk85964(r2);
return r32.then($mk85963(r2), r34);
};
const r25 = {
addGame: () => {},
toggleOverlay: () => {},
editName: () => {},
identifyGame: () => Promise.reject(new Error("not supported")),
getDetectableGames: () => {},
reportUnverifiedGame: () => {},
uploadIcon: () => {},
deleteEntry: () => {},
launch: () => Promise.resolve(),
join: async (c18394_0) => {
let r77;
let c26877_0, channelId;
L30: {
L28: {
const { application: application2, channelId: channelId2, embedded, source, locationObject = {}, analyticsLocations = [], remotePartyId } = c18394_0;
if (embedded) {
if (canLaunchFrame(application2)) {
await FramesActionCreators_native.launchFrame({
applicationId: application2.id
});
break L30;
}
channelId = channelId2;
if (channelId == null) {
channelId = void 0;
}
const r68 = await handleJoinEmbeddedActivity({
applicationId: application2.id,
activityChannelId: channelId,
source,
locationObject,
analyticsLocations
});
c26877_0 = r68;
if (r68 == null) {
c26877_0 = false;
}
r77 = c26877_0;
break L28;
}
return remotePartyId != null ? fetchJoinSecret(c18394_0, () => true) : (function joinViaDeeplink(a0) {
let r31;
let c31602_0 = a0;
const application = a0.application;
const DISCORD_CONNECT_EXAMPLE_APP_DEEPLINK_URI = application.id === DISCORD_CONNECT_EXAMPLE_APP_APPLICATION_ID ? _ConstantsIOS.DISCORD_CONNECT_EXAMPLE_APP_DEEPLINK_URI : application.deeplink_uri;
if (DISCORD_CONNECT_EXAMPLE_APP_DEEPLINK_URI == null && !hasFlag(a0.applicationActivity, ActivityFlags.SUPPORTS_JOIN_URL)) {
r31 = Promise.resolve(false);
} else {
let env31603;
const r32 = env31603 = {
$parent: env7380
};
env31603[0] = (a0) => {
let r43;
const join_url = a0.body.join_url;
const secret = a0.body.secret;
if (join_url != null) {
Linking.openURL(join_url, WebBrowserType.SAFARI);
let embedded2 = c31602_0.embedded;
if (embedded2 == null) {
embedded2 = false;
}
Dispatcher.dispatch({
type: "ACTIVITY_JOIN",
applicationId: application.id,
parentApplicationId: application.parent_id,
secret,
intent: ActivityIntent.PLAY,
embedded: embedded2
});
r43 = true;
} else if (DISCORD_CONNECT_EXAMPLE_APP_DEEPLINK_URI == null) {
Dispatcher.dispatch({
type: "ACTIVITY_JOIN_FAILED",
applicationId: application.id
});
r43 = false;
} else {
Linking.openURL(`${DISCORD_CONNECT_EXAMPLE_APP_DEEPLINK_URI.replace(/\/+$/, "")}${DiscordConnectDeeplinks.GAME_INVITE_FRAGMENT}${secret}`, WebBrowserType.SAFARI);
let embedded = c31602_0.embedded;
if (embedded == null) {
embedded = false;
}
Dispatcher.dispatch({
type: "ACTIVITY_JOIN",
applicationId: application.id,
parentApplicationId: application.parent_id,
secret,
intent: ActivityIntent.PLAY,
embedded
});
r43 = true;
}
return r43;
};
const { userId, sessionId, application: application2, channelId: channelId2, messageId, remotePartyId } = a0;
const id = application2.id;
env31603[1] = id;
const query = channelId2 != null && messageId != null ? {
channel_id: channelId2,
message_id: messageId,
headless: true
} : void 0;
Dispatcher.dispatch({
type: "ACTIVITY_JOIN_LOADING",
applicationId: id,
remotePartyId
});
const r53 = HTTP.get({
url: Endpoints.USER_ACTIVITY_JOIN(userId, sessionId, id),
retries: 3,
query,
oldFormErrors: true,
rejectWithError: true
});
const r55 = $mk85964(r32);
r31 = r53.then($mk85963(r32), r55);
}
return r31;
})(c18394_0);
}
return r77;
}
return 1;
},
joinWithSecret: function joinWithSecret(a0, a1) {
Linking.openURL(`${a0.replace(/\/+$/, "")}${DiscordConnectDeeplinks.GAME_INVITE_FRAGMENT}${a1}`, WebBrowserType.SAFARI);
}
};
export default r25;