312 lines
9.0 KiB
TypeScript
312 lines
9.0 KiB
TypeScript
// Metro module 8048 (f8049).
|
|
import SoundboardStore from "./SoundboardStore";
|
|
import { DEFAULT_SOUND_GUILD_ID } from "./SoundboardConstants";
|
|
import { Endpoints, AnalyticEvents } from "../../Constants";
|
|
import { MAX_FAVORITES, UserSettingsDelay } from "../user_settings/UserSettingsConstants";
|
|
import { HTTP, rejectWithMigratedError } from "../../_bundle/sendRequest";
|
|
import { soundboardSoundFromAPI } from "./SoundboardTypes";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import { captureOrIgnoreApiError } from "../errors/ErrorHandlingUtils";
|
|
import APIError from "../../errors/APIError";
|
|
import { getGuildIdsToFetchSoundsFor } from "./useGuildIdsToFetchSoundsFor";
|
|
import AnalyticsUtils from "../../utils/AnalyticsUtils";
|
|
import { FrecencyUserSettingsActionCreators } from "../user_settings/UserSettingsProtoActionCreators";
|
|
import Module12 from "../../_bundle/Module12";
|
|
import AlertActionCreators from "../../actions/AlertActionCreators";
|
|
import { intl, t } from "../../intl/index.native";
|
|
import { makeDiscoverableGuild } from "../../utils/GuildDiscoveryUtils";
|
|
function $mk79754($env) {
|
|
return (a0) => {
|
|
let env26092 = {
|
|
$parent: $env
|
|
};
|
|
env26092[0] = a0;
|
|
const r6 = $env.$parent;
|
|
const r4 = (0, r6[1])(r6[2][7]);
|
|
const r10 = $env[0];
|
|
const onSoundboardActionCompleted = function onSoundboardActionCompleted() {
|
|
const r3 = env26092.$parent.$parent;
|
|
(0, r3[1])(r3[2][7]).unsubscribe(env26092.$parent[0], env26092[1]);
|
|
setTimeout(env26092[0], 0);
|
|
};
|
|
env26092[1] = onSoundboardActionCompleted;
|
|
r4.subscribe(r10, onSoundboardActionCompleted);
|
|
};
|
|
}
|
|
function $mk115098($env) {
|
|
return (a0) => soundboardSoundFromAPI(a0, DEFAULT_SOUND_GUILD_ID);
|
|
}
|
|
let _maybeFetchDefaultSounds, _maybeFetchGuildSoundboardSounds;
|
|
let env5100 = {};
|
|
env5100[11] = function _fetchDefaultSoundsFromApi2() {
|
|
const r8 = async () => {
|
|
let c26091_0, c26091_1, c26091_2;
|
|
let c26091_3 = 0;
|
|
const r10 = env5100;
|
|
L10: {
|
|
try {
|
|
let env29881;
|
|
c26091_1 = r10;
|
|
const r26 = env29881 = {
|
|
$parent: r10
|
|
};
|
|
c26091_0 = r26;
|
|
env29881[0] = void 0;
|
|
c26091_3 = 1;
|
|
env29881[0] = (await HTTP.get({
|
|
url: Endpoints.SOUNDBOARD_DEFAULT_SOUNDS,
|
|
rejectWithError: rejectWithMigratedError()
|
|
})).body.map($mk115098(env5100));
|
|
Dispatcher.dispatch({
|
|
type: "SOUNDBOARD_FETCH_DEFAULT_SOUNDS_SUCCESS",
|
|
soundboardSounds: env29881[0]
|
|
});
|
|
c26091_3 = 0;
|
|
} catch ($e) {
|
|
const r24 = $e;
|
|
let r7 = r24;
|
|
c26091_2 = r24;
|
|
if (c26091_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r77 = c26091_2;
|
|
c26091_3 = 0;
|
|
env29881[1] = r77;
|
|
Dispatcher.dispatch({
|
|
type: "SOUNDBOARD_FETCH_DEFAULT_SOUNDS_FAILURE"
|
|
});
|
|
captureOrIgnoreApiError(new APIError(env29881[1]));
|
|
break L10;
|
|
} catch (r73) {
|
|
r7 = r73;
|
|
c26091_2 = r73;
|
|
if (c26091_3 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
};
|
|
env5100[11] = r8;
|
|
return r8.apply(this, arguments);
|
|
};
|
|
_maybeFetchDefaultSounds = function _maybeFetchDefaultSounds() {
|
|
if (SoundboardStore.shouldFetchDefaultSounds()) {
|
|
let env16214;
|
|
Dispatcher.dispatch({
|
|
type: "SOUNDBOARD_FETCH_DEFAULT_SOUNDS"
|
|
});
|
|
const r18 = env16214 = {
|
|
$parent: env5100
|
|
};
|
|
env16214[0] = "SOUNDBOARD_FETCH_DEFAULT_SOUNDS_SUCCESS";
|
|
const promise = new Promise($mk79754(r18));
|
|
(function _fetchDefaultSoundsFromApi() {
|
|
return env5100[11].apply(this, arguments);
|
|
})();
|
|
return promise;
|
|
}
|
|
return Promise.resolve();
|
|
};
|
|
_maybeFetchGuildSoundboardSounds = function _maybeFetchGuildSoundboardSounds() {
|
|
const guildIdsToFetchSoundsFor = getGuildIdsToFetchSoundsFor();
|
|
if (guildIdsToFetchSoundsFor.length === 0) {
|
|
return Promise.resolve();
|
|
}
|
|
let env16215;
|
|
const r15 = env16215 = {
|
|
$parent: env5100
|
|
};
|
|
env16215[0] = "SOUNDBOARD_SOUNDS_RECEIVED";
|
|
const promise = new Promise($mk79754(r15));
|
|
Dispatcher.dispatch({
|
|
type: "GUILD_SOUNDBOARD_FETCH"
|
|
});
|
|
Dispatcher.dispatch({
|
|
type: "REQUEST_SOUNDBOARD_SOUNDS",
|
|
guildIds: guildIdsToFetchSoundsFor
|
|
});
|
|
return promise;
|
|
};
|
|
env5100[10] = false;
|
|
export async function maybeFetchSoundboardSounds(c26093_0) {
|
|
let disableAnalytics;
|
|
let c29882_3;
|
|
c29882_3 = void 0;
|
|
let c29882_0 = performance.now();
|
|
const r29 = env5100[10];
|
|
let r30 = !r29;
|
|
if (!r29) {
|
|
const disableAnalytics2 = c26093_0?.disableAnalytics;
|
|
disableAnalytics = disableAnalytics2;
|
|
if (disableAnalytics2 == null) {
|
|
disableAnalytics = false;
|
|
}
|
|
r30 = !disableAnalytics;
|
|
}
|
|
let c29882_1 = r30;
|
|
if (r30) {
|
|
env5100[10] = true;
|
|
}
|
|
let c29882_2 = await Promise.all([_maybeFetchDefaultSounds(), _maybeFetchGuildSoundboardSounds()]);
|
|
if (c29882_1) {
|
|
c29882_3 = performance.now();
|
|
AnalyticsUtils.track(AnalyticEvents.EXPRESSION_PICKER_SOUNDBOARD_SOUNDS_LOADED, {
|
|
elapsed_ms: c29882_3 - c29882_0
|
|
});
|
|
}
|
|
return c29882_2;
|
|
}
|
|
export async function uploadSound(c26094_0) {
|
|
let c29883_0 = c26094_0.guildId;
|
|
let c29883_1 = c26094_0.name;
|
|
let c29883_2 = c26094_0.sound;
|
|
let c29883_3 = c26094_0.volume;
|
|
let c29883_4 = c26094_0.emojiId;
|
|
let c29883_5 = c26094_0.emojiName;
|
|
await void 0;
|
|
let c29883_6 = await HTTP.post({
|
|
url: Endpoints.GUILD_SOUNDBOARD_SOUNDS(c29883_0),
|
|
body: {
|
|
name: c29883_1,
|
|
sound: c29883_2,
|
|
volume: c29883_3,
|
|
emoji_id: c29883_4,
|
|
emoji_name: c29883_5
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
return soundboardSoundFromAPI(c29883_6.body, c29883_0);
|
|
}
|
|
export async function updateSound(c26095_0) {
|
|
let c29884_0 = c26095_0.guildId;
|
|
let c29884_1 = c26095_0.soundId;
|
|
let c29884_2 = c26095_0.name;
|
|
let c29884_3 = c26095_0.volume;
|
|
let c29884_4 = c26095_0.emojiId;
|
|
let c29884_5 = c26095_0.emojiName;
|
|
await void 0;
|
|
let c29884_6 = await HTTP.patch({
|
|
url: Endpoints.GUILD_SOUNDBOARD_SOUND(c29884_0, c29884_1),
|
|
body: {
|
|
name: c29884_2,
|
|
volume: c29884_3,
|
|
emoji_id: c29884_4,
|
|
emoji_name: c29884_5
|
|
},
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
return soundboardSoundFromAPI(c29884_6.body, c29884_0);
|
|
}
|
|
export async function deleteSound(c26096_0, c26096_1) {
|
|
await HTTP.del({
|
|
url: Endpoints.GUILD_SOUNDBOARD_SOUND(c26096_0, c26096_1),
|
|
oldFormErrors: true,
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
}
|
|
export function addFavoriteSound(c16216_0) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteSoundboardSounds", (a0) => {
|
|
let r0;
|
|
if (Module12.size(a0.soundIds) >= MAX_FAVORITES) {
|
|
AlertActionCreators.show({
|
|
title: intl.string(t["+XYXtZ"]),
|
|
body: intl.formatToPlainString(t.JaIyFi, {
|
|
count: MAX_FAVORITES
|
|
})
|
|
});
|
|
r0 = false;
|
|
} else {
|
|
const soundIds = a0.soundIds;
|
|
const r18 = soundIds.includes(c16216_0);
|
|
r0 = !r18;
|
|
if (!r18) {
|
|
a0.soundIds.push(c16216_0);
|
|
r0 = void 0;
|
|
}
|
|
}
|
|
return r0;
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|
|
export function removeFavoriteSound(c16217_0) {
|
|
FrecencyUserSettingsActionCreators.updateAsync("favoriteSoundboardSounds", (a0) => {
|
|
a0.soundIds = a0.soundIds.filter((soundId) => soundId !== c16217_0);
|
|
}, UserSettingsDelay.INFREQUENT_USER_ACTION);
|
|
}
|
|
export async function fetchSoundGuildData(c26097_0, c26097_1) {
|
|
let r65;
|
|
let c26097_4;
|
|
let c26097_5 = 0;
|
|
let c29885_0, c29885_1;
|
|
try {
|
|
c29885_0 = void 0;
|
|
c26097_5 = 1;
|
|
c29885_0 = await HTTP.get({
|
|
url: Endpoints.SOUNDBOARD_SOUND_GUILD_DATA(c26097_0, c26097_1),
|
|
rejectWithError: rejectWithMigratedError()
|
|
});
|
|
r65 = c29885_0.body != null ? makeDiscoverableGuild(c29885_0.body) : null;
|
|
c26097_5 = 0;
|
|
} catch ($e) {
|
|
const r29 = $e;
|
|
let r8 = r29;
|
|
c26097_4 = r29;
|
|
if (c26097_5 !== 0) {
|
|
while (true) {
|
|
try {
|
|
const r83 = c26097_4;
|
|
c26097_5 = 0;
|
|
c29885_1 = r83;
|
|
throw new APIError(c29885_1);
|
|
} catch (r79) {
|
|
r8 = r79;
|
|
c26097_4 = r79;
|
|
if (c26097_5 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r65;
|
|
}
|
|
export function playSoundLocally(a0, a1, a2) {
|
|
Dispatcher.dispatch({
|
|
type: "GUILD_SOUNDBOARD_SOUND_PLAY_LOCALLY",
|
|
sound: a1,
|
|
channelId: a0,
|
|
trigger: a2
|
|
});
|
|
}
|
|
export function reportSoundStartedPlaying(a0, a1) {
|
|
Dispatcher.dispatch({
|
|
type: "GUILD_SOUNDBOARD_SOUND_PLAY_START",
|
|
soundId: a0,
|
|
userId: a1
|
|
});
|
|
}
|
|
export function reportSoundFinishedPlaying(a0, a1) {
|
|
Dispatcher.dispatch({
|
|
type: "GUILD_SOUNDBOARD_SOUND_PLAY_END",
|
|
soundId: a0,
|
|
userId: a1
|
|
});
|
|
}
|
|
export function updateUserSoundboardVolume(a0, a1) {
|
|
Dispatcher.dispatch({
|
|
type: "USER_SOUNDBOARD_SET_VOLUME",
|
|
volume: a0,
|
|
location: a1
|
|
});
|
|
}
|
|
export function muteCustomJoinSound(a0) {
|
|
Dispatcher.dispatch({
|
|
type: "SOUNDBOARD_MUTE_JOIN_SOUND",
|
|
channelId: a0
|
|
});
|
|
}
|