Files
discord-decomp/sources/modules/soundboard/useSoundGrid.tsx
T
2026-07-27 16:20:00 +03:00

554 lines
22 KiB
TypeScript

/* Metro module 15419; source: modules/soundboard/useSoundGrid.tsx; dependencies: [57, 31, 1867, 3784, 1878, 4613, 4614, 1880, 6639, 8249, 15420, 566, 3802, 15421, 9077, 2] */
function _fun117940(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#117940, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:6, offset: 0x024c5e24, size: 312 bytes, params: 8, frame: 19
const env0_0 = require;
const _arrayLikeToArray_117943 = function(a0, a1) {
var r0;
var r1;
var r2;
var value3;
var length;
var value5;
var value = undefined;
var value2 = value == null;
reducibleJoin2: while (true) {
if (value2) {
r0 = value2;
break reducibleJoin2;
}
value3 = value > a0.length;
r0 = value3;
break reducibleJoin2;
}
reducibleJoin4: while (true) {
if (r0) {
length = a0.length;
r1 = length;
break reducibleJoin4;
}
r1 = value;
break reducibleJoin4;
}
value = (0, global.Array)(r1);
var value4 = 0;
if (value4 < r1) {
r2 = value4;
reducibleLoop5: while (true) {
value[r2] = a0[r2];
value5 = typeof r2 === 'bigint' ? r2 + 1n : +r2 + 1;
if (value5 < r1) {
r2 = value5;
continue reducibleLoop5;
}
break reducibleLoop5;
}
}
return value;
};
const createSoundItems = function(a0, a1) {
var r2;
var value = a0;
if (a1 == null) {
r2 = value;
} else {
value = a1(value);
r2 = value;
}
return r2.map(_fun117945);
};
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = importDefault(57) /* metro dependency 57 */;
const env0_4 = importAll(31) /* metro dependency 31 */;
const guildStore = importDefault(1867) /* metro dependency 1867: GuildStore */;
const permissionStore = importDefault(3784) /* metro dependency 3784: PermissionStore */;
const userStore = importDefault(1878) /* metro dependency 1878: UserStore */;
const soundboardStore = importDefault(4613) /* metro dependency 4613: SoundboardStore */;
const soundboardConstantsModule = require(4614) /* metro dependency 4614: SoundboardConstants */;
const env0_9 = soundboardConstantsModule.DEFAULT_SOUND_GUILD_ID;
const env0_10 = soundboardConstantsModule.EMPTY_SOUND_LIST;
const env0_11 = (require(1880) /* metro dependency 1880: PremiumConstants */).PremiumTypes;
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/soundboard/useSoundGrid.tsx');
exports.default = useSoundGrid;
exports.useSearchCategories = useSearchCategories;
}
function _createForOfIteratorHelperLoose_117941(a0, a1) { // fn#117941, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:244, offset: 0x024c5f5c, size: 372 bytes, params: 3, frame: 20
var r6;
var r9;
var r5;
var value3;
var regexp;
const env0_0 = a0;
const Symbol = global.Symbol;
let value = typeof Symbol !== 'undefined';
let r1 = value && a0[global.Symbol.iterator];
r1 = !r1 ? a0['@@iterator'] : r1;
if (r1) {
value = r1.call(a0);
return value.next.bind(value);
}
const Array = global.Array;
if (Array.isArray(a0)) {
if (r1) {
}
return _fun117942;
}
value = undefined;
if (a0) {
if (typeof a0 === 'string') {
value = _arrayLikeToArray_117943(a0, value);
r5 = value;
} else {
value3 = ({}).toString.call(a0).slice(8, -1);
r6 = value3 === 'Object' && a0.constructor;
r9 = r6 ? a0.constructor.name : value3;
if (r9 === 'Map') {
r6 = global.Array.from(a0);
} else if (r9 === 'Set') {
r6 = global.Array.from(a0);
} else if (r9 === 'Arguments') {
value = _arrayLikeToArray_117943(a0, value);
r6 = value;
} else {
regexp = RegExp('^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$', '');
if (regexp.test(r9)) {
value = _arrayLikeToArray_117943(a0, value);
r6 = value;
} else {
r6 = value;
}
}
r5 = r6;
}
} else {
r5 = value;
}
if (r5) {
if (r5) {
}
return _fun117942;
}
const TypeError = global.TypeError;
throw new TypeError('Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.');
}
function createSoundItems(a0, a1) { // fn#117944, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:1154, offset: 0x024c60d0, size: 43 bytes, params: 3, frame: 12
var r2;
let value = a0;
if (a1 == null) {
r2 = value;
} else {
value = a1(value);
r2 = value;
}
return r2.map(function(a0, a1) {
var object = {};
object.type = require(dependencyMap[8]).SoundboardSoundItemType.SOUND;
object.sound = a0;
object.index = a1;
return object;
});
}
function addDefaultSection(a0, a1) { // fn#117946, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:1290, offset: 0x024c6137, size: 150 bytes, params: 3, frame: 19
const r6 = a1.get(DEFAULT_SOUND_GUILD_ID) ?? EMPTY_SOUND_LIST;
const push = a0.push;
const object2 = {};
const SoundboardSoundGridSectionType = (require(6639) /* metro dependency 6639: SoundboardTypes */).SoundboardSoundGridSectionType;
let DEFAULTS = SoundboardSoundGridSectionType.DEFAULTS;
object2.key = DEFAULTS;
DEFAULTS = SoundboardSoundGridSectionType.DEFAULTS;
object2.categoryInfo = {type: DEFAULTS};
object2.items = createSoundItems(r6,
(require(15420) /* metro dependency 15420: useSoundOrganizer */).sortSoundsOldestToNewestCreationDate);
Reflect.apply(push, a0, [object2]);
}
function useSoundGrid(a0) { // fn#117947, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:1640, offset: 0x024c61cd, size: 560 bytes, params: 2, frame: 32
const value = a1;
const value2 = a2;
const env0_0 = a0;
let filterOutEmptyCurrentGuild = (value !== undefined ? value : {}).filterOutEmptyCurrentGuild;
filterOutEmptyCurrentGuild = !(filterOutEmptyCurrentGuild === undefined) && filterOutEmptyCurrentGuild;
const r7 = value2 !== undefined ? value2 : false;
const currentUser = (require(566) /* metro dependency 566: flux */).useStateFromStores([UserStore], function() {
return UserStore.getCurrentUser();
});
const defaultImport = importDefault(3802) /* metro dependency 3802: PremiumUtils */;
const isPremium = defaultImport.isPremium;
const TIER_2 = PremiumTypes.TIER_2;
const isPremium2 = Reflect.apply(isPremium, defaultImport, [currentUser, TIER_2]);
const env0_3 = isPremium2;
const fluxModule = require(566) /* metro dependency 566: flux */;
const useStateFromStoresArray = fluxModule.useStateFromStoresArray;
const value4 = env0_3(Reflect.apply(useStateFromStoresArray, fluxModule, [[SoundboardStore], _fun117949]), 3);
const property = value4[0];
const env0_4 = property;
const property2 = value4[1];
const property3 = value4[2];
const value5 = (require(15420) /* metro dependency 15420: useSoundOrganizer */).useSoundOrganizer();
const value6 = (require(15421) /* metro dependency 15421: useSortedGuildIdsForSoundboard */).useSortedGuildIdsForSoundboard(a0,
false);
const value7 = fluxModule.useStateFromStoresArray([GuildStore], _fun117950);
const canUseSoundboardEverywhere2 = defaultImport.canUseSoundboardEverywhere(currentUser);
const guild = fluxModule.useStateFromStores([GuildStore], _fun117952);
return env0_4.useMemo(_fun117954, [value6, property, property2, guild,
fluxModule.useStateFromStores([PermissionStore], _fun117953, [guild]), filterOutEmptyCurrentGuild,
canUseSoundboardEverywhere2, value7, r7, property3, isPremium2, value5]);
}
function useSearchCategories(a0, a1, a2) { // fn#117959, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:4821, offset: 0x024c6ac9, size: 71 bytes, params: 4, frame: 16
const env0_0 = a0;
const env0_1 = a1;
const env0_2 = a2;
return env0_4.useMemo(_fun117960, [a0, a2.length, a1]);
}
function _fun117949() { // fn#117949, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:1846, offset: 0x024c63fd, size: 57 bytes, params: 1, frame: 10
const value = environment.__proto__;
const items2 = [SoundboardStore.getSounds()];
const getFavorites = SoundboardStore.getFavorites;
items2[1] = Reflect.apply(getFavorites, SoundboardStore, []);
items2[2] = SoundboardStore.isFetching();
return items2;
}
function _fun117950() { // fn#117950, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:2052, offset: 0x024c6436, size: 36 bytes, params: 1, frame: 12
env0_8.forEach(_fun117951);
return [];
}
function _fun117953() { // fn#117953, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:2292, offset: 0x024c648a, size: 51 bytes, params: 1, frame: 11
let value = environment.__proto__;
value = require(9077) /* metro dependency 9077: useManageResourcePermissions */;
const getManageResourcePermissions = value.getManageResourcePermissions;
return Reflect.apply(getManageResourcePermissions, value, [guild]).canCreateExpressions;
}
function _fun117954() { // fn#117954, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:2383, offset: 0x024c64bd, size: 1039 bytes, params: 1, frame: 35
var environment;
var r10;
var r5;
var id;
var r9;
var r0;
var object5;
var Array;
var from;
var value2;
var value3;
const SoundboardSoundGridSectionType = (require(6639) /* metro dependency 6639: SoundboardTypes */).SoundboardSoundGridSectionType;
var guildBinding;
var object6;
var currentGuildHasAddPermissions;
var allSounds;
var filterOutEmptyCurrentGuild2;
var sortSoundsFn;
var get;
var createSoundItemsBinding;
var soundItems;
var length;
var moduleValue;
var value6;
var push;
var object8;
var GUILD;
var object9;
var sections;
var guilds;
var currentGuildId;
var hasNitro;
var value9;
var value10;
var done;
var value11;
var value12;
var soundItems2;
var value13;
var object12;
var binding;
var value15;
var object13;
const env0_0 = 0;
const env0_1 = 0;
const items = [];
if (env0_2) {
value15 = environment.__proto__;
addDefaultSection(items, env0_4);
object13 = {categories: items};
object13.availableSounds = env0_4.get(DEFAULT_SOUND_GUILD_ID) ?? EMPTY_SOUND_LIST;
object13.isFetching = env0_6;
object13.soundCounts = {'favoriteSoundCount': 0, 'unlockedCustomSoundCount': 0, 'lockedCustomSoundCount': 0};
r0 = object13;
} else {
object5 = {sections: items, guildIds: env0_8, allSounds: env0_4};
Array = global.Array;
object5.potentialSoundIdsForSection = Array.from(env0_5);
value2 = environment.__proto__;
value3 = undefined;
object5.sectionType = SoundboardSoundGridSectionType.FAVORITES;
object5.sortSoundsFn = (require(15420) /* metro dependency 15420: useSoundOrganizer */).sortSoundsOldestToNewestCreationDate;
_addSectionForPotentialSoundIds(object5);
guildBinding = guild;
if (value3 !== guildBinding) {
guildBinding = guild;
object6 = {currentGuildHasAddPermissions: env0_12, allSounds: env0_4};
object6.filterOutEmptyCurrentGuild = filterOutEmptyCurrentGuild;
object6.sortSoundsFn = env0_7;
currentGuildHasAddPermissions = object6.currentGuildHasAddPermissions;
allSounds = object6.allSounds;
filterOutEmptyCurrentGuild2 = object6.filterOutEmptyCurrentGuild;
sortSoundsFn = object6.sortSoundsFn;
r10 = allSounds.get(guildBinding.id) ?? [];
soundItems = createSoundItems(r10, sortSoundsFn);
length = r10.length;
moduleValue = require(8249) /* metro dependency 8249: GuildBoostingUtils */;
r10 = length < moduleValue.getMaxSoundboardSlots(guildBinding) && currentGuildHasAddPermissions;
length = soundItems.length;
value6 = length === 0;
r10 = !r10 && !value6;
r10 = !r10 ? filterOutEmptyCurrentGuild2 : r10;
if (!r10) {
push = soundItems.push;
object8 = {};
object8.type = (require(6639) /* metro dependency 6639: SoundboardTypes */).SoundboardSoundItemType.ADD_SOUND;
object8.guild = guildBinding;
Reflect.apply(push, soundItems, [object8]);
}
if (!(filterOutEmptyCurrentGuild2 && value6)) {
push = items.push;
GUILD = SoundboardSoundGridSectionType.GUILD;
Reflect.apply(push, items, [{categoryInfo: {type: GUILD, guild: guildBinding, isNitroLocked: false},
key: guildBinding.id, items: soundItems}]);
}
}
if (!env0_10) {
addDefaultSection(items, env0_4);
}
object9 = {sections: items, guilds: env0_9};
id = guild == null ? value3 : guild.id;
object9.currentGuildId = id;
object9.allSounds = env0_4;
object9.hasNitro = env0_3;
object9.sortSoundsFn = env0_7;
sections = object9.sections;
guilds = object9.guilds;
currentGuildId = object9.currentGuildId;
allSounds = object9.allSounds;
hasNitro = object9.hasNitro;
sortSoundsFn = object9.sortSoundsFn;
value9 = _createForOfIteratorHelperLoose_117941(guilds);
value10 = value9();
done = value10.done;
if (!done) {
r9 = value10;
while (true) {
value11 = r9.value;
id = value11.id;
if (id !== currentGuildId) {
createSoundItemsBinding = createSoundItems;
get = allSounds.get;
id = value11.id;
value12 = Reflect.apply(get, allSounds, [id]);
if (value12 != null) {
r5 = value12;
continue;
}
soundItems2 = createSoundItemsBinding([], sortSoundsFn);
length = soundItems2.length;
if (length > 0) {
push = sections.push;
GUILD = SoundboardSoundGridSectionType.GUILD;
id = value11.id;
Reflect.apply(push, sections, [{categoryInfo: {type: GUILD, guild: value11,
isNitroLocked: !hasNitro},
key: id,
items: soundItems2}]);
break;
}
break;
}
value13 = value9();
done = value13.done;
if (done) {
break;
}
r9 = value13;
continue;
}
}
if (env0_10) {
addDefaultSection(items, env0_4);
}
items.forEach(_fun117958);
object12 = {categories: items};
Array = global.Array;
from = Array.from;
binding = env0_4;
object12.availableSounds = Reflect.apply(from, Array, [binding.values()]).flat();
object12.isFetching = env0_6;
object12.soundCounts = {favoriteSoundCount: env0_5.size, unlockedCustomSoundCount: env0_0,
lockedCustomSoundCount: env0_1};
r0 = object12;
}
return r0;
}
function _fun117960() { // fn#117960, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:4875, offset: 0x024c6b10, size: 130 bytes, params: 1, frame: 17
var r0;
var object2;
var value2;
const SoundboardSoundGridSectionType = (require(6639) /* metro dependency 6639: SoundboardTypes */).SoundboardSoundGridSectionType;
var SEARCH;
if (importDefault.length > 0) {
object2 = {};
value2 = environment.__proto__;
SEARCH = SoundboardSoundGridSectionType.SEARCH;
object2.key = SEARCH;
SEARCH = SoundboardSoundGridSectionType.SEARCH;
object2.categoryInfo = {type: SEARCH};
object2.items = createSoundItems(require);
r0 = [object2];
} else {
r0 = env0_0;
}
return r0;
}
function _fun117951(a0) { // fn#117951, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:2084, offset: 0x024c645a, size: 48 bytes, params: 2, frame: 11
let value = environment.__proto__.__proto__;
value = GuildStore.getGuild(a0);
if (value != null) {
env0_0.push(value);
}
}
function _addSectionForPotentialSoundIds({sections, guildIds, allSounds, potentialSoundIdsForSection, sectionType, sortSoundsFn}) { // fn#117955, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:2596, offset: 0x024c68cc, size: 306 bytes, params: 2, frame: 28
var r7;
var r4;
var r14;
var r8;
var property;
var closure;
var _createForOfIteratorHelperLoose_117941Binding;
var get;
var value4;
var value5;
var value6;
var done;
var value7;
var value8;
var value9;
var value12;
var push;
var value13;
const object2 = {};
const items2 = [];
const value2 = arraySpread(items2, guildIds, 0, undefined);
items2[value2] = DEFAULT_SOUND_GUILD_ID;
value2 + 1;
let length = items2.length;
if (0 < length) {
r7 = 0;
reducibleLoop1: while (true) {
property = items2[r7];
closure = _addSectionForPotentialSoundIds_loop;
_createForOfIteratorHelperLoose_117941Binding = _createForOfIteratorHelperLoose_117941;
get = allSounds.get;
value4 = Reflect.apply(get, allSounds, [property]);
reducibleJoin3: while (true) {
if (value4 != null) {
r4 = value4;
break reducibleJoin3;
}
r4 = [];
break reducibleJoin3;
}
value5 = _createForOfIteratorHelperLoose_117941Binding(r4);
value6 = value5();
done = value6.done;
if (!done) {
r14 = value6;
reducibleLoop4: while (true) {
value7 = r14.value;
closure(value7);
value8 = value5();
done = value8.done;
if (done) {
break reducibleLoop4;
}
r14 = value8;
continue reducibleLoop4;
}
}
value9 = typeof r7 === 'bigint' ? r7 + 1n : +r7 + 1;
length = items2.length;
if (value9 < length) {
r7 = value9;
continue reducibleLoop1;
}
break reducibleLoop1;
}
}
const items3 = [];
const value10 = _createForOfIteratorHelperLoose_117941(potentialSoundIdsForSection);
const value11 = value10();
done = value11.done;
if (!done) {
r8 = value11;
reducibleLoop7: while (true) {
value12 = r8.value;
property = object2[value12];
reducibleJoin9: while (true) {
if (property == null) {
break reducibleJoin9;
}
push = items3.push;
Reflect.apply(push, items3, [property]);
break reducibleJoin9;
}
value13 = value10();
done = value13.done;
if (done) {
break reducibleLoop7;
}
r8 = value13;
continue reducibleLoop7;
}
}
const soundItems = createSoundItems(items3, sortSoundsFn);
reducibleJoin12: while (true) {
if (soundItems.length > 0) {
push = sections.push;
Reflect.apply(push, sections, [{key: sectionType, categoryInfo: {type: sectionType}, items: soundItems}]);
break reducibleJoin12;
}
break reducibleJoin12;
}
}
function _fun117958(a0) { // fn#117958, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:4458, offset: 0x024c6a4e, size: 123 bytes, params: 2, frame: 13
const type = a0.categoryInfo.type;
const SoundboardSoundGridSectionType = (require(6639) /* metro dependency 6639: SoundboardTypes */).SoundboardSoundGridSectionType;
const GUILD = SoundboardSoundGridSectionType.GUILD;
if (type === GUILD) {
if (a0.categoryInfo.isNitroLocked) {
env0_1 = env0_1 + a0.items.length;
} else {
env0_0 = env0_0 + a0.items.length;
}
}
}
function _addSectionForPotentialSoundIds_loop(a0) { // fn#117956, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:2801, owner: _addSectionForPotentialSoundIds._loop, offset: 0x024c69fe, size: 58 bytes, params: 2, frame: 13
const env0_0 = a0;
if (potentialSoundIdsForSection.find(_fun117957) != null) {
env0_1[a0.soundId] = a0;
}
}
function _fun117957(a0) { // fn#117957, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:15616:2827, offset: 0x024c6a38, size: 22 bytes, params: 2, frame: 2
return a0 === env0_0.soundId;
}