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

113 lines
4.0 KiB
TypeScript

// Metro module 8915 (f8916).
import AuthenticationStore from "../../stores/AuthenticationStore";
import CallStore from "../../stores/CallStore";
import ChannelStore from "../../stores/ChannelStore";
import GuildMemberStore from "../../stores/GuildMemberStore";
import GuildVerificationStore from "../../stores/GuildVerificationStore";
import PermissionStore from "../../stores/PermissionStore";
import PresenceStore from "../../stores/PresenceStore";
import RelationshipStore from "../../stores/RelationshipStore";
import VoiceStateStore from "../../stores/VoiceStateStore";
import { ChannelTypes, ChannelTypesSets, StatusTypes } from "../../Constants";
import { useStateFromStores } from "../../_bundle/Module589";
import GuildVoiceRingingExperiment from "../voice_calls/GuildVoiceRingingExperiment";
import canJoinVoiceChannel from "../channel/canJoinVoiceChannel";
import useChannelRoleSubscriptionStatus from "../guild_role_subscriptions/useChannelRoleSubscriptionStatus";
const useCanRingToGuildVoiceChannel = function useCanRingToGuildVoiceChannel(c16870_0, location2 = "useCanRingToGuildVoiceChannel", r9) {
let c16870_1 = r9;
const stateFromStores2 = useStateFromStores([PermissionStore], () => c16870_1 != null && canJoinVoiceChannel(c16870_1, PermissionStore));
const stateFromStores3 = useStateFromStores([GuildMemberStore, GuildVerificationStore], () => {
const guild_id = c16870_1?.guild_id;
if (guild_id == null) {
return false;
}
let r11 = GuildMemberStore.getMember(guild_id, c16870_0.id) != null;
const canChat = GuildVerificationStore.getCheck(guild_id).canChat;
if (r11) {
r11 = canChat;
}
return r11;
});
const needSubscriptionToAccess = useChannelRoleSubscriptionStatus(r9?.id).needSubscriptionToAccess;
let enabled = GuildVoiceRingingExperiment.useExperiment({
guildId: r9?.guild_id,
location: location2
}).enabled;
const type = r9?.type;
const GUILD_VOICE = ChannelTypes.GUILD_VOICE;
if (enabled) {
enabled = type === GUILD_VOICE;
}
if (enabled) {
enabled = stateFromStores3;
}
if (enabled) {
enabled = stateFromStores2;
}
if (enabled) {
enabled = !needSubscriptionToAccess;
}
return enabled;
};
export function useCanRing(a0) {
let r10 = arguments[1];
if (r10 === void 0) {
r10 = "useCanRing";
}
let c16871_1 = arguments[2];
const stateFromStores = useStateFromStores([ChannelStore], () => ChannelStore.getChannel(c16871_1));
const stateFromStores2 = useStateFromStores([AuthenticationStore], () => AuthenticationStore.getId() === a0.id);
let r30 = useStateFromStores([RelationshipStore], () => RelationshipStore.isFriend(a0.id));
const stateFromStores3 = useStateFromStores([PresenceStore], () => PresenceStore.getStatus(a0.id) === StatusTypes.DND && stateFromStores?.guild_id != null);
const type = stateFromStores?.type;
const r39 = type != null && ChannelTypesSets.CALLABLE.has(type);
let r44 = useCanRingToGuildVoiceChannel(a0, r10, stateFromStores);
if (r30) {
r30 = !stateFromStores3;
}
if (r30) {
r30 = !stateFromStores2;
}
if (r30) {
r30 = !a0.bot;
}
if (r30) {
r30 = !a0.system;
}
if (r30) {
r30 = !a0.isProvisional;
}
if (r30) {
if (!r44) {
r44 = r39;
}
r30 = r44;
}
return r30;
}
export function canRingUsersInChannel(a0) {
const r11 = ChannelTypesSets.CALLABLE.has(a0.type);
const type = a0.type;
const GUILD_VOICE = ChannelTypes.GUILD_VOICE;
if (r11) {
const call = CallStore.getCall(a0.id);
return call != null && call.messageId != null && !CallStore.isCallUnavailable(a0.id);
}
if (type === GUILD_VOICE) {
let enabled = GuildVoiceRingingExperiment.getCurrentConfig({
guildId: a0.guild_id,
location: "ring"
}).enabled;
const voiceState = VoiceStateStore.getVoiceState(a0.guild_id, AuthenticationStore.getId());
if (enabled) {
enabled = voiceState != null;
}
if (enabled) {
enabled = voiceState.channelId === a0.id;
}
return enabled;
}
return false;
}
export { useCanRingToGuildVoiceChannel };