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

147 lines
4.4 KiB
TypeScript

// Metro module 6050 (f6051).
import _objectWithoutProperties from "../../_bundle/_objectWithoutProperties";
import { useMemo } from "react";
import ChannelStore from "../../stores/ChannelStore";
import GuildStore from "../../stores/GuildStore";
import { ActivityTypes, ActivityFlags } from "../../Constants";
import { useStateFromStores, useStateFromStoresArray } from "../../_bundle/Module589";
import { useAppliedTags } from "../forums/ForumTagHooks";
import { useFirstForumPostMessage } from "../forums/ForumPostDataLoader";
import { useApplication } from "../applications/ApplicationActionCreators";
import { useSubscribeGuildMembers } from "../../lib/guild/subscribeGuildMembers";
import hasFlag from "../activities/utils/hasFlag";
function $mk77642($env) {
return () => {
const r5 = $env[0];
let r8 = r5 != null;
if (r8) {
const isForumPost = r5.isForumPost();
const r0 = isForumPost ? r5.parent_id == null : !isForumPost;
let r11 = !r0;
if (!r0) {
const channel = $env.$parent[6].getChannel(r5.parent_id);
let r16 = channel == null ? void 0 : channel.isGameInvitesChannel();
if (r16 == null) {
r16 = false;
}
r11 = r16;
}
r8 = r11;
}
return r8;
};
}
function $mk77643($env) {
return () => {
const r6 = $env[0];
const r2 = r6 == null;
let r7 = null;
if (!r2) {
const guild = $env.$parent[7].getGuild(r6);
const r10 = guild == null;
let r11 = void 0;
if (!r10) {
const gameApplicationIds = guild.gameApplicationIds;
r11 = gameApplicationIds == null ? void 0 : gameApplicationIds[0];
}
if (r11 == null) {
r11 = null;
}
r7 = r11;
}
return r7;
};
}
let env3833 = {};
const _excluded = ["data"];
const c3833_10 = {
"1509696536903417891": "1373923512766697512"
};
const c3833_11 = "No Mic";
export const GAME_INVITES_CHANNEL_NO_MIC_TAG_NAME = "No Mic";
export function useIsGameInvitesPost(a0) {
let env15393;
const r1 = env15393 = {
$parent: env3833
};
env15393[0] = a0;
return useStateFromStores([ChannelStore], $mk77642(r1));
}
export function useIsGameInvitePostVoiceEnabled(a0) {
let env15395;
const appliedTags = useAppliedTags(a0);
const r11 = env15395 = {
$parent: env3833
};
env15395[0] = a0;
return !!useStateFromStores([ChannelStore], $mk77642(r11)) && !appliedTags.some((appliedTag) => appliedTag.name === c3833_11);
}
export function useFirstMessage(a0, a1) {
return useFirstForumPostMessage(a0, {
enabled: a1,
allowArchived: true
});
}
export function useGameInvitesChannelApplicationId(a0) {
let env15394;
const r2 = env15394 = {
$parent: env3833
};
env15394[0] = a0;
const stateFromStores = useStateFromStores([GuildStore], $mk77643(r2), [a0]);
let r16 = a0 != null ? c3833_10[a0] : null;
if (r16 == null) {
r16 = stateFromStores;
}
return r16;
}
export function useGameInvitesChannelOfficialApplication(a0) {
let env15396;
const r3 = env15396 = {
$parent: env3833
};
env15396[0] = a0;
const stateFromStores = useStateFromStores([GuildStore], $mk77643(r3), [a0]);
let r16 = a0 != null ? c3833_10[a0] : null;
if (r16 == null) {
r16 = stateFromStores;
}
const application = useApplication(r16);
return (0, useMemo)(() => ({
application: application.data,
..._objectWithoutProperties(application, _excluded)
}), [application]);
}
export function useSubscribeToGameInvitePostAuthors(a0, a1) {
const isGameInvitesChannel = a0.isGameInvitesChannel();
const stateFromStoresArray = useStateFromStoresArray([ChannelStore], () => {
if (!isGameInvitesChannel) {
return [];
}
const set = new Set();
const r26 = [];
for (const item of a1) {
const ownerId = ChannelStore.getChannel(item)?.ownerId;
if (!(ownerId == null || set.has(ownerId))) {
set.add(ownerId);
r26.push(ownerId);
}
}
return r26;
}, [isGameInvitesChannel, a1]);
useSubscribeGuildMembers((0, useMemo)(() => {
let r4;
const r1 = {};
if (isGameInvitesChannel) {
r1[a0.guild_id] = stateFromStoresArray;
r4 = r1;
} else {
r4 = r1;
}
return r4;
}, [stateFromStoresArray, a0.guild_id, isGameInvitesChannel]), "GameInvitesChannelPostAuthors");
}
export function canInviteToActivity(a0) {
return a0.type === ActivityTypes.PLAYING && hasFlag(a0, ActivityFlags.JOIN);
}