289 lines
10 KiB
TypeScript
289 lines
10 KiB
TypeScript
// Metro module 15892 (f15893).
|
|
import { useMemo } from "react";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import SoundboardStore from "./SoundboardStore";
|
|
import { DEFAULT_SOUND_GUILD_ID, EMPTY_SOUND_LIST } from "./SoundboardConstants";
|
|
import { PremiumTypes } from "../premium/PremiumConstants";
|
|
import { SoundboardSoundItemType, SoundboardSoundGridSectionType } from "./SoundboardTypes";
|
|
import { getMaxSoundboardSlots } from "../../utils/GuildBoostingUtils";
|
|
import { useSoundOrganizer, sortSoundsOldestToNewestCreationDate } from "./useSoundOrganizer";
|
|
import { useStateFromStores, useStateFromStoresArray } from "../../_bundle/Module589";
|
|
import PremiumUtils from "../../utils/PremiumUtils";
|
|
import { useSortedGuildIdsForSoundboard } from "./useSortedGuildIdsForSoundboard";
|
|
import { getManageResourcePermissions } from "../permissions/useManageResourcePermissions";
|
|
import SoundboardFrequentlyUsedExperiment from "./SoundboardFrequentlyUsedExperiment";
|
|
let _addSectionForPotentialSoundIds, $mk98061 = function() {
|
|
return (a0, a1) => ({
|
|
type: SoundboardSoundItemType.SOUND,
|
|
sound: a0,
|
|
index: a1
|
|
});
|
|
};
|
|
const createSoundItems = function createSoundItems(a0, sortSoundsFn) {
|
|
return (sortSoundsFn != null ? sortSoundsFn(a0) : a0).map($mk98061());
|
|
};
|
|
_addSectionForPotentialSoundIds = function _addSectionForPotentialSoundIds({ sections, guildIds, allSounds: allSounds2, potentialSoundIdsForSection, sectionType, sortSoundsFn }) {
|
|
const r10 = {};
|
|
let c22574_1 = r10;
|
|
for (const item of [...guildIds, DEFAULT_SOUND_GUILD_ID]) {
|
|
let r17 = allSounds2.get(item);
|
|
if (r17 == null) {
|
|
r17 = [];
|
|
}
|
|
const _loop = function _loop(a0) {
|
|
if (potentialSoundIdsForSection.find((item) => item === a0.soundId) != null) {
|
|
c22574_1[a0.soundId] = a0;
|
|
}
|
|
};
|
|
for (const item2 of r17) {
|
|
_loop(item2);
|
|
}
|
|
}
|
|
const r51 = [];
|
|
for (const item3 of potentialSoundIdsForSection) {
|
|
const r58 = r10[item3];
|
|
if (r58 != null) {
|
|
r51.push(r58);
|
|
}
|
|
}
|
|
const soundItems = createSoundItems(r51, sortSoundsFn);
|
|
if (soundItems.length > 0) {
|
|
sections.push({
|
|
key: sectionType,
|
|
categoryInfo: {
|
|
type: sectionType
|
|
},
|
|
items: soundItems
|
|
});
|
|
}
|
|
};
|
|
export default function useSoundGrid(a0) {
|
|
let isPremium, allSounds, c22575_5, c22575_6, isFetching, soundOrganizer, sortedGuildIdsForSoundboard, stateFromStoresArray, canUseSoundboardEverywhere, stateFromStores, stateFromStores2, memo, enabled;
|
|
let r4 = arguments[1];
|
|
if (r4 === void 0) {
|
|
r4 = {};
|
|
}
|
|
let filterOutEmptyCurrentGuild = r4.filterOutEmptyCurrentGuild;
|
|
if (filterOutEmptyCurrentGuild === void 0) {
|
|
filterOutEmptyCurrentGuild = false;
|
|
}
|
|
let c22575_1 = filterOutEmptyCurrentGuild;
|
|
let r11 = arguments[2];
|
|
if (r11 === void 0) {
|
|
r11 = false;
|
|
}
|
|
let c22575_2 = r11;
|
|
isPremium = void 0;
|
|
allSounds = void 0;
|
|
c22575_5 = void 0;
|
|
c22575_6 = void 0;
|
|
isFetching = void 0;
|
|
soundOrganizer = void 0;
|
|
sortedGuildIdsForSoundboard = void 0;
|
|
stateFromStoresArray = void 0;
|
|
canUseSoundboardEverywhere = void 0;
|
|
stateFromStores = void 0;
|
|
stateFromStores2 = void 0;
|
|
memo = void 0;
|
|
enabled = void 0;
|
|
const stateFromStores3 = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
|
|
isPremium = PremiumUtils.isPremium(stateFromStores3, PremiumTypes.TIER_2);
|
|
let r18, r41;
|
|
[allSounds, r18, r41, isFetching] = useStateFromStoresArray([SoundboardStore], () => [SoundboardStore.getSounds(), SoundboardStore.getFavorites(), SoundboardStore.getFrequentlyUsedSoundIds(), SoundboardStore.isFetching()]);
|
|
c22575_5 = r18;
|
|
c22575_6 = r41;
|
|
soundOrganizer = useSoundOrganizer();
|
|
sortedGuildIdsForSoundboard = useSortedGuildIdsForSoundboard(a0, false);
|
|
stateFromStoresArray = useStateFromStoresArray([GuildStore], () => {
|
|
const r4 = [];
|
|
let c28175_0 = r4;
|
|
sortedGuildIdsForSoundboard.forEach((item) => {
|
|
const guild = GuildStore.getGuild(item);
|
|
if (guild != null) {
|
|
c28175_0.push(guild);
|
|
}
|
|
});
|
|
return r4;
|
|
});
|
|
canUseSoundboardEverywhere = PremiumUtils.canUseSoundboardEverywhere(stateFromStores3);
|
|
stateFromStores = useStateFromStores([GuildStore], () => GuildStore.getGuild(a0?.guild_id));
|
|
stateFromStores2 = useStateFromStores([PermissionStore], () => getManageResourcePermissions(stateFromStores).canCreateExpressions, [stateFromStores]);
|
|
memo = useMemo(() => c22575_6.filter((item) => !c22575_5.has(item)).slice(0, 3), [r41, r18]);
|
|
enabled = SoundboardFrequentlyUsedExperiment.useConfig({
|
|
location: memo.length > 0 ? "useSoundGrid" : "useSoundGridNoFrequentlyUsed"
|
|
}).enabled;
|
|
return useMemo(() => {
|
|
let r138;
|
|
let unlockedCustomSoundCount = 0;
|
|
let lockedCustomSoundCount = 0;
|
|
const categories = [];
|
|
if (c22575_2) {
|
|
let r147 = allSounds.get(DEFAULT_SOUND_GUILD_ID);
|
|
if (r147 == null) {
|
|
r147 = EMPTY_SOUND_LIST;
|
|
}
|
|
categories.push({
|
|
key: SoundboardSoundGridSectionType.DEFAULTS,
|
|
categoryInfo: {
|
|
type: SoundboardSoundGridSectionType.DEFAULTS
|
|
},
|
|
items: (sortSoundsOldestToNewestCreationDate != null ? sortSoundsOldestToNewestCreationDate(r147) : r147).map($mk98061())
|
|
});
|
|
let availableSounds = allSounds.get(DEFAULT_SOUND_GUILD_ID);
|
|
if (availableSounds == null) {
|
|
availableSounds = EMPTY_SOUND_LIST;
|
|
}
|
|
r138 = {
|
|
categories,
|
|
availableSounds,
|
|
isFetching,
|
|
soundCounts: {
|
|
favoriteSoundCount: 0,
|
|
unlockedCustomSoundCount: 0,
|
|
lockedCustomSoundCount: 0
|
|
}
|
|
};
|
|
} else {
|
|
const r15 = Array;
|
|
_addSectionForPotentialSoundIds({
|
|
sections: categories,
|
|
guildIds: sortedGuildIdsForSoundboard,
|
|
allSounds,
|
|
potentialSoundIdsForSection: r15.from(c22575_5),
|
|
sectionType: SoundboardSoundGridSectionType.FAVORITES,
|
|
sortSoundsFn: sortSoundsOldestToNewestCreationDate
|
|
});
|
|
let r30 = enabled;
|
|
if (enabled) {
|
|
r30 = memo.length > 0;
|
|
}
|
|
if (r30) {
|
|
_addSectionForPotentialSoundIds({
|
|
sections: categories,
|
|
guildIds: sortedGuildIdsForSoundboard,
|
|
allSounds,
|
|
potentialSoundIdsForSection: memo,
|
|
sectionType: SoundboardSoundGridSectionType.FREQUENTLY_USED
|
|
});
|
|
}
|
|
if (stateFromStores !== void 0) {
|
|
let r42 = c22575_1;
|
|
let r44 = allSounds.get(stateFromStores.id);
|
|
if (r44 == null) {
|
|
r44 = [];
|
|
}
|
|
const items = (soundOrganizer != null ? soundOrganizer(r44) : r44).map($mk98061());
|
|
const r54 = r44.length < getMaxSoundboardSlots(stateFromStores) && stateFromStores2;
|
|
const r56 = items.length === 0;
|
|
if (!((r54 ? !r54 : !r56) || r42)) {
|
|
items.push({
|
|
type: SoundboardSoundItemType.ADD_SOUND,
|
|
guild: stateFromStores
|
|
});
|
|
}
|
|
if (r42) {
|
|
r42 = r56;
|
|
}
|
|
if (!r42) {
|
|
categories.push({
|
|
categoryInfo: {
|
|
type: SoundboardSoundGridSectionType.GUILD,
|
|
guild: stateFromStores,
|
|
isNitroLocked: false
|
|
},
|
|
key: stateFromStores.id,
|
|
items
|
|
});
|
|
}
|
|
}
|
|
if (!canUseSoundboardEverywhere) {
|
|
let r77 = allSounds.get(DEFAULT_SOUND_GUILD_ID);
|
|
if (r77 == null) {
|
|
r77 = EMPTY_SOUND_LIST;
|
|
}
|
|
categories.push({
|
|
key: SoundboardSoundGridSectionType.DEFAULTS,
|
|
categoryInfo: {
|
|
type: SoundboardSoundGridSectionType.DEFAULTS
|
|
},
|
|
items: (sortSoundsOldestToNewestCreationDate != null ? sortSoundsOldestToNewestCreationDate(r77) : r77).map($mk98061())
|
|
});
|
|
}
|
|
(function addGuildsSections({ sections, guilds, currentGuildId, allSounds: allSounds2, hasNitro, sortSoundsFn }) {
|
|
for (const item of guilds) {
|
|
if (item.id !== currentGuildId) {
|
|
let r39 = allSounds2.get(item.id);
|
|
if (r39 == null) {
|
|
r39 = [];
|
|
}
|
|
const items = createSoundItems(r39, sortSoundsFn);
|
|
if (items.length > 0) {
|
|
const guild = item;
|
|
sections.push({
|
|
categoryInfo: {
|
|
type: SoundboardSoundGridSectionType.GUILD,
|
|
guild,
|
|
isNitroLocked: !hasNitro
|
|
},
|
|
key: guild.id,
|
|
items
|
|
});
|
|
}
|
|
}
|
|
}
|
|
})({
|
|
sections: categories,
|
|
guilds: stateFromStoresArray,
|
|
currentGuildId: stateFromStores?.id,
|
|
allSounds,
|
|
hasNitro: isPremium,
|
|
sortSoundsFn: soundOrganizer
|
|
});
|
|
if (canUseSoundboardEverywhere) {
|
|
let r108 = allSounds.get(DEFAULT_SOUND_GUILD_ID);
|
|
if (r108 == null) {
|
|
r108 = EMPTY_SOUND_LIST;
|
|
}
|
|
categories.push({
|
|
key: SoundboardSoundGridSectionType.DEFAULTS,
|
|
categoryInfo: {
|
|
type: SoundboardSoundGridSectionType.DEFAULTS
|
|
},
|
|
items: (sortSoundsOldestToNewestCreationDate != null ? sortSoundsOldestToNewestCreationDate(r108) : r108).map($mk98061())
|
|
});
|
|
}
|
|
categories.forEach((category) => {
|
|
if (category.categoryInfo.type === SoundboardSoundGridSectionType.GUILD) {
|
|
if (category.categoryInfo.isNitroLocked) {
|
|
lockedCustomSoundCount = lockedCustomSoundCount + category.items.length;
|
|
} else {
|
|
unlockedCustomSoundCount = unlockedCustomSoundCount + category.items.length;
|
|
}
|
|
}
|
|
});
|
|
r138 = {
|
|
categories,
|
|
availableSounds: Array.from(allSounds.values()).flat(),
|
|
isFetching,
|
|
soundCounts: {
|
|
favoriteSoundCount: c22575_5.size,
|
|
unlockedCustomSoundCount,
|
|
lockedCustomSoundCount
|
|
}
|
|
};
|
|
}
|
|
return r138;
|
|
}, [sortedGuildIdsForSoundboard, allSounds, r18, enabled, stateFromStores, stateFromStores2, filterOutEmptyCurrentGuild, canUseSoundboardEverywhere, stateFromStoresArray, r11, isFetching, isPremium, soundOrganizer, memo]);
|
|
};
|
|
export function useSearchCategories(a0, a1, a2) {
|
|
return useMemo(() => a2.length > 0 ? [{
|
|
key: SoundboardSoundGridSectionType.SEARCH,
|
|
categoryInfo: {
|
|
type: SoundboardSoundGridSectionType.SEARCH
|
|
},
|
|
items: a1.map($mk98061())
|
|
}] : a0, [a0, a2.length, a1]);
|
|
}
|