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

146 lines
5.0 KiB
TypeScript

// Metro module 12208 (f12209).
import { useMemo } from "react";
import GuildChannelStore from "../../../stores/GuildChannelStore";
import GuildMemberCountStore from "../../../stores/GuildMemberCountStore";
import GuildMemberStore from "../../../stores/GuildMemberStore";
import GuildStore from "../../../stores/GuildStore";
import PermissionStore from "../../../stores/PermissionStore";
import SortedGuildStore from "../../../stores/SortedGuildStore";
import UserStore from "../../../stores/UserStore";
import { setSendState } from "../GuildInviteSendStateStore";
import { InviteSendStates } from "../Constants";
import { AnalyticEvents, Permissions } from "../../../Constants";
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
import ActionSheetActionCreators from "../../action_sheet/native/ActionSheetActionCreators";
import fuzzysearch from "../../../_bundle/fuzzysearch";
import { useStateFromStoresArray } from "../../../_bundle/Module589";
import { AccessibilityAnnouncer } from "../../../_bundle/Module3902";
import { intl, t } from "../../../intl/index.native";
import InstantInviteActionCreators from "../../../actions/InstantInviteActionCreators";
import InstantInviteUtils from "../../../utils/InstantInviteUtils";
import InviteQueue, { InvitePropertiesType } from "../../../lib/InviteQueue";
function $mk116384($env) {
return () => {
const r2 = $env;
(0, setSendState)(r2[0], r2[1], InviteSendStates.SENT);
AccessibilityAnnouncer.announce(intl.string(t.PuLLzP));
};
}
let env8437 = {};
export function showGuildInviteActionSheet(a0, a1) {
AnalyticsUtils.track(AnalyticEvents.OPEN_POPOUT, {
type: "Invite to Guilds",
source: a1
});
ActionSheetActionCreators.openLazy(import("./action_sheet/invite_to_guilds/GuildInviteActionSheet"), `invite-to-guilds-${a0}`, {
recipientId: a0,
source: a1
});
}
export function useServerInviteRows(a0, a1) {
const stateFromStoresArray = useStateFromStoresArray([SortedGuildStore, GuildStore], () => {
const flattenedGuildIds = SortedGuildStore.getFlattenedGuildIds();
const r5 = [];
let c27273_0 = r5;
flattenedGuildIds.forEach((flattenedGuildId) => {
const guild = GuildStore.getGuild(flattenedGuildId);
if (guild != null) {
c27273_0.push(guild);
}
});
return r5;
});
return useMemo(() => {
if (a0 == null) {
return [[], []];
}
const memberCounts = GuildMemberCountStore.getMemberCounts();
const r9 = [];
let c27274_1 = r9;
const r10 = [];
let c27274_2 = r10;
stateFromStoresArray.forEach((item) => {
if (PermissionStore.can(Permissions.CREATE_INSTANT_INVITE, item) || item.vanityURLCode != null) {
const name = item.name;
if ((a1 == null || fuzzysearch(a1.toLowerCase(), name.toLowerCase())) && !GuildMemberStore.isMember(item.id, a0)) {
let memberCount = memberCounts[item.id];
if (memberCount == null) {
memberCount = 0;
}
const r30 = {
guild: item,
memberCount
};
if (item.ownerId === UserStore.getCurrentUser()?.id) {
c27274_1.push(r30);
} else {
c27274_2.push(r30);
}
}
}
});
return [r9, r10];
}, [stateFromStoresArray, a1, a0]);
}
export async function sendGuildInvite(c27272_0, c27272_1, c27272_2) {
let c27272_3, c27272_4;
let c27272_5 = 0;
const r12 = env8437;
L12: {
try {
let env30511;
c27272_4 = r12;
const r32 = env30511 = {
$parent: r12
};
c27272_3 = r32;
env30511[0] = c27272_0;
env30511[1] = c27272_1;
env30511[2] = c27272_2;
env30511[3] = void 0;
c27272_5 = 1;
(0, setSendState)(c27272_0, c27272_1, InviteSendStates.SENDING);
AccessibilityAnnouncer.announce(intl.string(t.kC3ZRG));
const defaultChannel = GuildChannelStore.getDefaultChannel(c27272_1, true, Permissions.CREATE_INSTANT_INVITE);
if (defaultChannel == null) {
throw Error();
}
const invite = await InstantInviteActionCreators.createInvite(defaultChannel.id, {
max_uses: InstantInviteUtils.INVITE_OPTIONS_ONCE.value,
max_age: InstantInviteUtils.INVITE_OPTIONS_7_DAYS.value,
unique: true
}, c27272_2);
const r99 = c27272_3;
env30511[3] = invite;
InviteQueue.enqueue({
inviteKey: env30511[3].code,
type: InvitePropertiesType.USER,
user: UserStore.getUser(env30511[0]),
location: env30511[2],
inviteAnalyticsMetadata: {
source: env30511[2]
}
}, $mk116384(r99));
c27272_5 = 0;
} catch ($e) {
let r31 = $e;
if (c27272_5 !== 0) {
while (true) {
try {
c27272_5 = 0;
(0, setSendState)(env30511[0], env30511[1], InviteSendStates.ERROR);
AccessibilityAnnouncer.announce(intl.string(t.fEptJP));
break L12;
} catch ($e) {
r31 = $e;
if (c27272_5 === 0) {
break;
}
}
}
}
throw r31;
}
}
}