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

138 lines
4.9 KiB
TypeScript

// Metro module 10572 (f10573).
import UserStore from "../../stores/UserStore";
import { EMOJI_SIZE, VoiceChannelEffectAnimationType } from "./VoiceChannelEffectsConstants";
import Module10574 from "../../_bundle/Module10574";
import Module10575 from "../../_bundle/Module10575";
import Module10576 from "../../_bundle/Module10576";
import Module10577 from "../../_bundle/Module10577";
import Module10578 from "../../_bundle/Module10578";
import Module10579 from "../../_bundle/Module10579";
import Module10580 from "../../_bundle/Module10580";
import Module10581 from "../../_bundle/Module10581";
import Module10582 from "../../_bundle/Module10582";
import Module10583 from "../../_bundle/Module10583";
import Module10584 from "../../_bundle/Module10584";
import Module10585 from "../../_bundle/Module10585";
import Module10586 from "../../_bundle/Module10586";
import Module10587 from "../../_bundle/Module10587";
import Module10588 from "../../_bundle/Module10588";
import Module10589 from "../../_bundle/Module10589";
import Module10590 from "../../_bundle/Module10590";
import Module10591 from "../../_bundle/Module10591";
import Module10592 from "../../_bundle/Module10592";
import Module10593 from "../../_bundle/Module10593";
import Module10594 from "../../_bundle/Module10594";
import Module10595 from "../../_bundle/Module10595";
import Module12 from "../../_bundle/Module12";
import { getDevicePixelRatio } from "../image_upload/ImageLoaderUtils";
import AvatarUtils from "../../utils/AvatarUtils";
import UnicodeEmojis from "../emojis/UnicodeEmojis";
import EmojiUtils from "../../utils/EmojiUtils";
import { intl, t } from "../../intl/index.native";
function $mk85113($env) {
return (a0) => {
let r4 = a0[$env[0]];
if (r4 == null) {
r4 = null;
}
return r4;
};
}
function $mk85114() {
return (a0) => a0 != null;
}
const r10 = [Module10574];
const r23 = [Module10575, Module10576, Module10577, Module10578, Module10579, Module10580, Module10581, Module10582, Module10583, Module10584, Module10585, Module10586, Module10587, Module10588, Module10589, Module10590, Module10591, Module10592, Module10593, Module10594, Module10595];
const r64 = {};
r64[VoiceChannelEffectAnimationType.BASIC] = r10;
r64[VoiceChannelEffectAnimationType.PREMIUM] = r23;
let c7107_6 = r64;
const r71 = Module12.memoize((src) => new Promise((c26709_0) => {
const image = new Image();
let c26709_1 = image;
image.src = src;
image.crossOrigin = "Anonymous";
image.onload = () => {
const width = EMOJI_SIZE * getDevicePixelRatio();
if (c26709_1.width === width && c26709_1.height === width) {
c26709_0(src);
} else {
const element = document.createElement("canvas");
element.width = width;
element.height = width;
const context = element.getContext("2d");
if (context != null) {
context.drawImage(c26709_1, 0, 0);
}
c26709_0(element.toDataURL("image/png"));
}
};
}));
export const CUSTOM_CALL_SOUND_ANIMATION_RANGE = {
start: 10,
end: 15
};
export { c7107_6 as AnimationTypeToAnimations };
export { r71 as getResizedEmojiData };
export function sampleAnimationId(a0, a1) {
const r8 = c7107_6[a0];
if (a1 != null && a0 === VoiceChannelEffectAnimationType.PREMIUM) {
const r19 = a1.end + 1;
return Math.floor(Math.random() * (a1.start - r19) + r19);
}
return Math.floor(Math.random() * r8.length);
}
export function getEffectUrl(a0, size = EMOJI_SIZE) {
if (a0.id != null) {
let animated = a0.animated;
if (animated == null) {
animated = false;
}
return AvatarUtils.getEmojiURL({
id: a0.id,
animated,
size
});
}
const byName = UnicodeEmojis.getByName(UnicodeEmojis.convertSurrogateToName(a0.name, false));
return byName != null ? EmojiUtils.getURL(byName.surrogates) : "";
}
export function getEffectAnnouncement(a0) {
let emojiNames;
if (a0.length < 1) {
return "";
}
let env18138;
let env18139;
const r18 = env18138 = {};
env18138[0] = "userId";
const r30 = Module12(a0).map($mk85113(r18)).filter($mk85114()).uniq().value();
const r31 = env18139 = {};
env18139[0] = "emojiName";
const r45 = Module12(a0).map($mk85113(r31)).filter($mk85114()).uniq().value();
if (r45.length < 2) {
let r49 = r45 == null ? void 0 : r45[0];
if (r49 == null) {
r49 = "";
}
emojiNames = r49;
} else {
emojiNames = r45.join(", ");
}
const r51 = r30.length < 1;
const r52 = r51 ? "" : r30.length === 1 ? intl.formatToPlainString(t.yZYxzF, {
firstUsername: UserStore.getUser(r30[0])?.username,
emojiNames
}) : r30.length === 2 ? intl.formatToPlainString(t["8rmtbd"], {
firstUsername: UserStore.getUser(r30[0])?.username,
secondUsername: UserStore.getUser(r30[1])?.username,
emojiNames
}) : intl.formatToPlainString(t["/okjv0"], {
firstUsername: UserStore.getUser(r30[0])?.username,
secondUsername: UserStore.getUser(r30[1])?.username,
count: r30.length - 2,
emojiNames
});
return r52;
}