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

162 lines
5.6 KiB
TypeScript

// Metro module 8845 (f8846).
import ChannelStore from "../../stores/ChannelStore";
import RTCConnectionStore from "../../stores/RTCConnectionStore";
import { ANIMATED_DEFAULT_VIDEO_BACKGROUNDS, DefaultVideoBackground, VideoFilterType } from "./VideoBackgroundConstants";
import { AnalyticEvents } from "../../Constants";
import { isAnimatedIconHash, isVideoAssetHash } from "../../utils/AvatarUtils";
import { getVoiceStateMetadata } from "../app_analytics/AppAnalyticsUtils";
import AnalyticsUtils from "../../utils/AnalyticsUtils";
let getEffectDetailAnalyticsName;
const isAnimatedBackgroundOption = function isAnimatedBackgroundOption(a0) {
let r18;
if (typeof a0 === "number" ? a0 in DefaultVideoBackground : typeof a0 === "number") {
r18 = ANIMATED_DEFAULT_VIDEO_BACKGROUNDS.includes(a0);
} else {
let r12 = a0 != null && typeof a0 === "object" && "id" in a0;
if (r12) {
let r1 = a0.type === VideoFilterType.BACKGROUND;
if (!r1) {
a0.type;
r1 = false;
}
r12 = r1;
}
r18 = !!r12 && (isAnimatedIconHash(a0.asset) || isVideoAssetHash(a0.asset));
}
return r18;
};
getEffectDetailAnalyticsName = function getEffectDetailAnalyticsName(lastUsedVideoBackgroundOption) {
const r1 = lastUsedVideoBackgroundOption == null;
let r3 = "None";
if (!r1) {
let r10 = lastUsedVideoBackgroundOption != null && typeof lastUsedVideoBackgroundOption === "object" && "id" in lastUsedVideoBackgroundOption;
if (r10) {
let r13 = lastUsedVideoBackgroundOption.type === VideoFilterType.BACKGROUND;
if (!r13) {
lastUsedVideoBackgroundOption.type;
r13 = false;
}
r10 = r13;
}
let r15 = "Custom";
if (!r10) {
let r16 = "Blur";
if (lastUsedVideoBackgroundOption !== "blur") {
const OPTION_1 = DefaultVideoBackground.OPTION_1;
const r18 = OPTION_1 !== lastUsedVideoBackgroundOption ? DefaultVideoBackground.OPTION_2 !== lastUsedVideoBackgroundOption ? DefaultVideoBackground.OPTION_3 !== lastUsedVideoBackgroundOption ? DefaultVideoBackground.OPTION_4 !== lastUsedVideoBackgroundOption ? DefaultVideoBackground.OPTION_7 !== lastUsedVideoBackgroundOption ? DefaultVideoBackground.OPTION_8 !== lastUsedVideoBackgroundOption ? DefaultVideoBackground.OPTION_9 !== lastUsedVideoBackgroundOption ? DefaultVideoBackground.OPTION_10 === lastUsedVideoBackgroundOption ? "Wumpice" : void 0 : "Hacker Den" : "Capernite Night" : "Capernite Day" : "Vaporwave" : "Wumpus Vacation" : "Discord the Movie" : "Cybercity";
r16 = `Preset - ${r18}`;
}
r15 = r16;
}
r3 = r15;
}
return r3;
};
export function isCustomBackgroundOption(a0) {
let r6 = a0 != null && typeof a0 === "object" && "id" in a0;
if (r6) {
let r1 = a0.type === VideoFilterType.BACKGROUND;
if (!r1) {
a0.type;
r1 = false;
}
r6 = r1;
}
return r6;
}
export function isDefaultBackgroundOption(a0) {
return typeof a0 === "number" ? a0 in DefaultVideoBackground : typeof a0 === "number";
}
export { isAnimatedBackgroundOption };
export function getEffectAnalyticsType(a0) {
return a0 != null ? "Video Background" : "None";
}
export { getEffectDetailAnalyticsName };
export function trackBackgroundOptionUpdated(a0, a1, a2) {
const guildId = RTCConnectionStore.getGuildId();
const channelId = RTCConnectionStore.getChannelId();
const channel = ChannelStore.getChannel(channelId);
const voiceStateMetadata = getVoiceStateMetadata(guildId, channelId, true);
AnalyticsUtils.track(AnalyticEvents.VIDEO_EFFECT_UPDATED, {
location: a1,
effect_type: a0 != null ? "Video Background" : "None",
effect_detail: getEffectDetailAnalyticsName(a0),
effect_state: a2,
channel_id: channelId,
channel_type: channel?.type,
guild_id: guildId,
voice_state_count: voiceStateMetadata.voice_state_count,
video_stream_count: voiceStateMetadata.video_stream_count,
media_session_id: RTCConnectionStore.getMediaSessionId(),
rtc_connection_id: RTCConnectionStore.getRTCConnectionId(),
is_animated: isAnimatedBackgroundOption(a0)
});
}
export function trackBackgroundOptionAdded(a0, a1, a2) {
AnalyticsUtils.track(AnalyticEvents.VIDEO_BACKGROUND_ADDED, {
is_animated: isAnimatedBackgroundOption(a0),
is_video: a1,
is_from_tenor: a2
});
}
export function trackBackgroundOptionDeleted(a0) {
AnalyticsUtils.track(AnalyticEvents.VIDEO_BACKGROUND_DELETED, {
is_animated: isAnimatedBackgroundOption(a0)
});
}
export function getVideoBackgroundProtoFromOption(a0) {
let r14;
if (a0 == null) {
r14 = {
oneofKind: void 0
};
} else {
let r8 = a0 != null && typeof a0 === "object" && "id" in a0;
if (r8) {
let r1 = a0.type === VideoFilterType.BACKGROUND;
if (!r1) {
a0.type;
r1 = false;
}
r8 = r1;
}
r14 = r8 ? {
oneofKind: "customAsset",
customAsset: {
id: a0.id,
assetHash: a0.asset
}
} : a0 === "blur" ? {
oneofKind: "blur",
blur: {
useBlur: true
}
} : {
oneofKind: "presetOption",
presetOption: a0
};
}
return r14;
}
export function getVideoBackgroundOptionFromProto(a0, a1) {
if (a0 != null && a0.oneofKind !== void 0) {
const oneofKind = a0.oneofKind;
if (oneofKind === "customAsset") {
return {
type: VideoFilterType.BACKGROUND,
id: a0.customAsset.id,
user_id: a1,
asset: a0.customAsset.assetHash
};
}
if (oneofKind === "blur") {
return a0.blur.useBlur ? "blur" : null;
}
if (oneofKind === "presetOption") {
return a0.presetOption;
}
return void 0;
}
return null;
}