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

348 lines
14 KiB
TypeScript

// Metro module 4403 (f4404).
import { isGuildNSFW } from "../../records/GuildRecord";
import ChannelStore from "../../stores/ChannelStore";
import GuildNSFWAgreeStore from "../../stores/GuildNSFWAgreeStore";
import GuildStore from "../../stores/GuildStore";
import UserStore from "../../stores/UserStore";
import { AgeGateSource } from "./AgeGateConstants";
import { HelpdeskArticles, GuildNSFWContentLevel } from "../../Constants";
import { intl, t } from "../../intl/index.native";
import SnowflakeUtils from "../../utils/SnowflakeUtils";
import * as _AgeVerificationUtils from "../age_assurance/AgeVerificationUtils";
import { useShouldShowTiggerPawtect, useIsAgeVerified } from "../age_assurance/AgeVerificationUtils";
import * as _RegionalFeatureConfigUtils from "../regional_feature_config/RegionalFeatureConfigUtils";
import { useIsFeatureAgeGated } from "../regional_feature_config/RegionalFeatureConfigUtils";
import { AgeGatedFeature } from "../../_bundle/Module5013";
import { useStateFromStores } from "../../_bundle/Module589";
import { NsfwSpaceWarningModalType } from "../age_assurance/AgeVerificationAnalyticsUtils";
import HelpdeskUtils from "../../utils/HelpdeskUtils";
import { openAgeGateModal } from "./AgeGateModalActionCreators";
import { useIsChannelSpoilerGated } from "../spoiler_channels/SpoilerChannelUtils";
let c2633_10, c2633_11, c2633_12, isChannelContentGated, useIsChannelContentGated;
const shouldShowAgeGateForVoiceChannel = function shouldShowAgeGateForVoiceChannel(channelId) {
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
let r19 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect;
if (r19) {
const currentUser = UserStore.getCurrentUser();
const r0 = currentUser == null;
let r23 = false;
if (!r0) {
const shouldShowTiggerPawtect2 = _AgeVerificationUtils.shouldShowTiggerPawtect();
const r33 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect2;
r23 = currentUser.nsfwAllowed !== true || r33;
}
const r38 = r23 ? channelId == null : !r23;
r19 = r38 ? !r38 : isChannelContentGated(ChannelStore.getChannel(channelId));
}
return r19;
};
isChannelContentGated = function isChannelContentGated(a0) {
if (a0 == null) {
return false;
}
let r8 = GuildNSFWAgreeStore.didAgree(a0.guild_id);
const nsfwAllowed = UserStore.getCurrentUser()?.nsfwAllowed;
const isFeatureAgeGated = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES);
let r26 = _AgeVerificationUtils.shouldShowTiggerPawtect();
if (r8) {
r8 = !(nsfwAllowed === false);
}
let r29 = !r8;
if (r8) {
if (r26) {
r26 = isFeatureAgeGated;
}
r29 = r26;
}
if (a0.isNSFW() && r29) {
return true;
}
const guild = GuildStore.getGuild(a0.guild_id);
return guild != null && (isGuildNSFW(guild) && r29);
};
useIsChannelContentGated = function useIsChannelContentGated(a0) {
const shouldShowTiggerPawtect = useShouldShowTiggerPawtect();
let r21 = useStateFromStores([GuildNSFWAgreeStore], () => GuildNSFWAgreeStore.didAgree(a0?.guild_id));
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser()?.nsfwAllowed === false);
let r35 = useIsFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES);
const stateFromStores2 = useStateFromStores([GuildStore], () => GuildStore.getGuild(a0?.guild_id));
if (r21) {
r21 = !stateFromStores;
}
let r43 = !r21;
if (r21) {
if (r35) {
r35 = shouldShowTiggerPawtect;
}
r43 = r35;
}
let r3 = a0 != null;
if (r3) {
const isNSFW = a0.isNSFW();
const r2 = isNSFW ? !r43 : !isNSFW;
let r4 = !r2;
if (r2) {
let r46 = stateFromStores2 != null;
if (r46) {
const isGuildNSFW2 = isGuildNSFW(stateFromStores2);
r46 = !(isGuildNSFW2 ? !r43 : !isGuildNSFW2);
}
r4 = r46;
}
r3 = r4;
}
return r3;
};
c2633_10 = new Date("06/16/2020");
c2633_11 = [GuildNSFWContentLevel.AGE_RESTRICTED, GuildNSFWContentLevel.EXPLICIT];
c2633_12 = new Set([AgeGateSource.NSFW_SERVER, AgeGateSource.NSFW_SERVER_INVITE, AgeGateSource.NSFW_SERVER_INVITE_EMBED]);
export { c2633_12 as SERVER_AGE_GATE_SOURCES };
export function userNeedsAgeGate() {
const currentUser = UserStore.getCurrentUser();
return currentUser != null && SnowflakeUtils.extractTimestamp(currentUser.id) > c2633_10.getTime() && currentUser.nsfwAllowed == null;
}
export function guildNeedsAgeGate(a0) {
return c2633_11.includes(a0.nsfwLevel);
}
export function shouldAgeVerifyForAgeGate() {
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
return _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect;
}
export function useShouldAgeVerifyForAgeGate() {
let r11 = useIsFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES);
const shouldShowTiggerPawtect = useShouldShowTiggerPawtect();
if (r11) {
r11 = shouldShowTiggerPawtect;
}
return r11;
}
export function useAgeGateVerifyContentForGuild(a0) {
let r66, r117;
const isAgeVerified = useIsAgeVerified();
const isGuildNSFW2 = isGuildNSFW(a0);
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser()?.nsfwAllowed === false);
const isFeatureAgeGated = useIsFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES);
const shouldShowTiggerPawtect = useShouldShowTiggerPawtect();
const r35 = isFeatureAgeGated && shouldShowTiggerPawtect;
const title = intl.string(isGuildNSFW2 ? t.xi46lg : t.ZmwvDc);
const r43 = {
title: null,
description: null,
agreement: null,
modalType: null
};
if (r35) {
r43.title = title;
if (isAgeVerified) {
r43.description = isGuildNSFW2 ? intl.format(t["8tk6bB"], {}) : intl.format(t.XQZvwn, {});
r43.agreement = intl.string(t.Zt4Mf4);
r43.modalType = NsfwSpaceWarningModalType.NSFW_CHANNEL_AGE_VERIFY;
r117 = r43;
} else {
r43.description = isGuildNSFW2 ? intl.string(t.V6Gmu9) : intl.string(t["5rygLk"]);
r43.agreement = intl.string(t.FDSSia);
r43.modalType = NsfwSpaceWarningModalType.NSFW_CHANNEL_AGE_VERIFY;
r117 = r43;
}
r66 = r117;
} else if (stateFromStores) {
r43.title = intl.string(isGuildNSFW2 ? t["H0SG/g"] : t.NEabBa);
r43.description = intl.format(isGuildNSFW2 ? t["6++3cX"] : t["2kHZes"], {
helpURL: HelpdeskUtils.getArticleURL(HelpdeskArticles.NSFW_AGE_GATING)
});
r43.modalType = NsfwSpaceWarningModalType.NSFW_CHANNEL_UNDERAGE;
r66 = r43;
} else {
r43.title = title;
r43.description = intl.string(isGuildNSFW2 ? t.ZtuRts : t.E4Cd5I);
r43.agreement = intl.string(t.wVq7uo);
r43.modalType = NsfwSpaceWarningModalType.NSFW_CHANNEL_VERIFIED;
r66 = r43;
}
return r66;
}
export function useAgeGateVerifyContent(a0) {
let r49;
const isAgeVerified = useIsAgeVerified();
const isFeatureAgeGated = useIsFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES);
const shouldShowTiggerPawtect = useShouldShowTiggerPawtect();
const r28 = isFeatureAgeGated && shouldShowTiggerPawtect;
const r1 = a0 === AgeGateSource.NSFW_SERVER || a0 === AgeGateSource.NSFW_SERVER_INVITE || a0 === AgeGateSource.NSFW_SERVER_INVITE_EMBED;
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser()?.nsfwAllowed === false);
if (a0 !== AgeGateSource.JOIN_LARGE_GUILD_UNDERAGE && a0 !== AgeGateSource.ACCESS_LARGE_GUILD_UNDERAGE) {
L31: {
if (isAgeVerified) {
r49 = {
verifyAgreementButtonText: intl.string(t.Zt4Mf4),
verifyGateDescription: r1 ? intl.format(t["8tk6bB"], {}) : intl.format(t.XQZvwn, {}),
verifyTitle: r1 ? intl.string(t.xi46lg) : intl.string(t.ZmwvDc)
};
} else if (a0 === AgeGateSource.LARGE_GUILD) {
r49 = {
verifyTitle: intl.string(t["7ymzsL"]),
verifyGateDescription: intl.string(t.SxY4IW),
verifyAgreementButtonText: intl.string(t.FDSSia)
};
} else {
if (stateFromStores && r1 && !r28) {
r49 = {
verifyTitle: intl.string(t["H0SG/g"]),
verifyGateDescription: intl.format(t["6++3cX"], {
helpURL: HelpdeskUtils.getArticleURL(HelpdeskArticles.AGE_GATE)
}),
verifyAgreementButtonText: null
};
break L31;
}
r49 = {
verifyAgreementButtonText: intl.string(t.FDSSia),
verifyGateDescription: r1 ? intl.string(t.V6Gmu9) : intl.string(t["5rygLk"]),
verifyTitle: r1 ? intl.string(t.xi46lg) : intl.string(t.ZmwvDc)
};
}
}
return r49;
}
const r159 = a0 === AgeGateSource.JOIN_LARGE_GUILD_UNDERAGE ? t["u/xsK9"] : t.MjQbfi;
const verifyGateDescription = isAgeVerified ? intl.string(t.SAoMVJ) : intl.string(t.SxY4IW);
const verifyAgreementButtonText = isAgeVerified ? intl.string(t.Zt4Mf4) : intl.string(t.FDSSia);
return {
verifyTitle: intl.string(r159),
verifyGateDescription,
verifyAgreementButtonText
};
}
export function shouldShowAgeGateForCurrentUser() {
const currentUser = UserStore.getCurrentUser();
if (currentUser == null) {
return false;
}
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
const r19 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect;
return currentUser.nsfwAllowed !== true || r19;
}
export function shouldShowAgeGateForGuildContentLevel(a0) {
const currentUser = UserStore.getCurrentUser();
const r0 = currentUser == null;
let r12 = false;
if (!r0) {
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
const r22 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect;
r12 = currentUser.nsfwAllowed !== true || r22;
}
if (r12 && a0 != null) {
const guild = GuildStore.getGuild(a0);
return guild != null && isGuildNSFW(guild);
}
return false;
}
export function shouldShowAgeGateForChannelId(a0) {
const currentUser = UserStore.getCurrentUser();
const r0 = currentUser == null;
let r11 = false;
if (!r0) {
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
const r21 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect;
r11 = currentUser.nsfwAllowed !== true || r21;
}
const r26 = r11 ? a0 == null : !r11;
return r26 ? !r26 : isChannelContentGated(ChannelStore.getChannel(a0));
}
export { shouldShowAgeGateForVoiceChannel };
export function maybeOpenAgeGateForVoiceChannel(a0) {
let r6 = !!shouldShowAgeGateForVoiceChannel(a0);
if (r6) {
openAgeGateModal(AgeGateSource.NSFW_VOICE_CHANNEL);
r6 = true;
}
return r6;
}
export function maybeShowAgeGate(a0, a1, a2) {
const currentUser = UserStore.getCurrentUser();
const r0 = currentUser == null;
let r5 = false;
if (!r0) {
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
const r23 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect;
r5 = currentUser.nsfwAllowed !== true || r23;
}
let r27 = false;
if (r5) {
const r29 = a0 == null;
r27 = false;
if (!r29) {
const guild = GuildStore.getGuild(a0);
r27 = guild != null && isGuildNSFW(guild);
}
}
let r36 = a2;
if (r27) {
if (!(a2 != null && c2633_12.has(a2))) {
r36 = AgeGateSource.NSFW_SERVER;
}
openAgeGateModal(r36);
} else {
const currentUser2 = UserStore.getCurrentUser();
let r39 = currentUser2 != null && currentUser2.nsfwAllowed == null;
if (r39) {
const currentUser3 = UserStore.getCurrentUser();
const r43 = currentUser3 == null;
let r6 = false;
if (!r43) {
const shouldShowTiggerPawtect2 = _AgeVerificationUtils.shouldShowTiggerPawtect();
const r58 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.AGE_GATED_SPACES) && shouldShowTiggerPawtect2;
r6 = currentUser3.nsfwAllowed !== true || r58;
}
const r63 = r6 ? a1 == null : !r6;
r39 = r63 ? !r63 : isChannelContentGated(ChannelStore.getChannel(a1));
}
if (r39) {
openAgeGateModal(a2 == null ? AgeGateSource.NSFW_CHANNEL : a2);
}
}
}
export function isChannelOrGuildNSFW(a0) {
return a0 != null && (a0.isNSFW() || isGuildNSFW(GuildStore.getGuild(a0.guild_id)));
}
export function isChannelAgeVerificationGated(a0) {
if (a0 == null) {
return false;
}
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
return a0 != null && (a0.isNSFW() || isGuildNSFW(GuildStore.getGuild(a0.guild_id))) && shouldShowTiggerPawtect;
}
export function userCannotSeeNSFWContent(a0) {
if (a0 == null) {
return false;
}
const nsfwAllowed = UserStore.getCurrentUser()?.nsfwAllowed;
return a0 != null && (a0.isNSFW() || isGuildNSFW(GuildStore.getGuild(a0.guild_id))) && !(nsfwAllowed === true);
}
export { isChannelContentGated };
export { useIsChannelContentGated };
export function useShouldHideChannelContent(a0) {
const isChannelContentGated2 = useIsChannelContentGated(a0);
const isChannelSpoilerGated = useIsChannelSpoilerGated(a0);
return isChannelContentGated2 || isChannelSpoilerGated;
}
export function isCurrentUserMissingDateOfBirth() {
const currentUser = UserStore.getCurrentUser();
return currentUser != null && currentUser.nsfwAllowed == null;
}
export function shouldAgeVerifyForSettingsToggles() {
let r11 = _RegionalFeatureConfigUtils.isFeatureAgeGated(AgeGatedFeature.COMMANDS_TOGGLE);
const shouldShowTiggerPawtect = _AgeVerificationUtils.shouldShowTiggerPawtect();
if (r11) {
r11 = shouldShowTiggerPawtect;
}
return r11;
}
export function useShouldAgeVerifyForSettingsToggles() {
let r11 = useIsFeatureAgeGated(AgeGatedFeature.COMMANDS_TOGGLE);
const shouldShowTiggerPawtect = useShouldShowTiggerPawtect();
if (r11) {
r11 = shouldShowTiggerPawtect;
}
return r11;
}