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

228 lines
8.5 KiB
TypeScript

// Metro module 10776 (f10777).
import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore";
import { SILENT_JOIN_LEAVE_CHANNEL_TYPES } from "../../records/ChannelRecord";
import PermissionStore from "../../stores/PermissionStore";
import UserStore from "../../stores/UserStore";
import SoundboardStore from "./SoundboardStore";
import { DEFAULT_SOUND_GUILD_ID, CUSTOM_CALL_SOUND_GLOBAL_GUILD_ID } from "./SoundboardConstants";
import { Permissions, AnalyticEvents } from "../../Constants";
import { ExpressionPickerViewType } from "../expression_picker/ExpressionPickerConstants";
import { SoundboardSettings } from "../user_settings/UserSettings";
import PremiumUtils from "../../utils/PremiumUtils";
import { getMuteStates } from "../video_calls/useMuteStates";
import { playSoundLocally, maybeFetchSoundboardSounds } from "./SoundboardActionCreators";
import { LocalSoundTrigger, AnalyticsChangeType, AnalyticsSoundType, AnalyticsSoundSource } from "./SoundboardTypes";
import { sendVoiceChannelCustomCallSoundEffect, sendVoiceChannelSoundboardEffect } from "../voice_channel_effects/VoiceChannelEffectsActionCreators";
import Dispatcher from "../../Dispatcher";
import getCurrentVoiceChannel from "../rpc/helpers/getCurrentVoiceChannel";
import { getCustomJoinSound } from "./useCustomJoinSound";
import { canSelectedVoiceChannelUseSoundboard } from "./canChannelUseSoundboard";
import { useStateFromStores } from "../../_bundle/defaultAreStatesEqual";
import { ageEligibleForPremiumUpsell } from "../../utils/UserUtils";
import { DismissibleContent } from "../../_bundle/Module1358";
import { updateUserGuildSettings, UserSettingsDelay } from "../user_settings/UserSettingsProtoActionCreators";
import AnalyticsUtils from "../../utils/AnalyticsUtils";
import AppAnalyticsUtils from "../app_analytics/AppAnalyticsUtils";
function $mk85512() {
return (a0) => a0.joinSound != null;
}
function $mk116049($env) {
return function playCustomJoinSound(a0, a1) {
playSoundLocally(a1, a0, LocalSoundTrigger.JOINED_VOICE_CHANNEL);
sendVoiceChannelCustomCallSoundEffect(a1, a0, false);
};
}
let canUseSoundboardSound, canMakeSound;
let env7239 = {};
export function hasPermissionToPlaySound(a0, a1) {
return a1?.guild_id == null || PermissionStore.can(Permissions.USE_EXTERNAL_SOUNDS, a1) || a0.guildId === DEFAULT_SOUND_GUILD_ID || a0.guildId === a1?.guild_id;
}
canUseSoundboardSound = function canUseSoundboardSound(a0, a1, a2, r6 = true) {
return (PremiumUtils.canUseSoundboardEverywhere(a0) || a1.guildId === a2?.guild_id || a1.guildId === DEFAULT_SOUND_GUILD_ID) && (a2?.guild_id == null || PermissionStore.can(Permissions.USE_EXTERNAL_SOUNDS, a2) || a1.guildId === DEFAULT_SOUND_GUILD_ID || a1.guildId === a2?.guild_id) && (r6 ? a1.available : !r6);
};
canMakeSound = function canMakeSound(a0) {
const muteStates = getMuteStates({
channel: a0
});
const { mute, suppress } = muteStates;
return mute ? !mute : !suppress;
};
export function getAmplitudinalSoundboardVolume() {
let r12 = SoundboardSettings.getSetting()?.volume;
if (r12 == null) {
r12 = 100;
}
return r12;
}
export { canUseSoundboardSound };
export { canMakeSound };
export function playSound(a0, a1, a2, a3) {
playSoundLocally(a1, a0, LocalSoundTrigger.SOUNDBOARD);
sendVoiceChannelSoundboardEffect(a1, a0, false, a2, a3);
Dispatcher.dispatch({
type: "SOUNDBOARD_TRACK_USAGE",
soundId: a0.soundId
});
}
export function hasSetAnyCustomJoinSound() {
let r5 = UserSettingsProtoStore.settings.guilds?.guilds;
if (r5 == null) {
r5 = {};
}
return Object.values(r5).some($mk85512());
}
export async function maybePlayCustomJoinSound(c26811_0) {
let r98;
let c26811_1, c26811_2;
L26: {
L25: {
L24: {
let env30288;
const r17 = env7239;
c26811_2 = r17;
const r12 = env30288 = {
$parent: r17
};
c26811_1 = r12;
env30288[0] = void 0;
env30288[1] = void 0;
env30288[2] = void 0;
env30288[3] = void 0;
env30288[4] = void 0;
const currentUser = UserStore.getCurrentUser();
env30288[0] = currentUser;
const currentVoiceChannel = getCurrentVoiceChannel();
env30288[1] = currentVoiceChannel;
const customJoinSound = getCustomJoinSound(c26811_0);
env30288[2] = customJoinSound;
if (currentVoiceChannel == null) {
break L26;
}
if (SILENT_JOIN_LEAVE_CHANNEL_TYPES.has(currentVoiceChannel.type)) {
break L26;
}
if (customJoinSound == null) {
break L26;
}
if (!PremiumUtils.canUseCustomCallSounds(currentUser)) {
break L26;
}
if (!canSelectedVoiceChannelUseSoundboard()) {
break L26;
}
await maybeFetchSoundboardSounds();
env30288[3] = env30288[2].guildId === CUSTOM_CALL_SOUND_GLOBAL_GUILD_ID ? DEFAULT_SOUND_GUILD_ID : env30288[2].guildId;
env30288[4] = SoundboardStore.getSound(env30288[3], env30288[2].soundId);
if (env30288[4] == null) {
break L25;
}
const r97 = (0, hasPermissionToPlaySound)(env30288[4], env30288[1]);
r98 = null;
if (!r97) {
break L24;
}
const r103 = (0, canUseSoundboardSound)(env30288[0], env30288[4], env30288[1], true);
r98 = null;
if (!r103) {
break L24;
}
const r108 = (0, canMakeSound)(env30288[1]);
r98 = null;
if (!r108) {
break L24;
}
const r110 = env30288[4];
const id = env30288[1].id;
$mk116049(env7239)(r110, id);
r98 = void 0;
}
return r98;
}
return void 0;
}
}
export function useSoundBoardDismissContentTypes({ isSoundboardButtonDisabled }) {
if (isSoundboardButtonDisabled === void 0) {
isSoundboardButtonDisabled = false;
}
const stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
const r15 = [];
if (!isSoundboardButtonDisabled) {
let r19 = UserSettingsProtoStore.settings.guilds?.guilds;
if (r19 == null) {
r19 = {};
}
if (!Object.values(r19).some($mk85512())) {
const r30 = ageEligibleForPremiumUpsell(stateFromStores);
if (PremiumUtils.canUseCustomCallSounds(stateFromStores) || r30) {
r15.push(DismissibleContent.CUSTOM_CALL_SOUNDS_PICKER_UPSELL);
}
}
}
return r15;
}
export function removeCustomJoinSound(a0, location2) {
const guildId = a0;
updateUserGuildSettings(a0, (a0) => {
a0.joinSound = void 0;
const r3 = {
guildId,
changeType: AnalyticsChangeType.REMOVED,
soundType: AnalyticsSoundType.ENTRY,
location: location2
};
const { guildId: guildId2, changeType, soundType, soundSource } = r3;
AnalyticsUtils.track(AnalyticEvents.USER_CUSTOM_CALL_SOUND_SETTING_UPDATED, {
location_stack: r3.location,
guild_id: guildId2 !== "" ? Number(guildId2) : 0,
change_type: changeType,
sound_type: soundType,
sound_source: soundSource
});
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
}
export function updateCustomJoinSound(a0, c18257_1, location_stack) {
let c18257_0 = a0;
updateUserGuildSettings(a0, (a0) => {
let r8, r16, DEFAULT;
const r2 = c18257_1.guildId === DEFAULT_SOUND_GUILD_ID;
if (r2) {
DEFAULT = AnalyticsSoundSource.DEFAULT;
r16 = dependencyMap;
r8 = require;
} else {
DEFAULT = AnalyticsSoundSource.CUSTOM;
r16 = dependencyMap;
r8 = require;
}
const change_type = a0.joinSound != null ? r8(r16[13]).AnalyticsChangeType.UPDATED : r8(r16[13]).AnalyticsChangeType.ADDED;
a0.joinSound = {
soundId: c18257_1.soundId,
guildId: r2 ? CUSTOM_CALL_SOUND_GLOBAL_GUILD_ID : c18257_1.guildId
};
const ENTRY = r8(r16[13]).AnalyticsSoundType.ENTRY;
importDefault(r16[23]).track(AnalyticEvents.USER_CUSTOM_CALL_SOUND_SETTING_UPDATED, {
location_stack,
guild_id: c18257_0 !== "" ? Number(c18257_0) : 0,
change_type,
sound_type: ENTRY,
sound_source: DEFAULT
});
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
}
export function trackCustomCallSoundExternallyDeleted(a0) {
AnalyticsUtils.track(AnalyticEvents.USER_CUSTOM_CALL_SOUND_SETTING_GUILD_REMOVED, {
location_stack: a0.location
});
}
export function trackSoundFavorited(a0) {
const sound = a0.sound;
AppAnalyticsUtils.trackWithMetadata(AnalyticEvents.EXPRESSION_FAVORITED, {
location: a0.location,
expression_type: ExpressionPickerViewType.SOUNDBOARD,
expression_id: sound.soundId,
expression_name: sound.name,
expression_guild_id: sound.guildId
});
}