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

108 lines
4.3 KiB
TypeScript

// Metro module 6046 (f6047).
import GuildStore from "../../stores/GuildStore";
import PermissionStore from "../../stores/PermissionStore";
import { GUILD_OFFICIAL_HIGHLIGHT_ALPHA } from "./MessageConstants";
import { GuildFeatures, Permissions, MessageFlags, ChannelTypes } from "../../Constants";
import { int2hex } from "../../_bundle/int2hslRaw";
import Module689 from "../../_bundle/Module689";
import { getAccessibleForegroundColor } from "../../utils/ColorUtils";
import { WCAGContrastRatios } from "../../design/shared";
import GuildOfficialMessagesExperiment from "./GuildOfficialMessagesExperiment";
import { useStateFromStores } from "../../_bundle/Module589";
import { getIsActiveChannelOrUnarchivableThread } from "../threads/ThreadHooks";
import isSystemMessage from "./isSystemMessage";
function $mk77626($env) {
return () => {
const r4 = $env[0];
return r4 != null ? $env.$parent[3].getGuild(r4) : null;
};
}
let env3830 = {};
export function useCanManageGuildOfficialMessages(a0, a1, a2) {
let env15378;
let guildId = a0;
const r2 = env15378 = {
$parent: env3830
};
env15378[0] = a0;
const stateFromStores = useStateFromStores([GuildStore], $mk77626(r2), [a0]);
if (a0 == null) {
guildId = void 0;
}
const enabled = GuildOfficialMessagesExperiment.useExperiment({
guildId,
location: a2
}).enabled;
let r25 = stateFromStores != null && stateFromStores.features.has(GuildFeatures.VERIFIED) && enabled;
const stateFromStores2 = useStateFromStores([PermissionStore], () => PermissionStore.can(Permissions.MANAGE_OFFICIAL_MESSAGES, a1), [a1]);
if (r25) {
r25 = stateFromStores2;
}
return r25;
}
export function getAccessibleGuildOfficialTextColor(a0, a1, saturationFactor = 1, r12 = GUILD_OFFICIAL_HIGHLIGHT_ALPHA) {
const r11 = int2hex(a0);
let background = Module689(a1);
const foreground = Module689(r11);
const r28 = Module689.mix(background, r11, r12, "rgb");
if (Module689.contrast(foreground, r28) < Module689.contrast(foreground, background)) {
background = r28;
}
return getAccessibleForegroundColor({
foreground,
background,
ratio: WCAGContrastRatios.Text,
saturationFactor
});
}
export function showGuildOfficialMessageGradient(a0) {
return a0 !== "no_gradient" && a0 !== "hidden";
}
export function showGuildOfficialMessageTextColor(a0) {
return a0 !== "no_text_color" && a0 !== "hidden";
}
export function isGuildOfficialMessagesEnabled(a0, a1) {
return a0 != null && a0.features.has(GuildFeatures.VERIFIED) && GuildOfficialMessagesExperiment.getCurrentConfig({
guildId: a0.id,
location: a1
}).enabled;
}
export function useIsGuildOfficialMessagesEnabled(a0, a1) {
let env15376;
const r3 = env15376 = {
$parent: env3830
};
let guildId = a0;
env15376[0] = a0;
const stateFromStores = useStateFromStores([GuildStore], $mk77626(r3), [a0]);
if (a0 == null) {
guildId = void 0;
}
const enabled = GuildOfficialMessagesExperiment.useExperiment({
guildId,
location: a1
}).enabled;
return stateFromStores != null && stateFromStores.features.has(GuildFeatures.VERIFIED) && enabled;
}
export function canManageGuildOfficialMessages(a0, a1, a2) {
return a0 != null && a0.features.has(GuildFeatures.VERIFIED) && GuildOfficialMessagesExperiment.getCurrentConfig({
guildId: a0.id,
location: a2
}).enabled && PermissionStore.can(Permissions.MANAGE_OFFICIAL_MESSAGES, a1);
}
export function useCanToggleGuildOfficialMessages(a0, a1, a2) {
let guild_id = a1.guild_id;
if (guild_id == null) {
guild_id = void 0;
}
const r8 = useCanManageGuildOfficialMessages(guild_id, a1, a2);
const r9 = r8 ? isSystemMessage(a0) : !r8;
return r9 ? !r9 : a0.hasFlag(MessageFlags.IS_GUILD_OFFICIAL) ? getIsActiveChannelOrUnarchivableThread(a1) : a1 != null && !a1.isPrivate() && getIsActiveChannelOrUnarchivableThread(a1) && a1.type !== ChannelTypes.GUILD_VOICE && a1.type !== ChannelTypes.GUILD_STAGE_VOICE;
}
export function canSendGuildOfficialMessages(a0, a1, a2) {
return a0 != null && a0.features.has(GuildFeatures.VERIFIED) && GuildOfficialMessagesExperiment.getCurrentConfig({
guildId: a0.id,
location: a2
}).enabled && PermissionStore.can(Permissions.MANAGE_OFFICIAL_MESSAGES, a1) && (a1 != null && !a1.isPrivate() && getIsActiveChannelOrUnarchivableThread(a1) && a1.type !== ChannelTypes.GUILD_VOICE && a1.type !== ChannelTypes.GUILD_STAGE_VOICE);
}