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

160 lines
6.1 KiB
TypeScript

// Metro module 8648 (f8649).
import AuthenticationStore from "../../stores/AuthenticationStore";
import GuildStore from "../../stores/GuildStore";
import { InviteTargetTypes, InviteTypes } from "./Constants";
import { AbortCodes, AnalyticEvents, Endpoints, LoggingInviteTypes } from "../../Constants";
import { getInviteType } from "./InviteTypeUtils";
import { parseExtraDataFromInviteKey } from "./InviteCodeUtils";
import AnalyticsUtils from "../../utils/AnalyticsUtils";
import TrackedHTTPUtils from "../../utils/TrackedHTTPUtils";
import { NetworkActionNames } from "../../_bundle/Module503";
import { exact } from "../../_bundle/Module1385";
let c5625_11 = new Map();
export default function resolveInvite(a0, location2, a2) {
const code = a0;
const r21 = parseExtraDataFromInviteKey(a0);
const { baseCode, targetChannelId, targetMessageId, guildScheduledEventId } = r21;
AnalyticsUtils.track(AnalyticEvents.INVITE_OPENED, {
invite_code: baseCode,
invite_instance_id: a2?.inviteInstanceId
});
if (c5625_11.has(a0)) {
return c5625_11.get(a0);
}
const query = {
inputValue: a2?.inputValue,
with_counts: true,
with_expiration: true,
guild_scheduled_event_id: guildScheduledEventId,
target_channel_id: targetChannelId,
target_message_id: targetMessageId,
with_permissions: true,
with_games: !!a2?.withGames || void 0
};
const r57 = TrackedHTTPUtils.get({
url: Endpoints.INVITE(baseCode),
query,
oldFormErrors: true,
trackedActionData: {
event: NetworkActionNames.INVITE_RESOLVE,
properties: (a0) => {
const r9 = a0.ok ? a0.body : null;
const code2 = a0.body?.code;
const USER_BANNED = AbortCodes.USER_BANNED;
const guild_id = r9 == null ? void 0 : r9.guild?.id;
const r20 = {
resolved: a0.ok,
guild_id,
channel_id: r9 == null ? void 0 : r9.channel?.id,
channel_type: r9 == null ? void 0 : r9.channel?.type,
inviter_id: r9 == null ? void 0 : r9.inviter?.id,
code: baseCode,
input_value: a2?.inputValue,
location: location2,
authenticated: AuthenticationStore.isAuthenticated(),
size_total: r9?.approximate_member_count,
size_online: r9?.approximate_presence_count,
destination_user_id: r9 == null ? void 0 : r9.target_user?.id,
invite_type: null,
user_banned: null,
user_is_member: null
};
const r52 = r9 == null;
let invite_type = null;
if (!r52) {
if (r9.target_type === InviteTargetTypes.STREAM) {
invite_type = LoggingInviteTypes.STREAM;
} else if (r9.target_type === InviteTargetTypes.EMBEDDED_APPLICATION) {
invite_type = LoggingInviteTypes.APPLICATION;
} else {
const inviteType = getInviteType(r9);
invite_type = InviteTypes.FRIEND === inviteType ? LoggingInviteTypes.FRIEND_INVITE : InviteTypes.GROUP_DM === inviteType ? LoggingInviteTypes.GDM_INVITE : InviteTypes.GUILD === inviteType ? LoggingInviteTypes.SERVER_INVITE : String(inviteType);
}
}
const user_banned = code2 === USER_BANNED;
r20.invite_type = invite_type;
r20.user_banned = user_banned;
r20.user_is_member = GuildStore.getGuild(r9 == null ? void 0 : r9.guild?.id) != null;
return exact(r20);
}
},
rejectWithError: false
}).then(({ body }) => {
if (location2 != null) {
const INVITE_RESOLVED = AnalyticEvents.INVITE_RESOLVED;
const guild_id = body.guild != null ? body.guild.id : null;
const channel_id = body.channel != null ? body.channel.id : null;
const channel_type = body.channel != null ? body.channel.type : null;
const inviter_id = body.inviter ? body.inviter.id : null;
const r21 = {
resolved: true,
guild_id,
channel_id,
channel_type,
inviter_id,
code: baseCode,
input_value: a2?.inputValue,
location: location2,
authenticated: AuthenticationStore.isAuthenticated(),
size_total: body.approximate_member_count,
size_online: body.approximate_presence_count,
destination_user_id: body.target_user != null ? body.target_user.id : null,
invite_type: null,
user_is_member: null,
invite_instance_id: null
};
const r45 = body == null;
let invite_type = null;
if (!r45) {
if (body.target_type === InviteTargetTypes.STREAM) {
invite_type = LoggingInviteTypes.STREAM;
} else if (body.target_type === InviteTargetTypes.EMBEDDED_APPLICATION) {
invite_type = LoggingInviteTypes.APPLICATION;
} else {
const inviteType = getInviteType(body);
invite_type = InviteTypes.FRIEND === inviteType ? LoggingInviteTypes.FRIEND_INVITE : InviteTypes.GROUP_DM === inviteType ? LoggingInviteTypes.GDM_INVITE : InviteTypes.GUILD === inviteType ? LoggingInviteTypes.SERVER_INVITE : String(inviteType);
}
}
r21.invite_type = invite_type;
r21.user_is_member = GuildStore.getGuild(body == null ? void 0 : body.guild?.id) != null;
let invite_instance_id = a2?.inviteInstanceId;
if (invite_instance_id == null) {
invite_instance_id = null;
}
r21.invite_instance_id = invite_instance_id;
AnalyticsUtils.track(INVITE_RESOLVED, r21, {
flush: true
});
}
return {
invite: body,
code
};
}, (a0) => {
const user_banned = a0.body != null && a0.body.code === AbortCodes.USER_BANNED;
if (location2 != null) {
AnalyticsUtils.track(AnalyticEvents.INVITE_RESOLVED, {
resolved: false,
code: baseCode,
input_value: a2?.inputValue,
location: location2,
authenticated: AuthenticationStore.isAuthenticated(),
user_banned,
error_code: a0.body?.code,
error_message: a0.body?.message
}, {
flush: true
});
}
return {
invite: null,
code,
banned: user_banned
};
}).finally(() => {
c5625_11.delete(code);
});
c5625_11.set(a0, r57);
return r57;
};