442 lines
16 KiB
TypeScript
442 lines
16 KiB
TypeScript
// Metro module 9619 (f9620).
|
|
import { useMemo, useEffect, useState, useRef } from "react";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import SelectedGuildStore from "../../stores/SelectedGuildStore";
|
|
import SortedGuildStore from "../../stores/SortedGuildStore";
|
|
import UserStore from "../../stores/UserStore";
|
|
import StickersPersistedStore from "./StickersPersistedStore";
|
|
import StickersStore from "./StickersStore";
|
|
import { Permissions } from "../../Constants";
|
|
import { useStateFromStoresArray, useStateFromStoresObject, useStateFromStores } from "../../_bundle/Module589";
|
|
import { fetchStickerPacks, fetchStickerPack, fetchSticker } from "./StickersActionCreators";
|
|
import { AnimateStickers } from "../user_settings/UserSettings";
|
|
import * as _StickersUtils from "./StickersUtils";
|
|
import { createStickerPackCategory, isStandardSticker, shouldAnimateSticker } from "./StickersUtils";
|
|
import { getManageResourcePermissions } from "../permissions/useManageResourcePermissions";
|
|
import { StickerCategoryTypes, StickerGridItemTypes } from "./StickersTypes";
|
|
import { getTotalStickerCountForTier } from "../../utils/GuildBoostingUtils";
|
|
import { intl, t } from "../../intl/index.native";
|
|
import { can } from "../../utils/PermissionUtils";
|
|
import { useFrecencySettings } from "../user_settings/FrecencyUserSettingsHooks";
|
|
import { getStickerSendability, StickerSendability } from "./StickerSendability";
|
|
import { HermesBuiltin } from "../../_hermes/prelude";
|
|
function $mk82898($env) {
|
|
return () => {
|
|
const r3 = $env[0];
|
|
const r4 = $env.$parent;
|
|
return r3.map($mk106566(r4)).filter($mk106567(r4));
|
|
};
|
|
}
|
|
function $mk106566($env) {
|
|
return (a0) => $env[11].getStickerById(a0);
|
|
}
|
|
function $mk106567($env) {
|
|
return (a0) => {
|
|
let r1 = a0 != null;
|
|
if (r1) {
|
|
const r2 = $env;
|
|
const r4 = r2[0];
|
|
const r3 = r2[2];
|
|
const isGuildSticker = r4(r3[13]).isGuildSticker(a0);
|
|
r1 = isGuildSticker ? r4(r3[13]).isAvailableGuildSticker(a0) : !isGuildSticker;
|
|
}
|
|
return r1;
|
|
};
|
|
}
|
|
let c6359_13;
|
|
let $mk82897 = function() {
|
|
return () => {
|
|
fetchStickerPacks();
|
|
};
|
|
};
|
|
let env6359 = {};
|
|
export function useStickerPackCategories(a0) {
|
|
let packs, frequentlyUsedStickers, stateFromStores, memo;
|
|
let r12 = useFrecencySettings().favoriteStickers?.stickerIds;
|
|
if (r12 == null) {
|
|
r12 = c6359_13;
|
|
}
|
|
let env17350;
|
|
let context, stateFromStores2, stateFromStoresArray2, stateFromStores3;
|
|
const r23 = env17350 = {
|
|
$parent: env6359
|
|
};
|
|
env17350[0] = r12;
|
|
const stateFromStoresArray = useStateFromStoresArray([StickersStore], $mk82898(r23), [r12]);
|
|
const stateFromStoresObject = useStateFromStoresObject([StickersStore, StickersPersistedStore], () => ({
|
|
packs: StickersStore.getPremiumPacks(),
|
|
frequentlyUsedStickers: StickersPersistedStore.stickerFrecencyWithoutFetchingLatest.frequently
|
|
}), []);
|
|
packs = stateFromStoresObject.packs;
|
|
frequentlyUsedStickers = stateFromStoresObject.frequentlyUsedStickers;
|
|
stateFromStores = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
|
|
context = a0;
|
|
stateFromStores2 = void 0;
|
|
stateFromStoresArray2 = void 0;
|
|
stateFromStores3 = void 0;
|
|
stateFromStores2 = useStateFromStores([StickersStore], () => StickersStore.getAllGuildStickers());
|
|
stateFromStoresArray2 = useStateFromStoresArray([SortedGuildStore, GuildStore], () => {
|
|
const flattenedGuildIds = SortedGuildStore.getFlattenedGuildIds();
|
|
const r5 = [];
|
|
let c30119_0 = r5;
|
|
flattenedGuildIds.forEach((flattenedGuildId) => {
|
|
const guild = GuildStore.getGuild(flattenedGuildId);
|
|
if (guild != null) {
|
|
c30119_0.push(guild);
|
|
}
|
|
});
|
|
return r5;
|
|
}, []);
|
|
stateFromStores3 = useStateFromStores([UserStore], () => UserStore.getCurrentUser());
|
|
memo = useMemo(() => {
|
|
const r0 = [];
|
|
for (const item of stateFromStoresArray2) {
|
|
const { name, id } = item;
|
|
const id2 = id;
|
|
const stickers = stateFromStores2.get(id);
|
|
if (stickers != null && stickers.length !== 0) {
|
|
r0.push({
|
|
type: StickerCategoryTypes.GUILD,
|
|
id: id2,
|
|
name,
|
|
stickers
|
|
});
|
|
}
|
|
}
|
|
if ((context == null ? void 0 : context.getGuildId()) != null) {
|
|
const guild = GuildStore.getGuild(context.getGuildId());
|
|
const canManageAllExpressions = getManageResourcePermissions(guild).canManageAllExpressions;
|
|
const r69 = r0.findIndex((item) => item.id === context.getGuildId());
|
|
if (r69 >= 1) {
|
|
r0.unshift(r0.splice(r69, 1)[0]);
|
|
} else if (r69 === -1 && guild != null && canManageAllExpressions) {
|
|
r0.unshift({
|
|
type: StickerCategoryTypes.EMPTY_GUILD_UPSELL,
|
|
id: guild.id,
|
|
name: guild.name,
|
|
stickers: []
|
|
});
|
|
}
|
|
if (stateFromStores3 != null) {
|
|
can({
|
|
permission: Permissions.USE_EXTERNAL_EMOJIS,
|
|
user: stateFromStores3,
|
|
context
|
|
});
|
|
}
|
|
}
|
|
return r0;
|
|
}, [stateFromStores2, stateFromStoresArray2, stateFromStores3, a0]);
|
|
return useMemo(() => {
|
|
const r18 = packs.map(createStickerPackCategory);
|
|
const r36 = [{
|
|
type: StickerCategoryTypes.FAVORITE,
|
|
id: StickerCategoryTypes.FAVORITE,
|
|
name: intl.string(t.y3LQCG),
|
|
stickers: stateFromStoresArray
|
|
}, ,];
|
|
const r41 = {
|
|
type: StickerCategoryTypes.RECENT,
|
|
id: StickerCategoryTypes.RECENT,
|
|
name: intl.string(t["6hjpXW"]),
|
|
stickers: null
|
|
};
|
|
let stickers = frequentlyUsedStickers == null ? void 0 : frequentlyUsedStickers.filter((frequentlyUsedSticker) => {
|
|
let r19;
|
|
if (_StickersUtils.isGuildSticker(frequentlyUsedSticker)) {
|
|
const stickersByGuildId = StickersStore.getStickersByGuildId(frequentlyUsedSticker.guild_id);
|
|
let r25 = stickersByGuildId == null ? void 0 : stickersByGuildId.some((item) => item.id === frequentlyUsedSticker.id);
|
|
if (r25 == null) {
|
|
r25 = false;
|
|
}
|
|
if (r25) {
|
|
r25 = getStickerSendability(frequentlyUsedSticker, stateFromStores, a0) !== StickerSendability.NONSENDABLE;
|
|
}
|
|
r19 = r25;
|
|
} else {
|
|
r19 = isStandardSticker(frequentlyUsedSticker) ? packs.some((pack) => pack.id === frequentlyUsedSticker.pack_id) : void 0;
|
|
}
|
|
return r19;
|
|
});
|
|
if (stickers == null) {
|
|
stickers = [];
|
|
}
|
|
r41.stickers = stickers;
|
|
r36[1] = r41;
|
|
HermesBuiltin.arraySpread(r36, r18, HermesBuiltin.arraySpread(r36, memo, 2));
|
|
return r36;
|
|
}, [packs, stateFromStoresArray, frequentlyUsedStickers, memo, stateFromStores, a0]);
|
|
}
|
|
c6359_13 = [];
|
|
export function useFetchStickerPack(a0) {
|
|
useEffect($mk82897(), []);
|
|
const stateFromStores4 = useStateFromStores([StickersStore], () => StickersStore.hasLoadedStickerPacks);
|
|
useEffect(() => {
|
|
let r2 = stateFromStores4;
|
|
if (stateFromStores4) {
|
|
r2 = StickersStore.getStickerPack(a0) == null;
|
|
}
|
|
if (r2) {
|
|
fetchStickerPack(a0);
|
|
}
|
|
}, [a0, stateFromStores4]);
|
|
}
|
|
export function useShouldAnimateSticker(a0) {
|
|
return shouldAnimateSticker(AnimateStickers.useSetting(), a0);
|
|
}
|
|
export function useStickersGrid(a0) {
|
|
const { collapsedStickersCategories, filteredStickers, listPaddingRight = 0 } = a0;
|
|
let c17353_2 = listPaddingRight;
|
|
let listWidth = a0.listWidth;
|
|
if (listWidth === void 0) {
|
|
listWidth = 0;
|
|
}
|
|
let c17353_3 = listWidth;
|
|
let stickerNodeMargin = a0.stickerNodeMargin;
|
|
if (stickerNodeMargin === void 0) {
|
|
stickerNodeMargin = 0;
|
|
}
|
|
let c17353_4 = stickerNodeMargin;
|
|
const { stickerNodeWidth, stickersCategories } = a0;
|
|
return useMemo(() => {
|
|
const r6 = Math;
|
|
const r1 = c17353_3 - c17353_2;
|
|
const r36 = r6.floor((r1 + c17353_4) / (stickerNodeWidth + c17353_4));
|
|
let c26484_0 = r36;
|
|
const gutterWidth = Math.floor(Math.max(c17353_4, (c17353_3 - c17353_2 - stickerNodeWidth * r36) / (r36 - 1)));
|
|
const columnCounts = [];
|
|
let c26484_1 = columnCounts;
|
|
const rowCountBySection = [];
|
|
let c26484_2 = rowCountBySection;
|
|
const stickersGrid = [];
|
|
let c26484_3 = stickersGrid;
|
|
let rowCount = 0;
|
|
let gridSectionIndex = 0;
|
|
let visibleRowIndex = 0;
|
|
if (c17353_3 !== 0) {
|
|
const addGridSection = function addGridSection(a0, category, r8 = false) {
|
|
const r28 = _StickersUtils.isGuildSticker(a0[0]) ? GuildStore.getGuild(a0[0].guild_id) : void 0;
|
|
const canCreateExpressions = getManageResourcePermissions(r28).canCreateExpressions;
|
|
const guildId = SelectedGuildStore.getGuildId();
|
|
const r14 = stickersCategories.findIndex((stickersCategory) => stickersCategory.type === StickerCategoryTypes.FAVORITE);
|
|
const r44 = stickersCategories.findIndex((stickersCategory) => stickersCategory.type === StickerCategoryTypes.RECENT);
|
|
const length = a0.length;
|
|
const r53 = r28 != null && guildId === r28.id && canCreateExpressions && a0.length < getTotalStickerCountForTier(r28.premiumTier) ? length + 1 : length;
|
|
const r60 = Math.ceil(r53 / c26484_0);
|
|
c26484_2[gridSectionIndex] = r8 ? 0 : r60;
|
|
const r63 = 0 < r60;
|
|
let r64 = 0;
|
|
if (r63) {
|
|
do {
|
|
const r1 = r64 * c26484_0;
|
|
const r71 = a0.slice(r1, r1 + c26484_0).map((item, index) => ({
|
|
type: StickerGridItemTypes.STICKER,
|
|
sticker: item,
|
|
packId: isStandardSticker(item) ? item.pack_id : "TODO - fix",
|
|
gridSectionIndex,
|
|
rowIndex: rowCount,
|
|
columnIndex: index,
|
|
visibleRowIndex,
|
|
category
|
|
}));
|
|
let r73 = gridSectionIndex > r44;
|
|
const r74 = r64;
|
|
if (r73) {
|
|
r73 = gridSectionIndex > r14;
|
|
}
|
|
if (r73) {
|
|
r73 = r28 != null;
|
|
}
|
|
if (r73) {
|
|
r73 = r53 > a0.length;
|
|
}
|
|
if (r73) {
|
|
r71.push({
|
|
type: StickerGridItemTypes.CREATE_STICKER,
|
|
guild_id: r28.id,
|
|
name: intl.string(t["UwF+Cw"]),
|
|
gridSectionIndex,
|
|
rowIndex: rowCount,
|
|
columnIndex: r71.length,
|
|
visibleRowIndex
|
|
});
|
|
}
|
|
if (!r8) {
|
|
visibleRowIndex = visibleRowIndex + 1;
|
|
c26484_3.push(r71);
|
|
c26484_1.push(r71.length);
|
|
}
|
|
rowCount = rowCount + 1;
|
|
r64 = r74 + 1;
|
|
} while (r64 < r60);
|
|
}
|
|
gridSectionIndex = gridSectionIndex + 1;
|
|
};
|
|
if (filteredStickers == null) {
|
|
for (const stickersCategory of stickersCategories) {
|
|
const r83 = stickersCategory;
|
|
if (stickersCategory.stickers.length > 0) {
|
|
rowCount = rowCount + 1;
|
|
addGridSection(r83.stickers, r83.type, (collapsedStickersCategories == null ? void 0 : collapsedStickersCategories.has(r83.id)) === true);
|
|
} else if (r83.type === StickerCategoryTypes.EMPTY_GUILD_UPSELL) {
|
|
rowCountBySection[gridSectionIndex] = 0;
|
|
gridSectionIndex = gridSectionIndex + 1;
|
|
}
|
|
}
|
|
} else {
|
|
if (filteredStickers.sendable.length > 0) {
|
|
addGridSection(filteredStickers.sendable, StickerCategoryTypes.SEARCH_RESULTS);
|
|
}
|
|
if (filteredStickers.sendableWithPremium.length > 0) {
|
|
addGridSection(filteredStickers.sendableWithPremium, StickerCategoryTypes.SEARCH_RESULTS);
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
rowCount,
|
|
rowCountBySection,
|
|
stickersGrid,
|
|
gutterWidth,
|
|
columnCounts
|
|
};
|
|
}, [collapsedStickersCategories, filteredStickers, listPaddingRight, listWidth, stickerNodeMargin, stickerNodeWidth, stickersCategories]);
|
|
}
|
|
export function useHasSendableSticker() {
|
|
return true;
|
|
}
|
|
export function useFetchStickerPacks() {
|
|
useEffect($mk82897(), []);
|
|
}
|
|
export function useFavoriteStickerIds() {
|
|
let r11 = useFrecencySettings().favoriteStickers?.stickerIds;
|
|
if (r11 == null) {
|
|
r11 = c6359_13;
|
|
}
|
|
return r11;
|
|
}
|
|
export function useFavoriteStickers() {
|
|
let r8 = useFrecencySettings().favoriteStickers?.stickerIds;
|
|
if (r8 == null) {
|
|
r8 = c6359_13;
|
|
}
|
|
let env17348;
|
|
const r12 = env17348 = {
|
|
$parent: env6359
|
|
};
|
|
env17348[0] = r8;
|
|
return useStateFromStoresArray([StickersStore], $mk82898(r12), [r8]);
|
|
}
|
|
export function useLatestFrecentStickerIds() {
|
|
const frecencySettings = useFrecencySettings();
|
|
let r11 = c6359_13;
|
|
if ((frecencySettings == null ? void 0 : frecencySettings.stickerFrecency?.stickers) != null) {
|
|
r11 = Object.keys(frecencySettings == null ? void 0 : frecencySettings.stickerFrecency?.stickers);
|
|
}
|
|
return r11;
|
|
}
|
|
export function useLatestFrecentStickers() {
|
|
const frecencySettings = useFrecencySettings();
|
|
let r8 = c6359_13;
|
|
if ((frecencySettings == null ? void 0 : frecencySettings.stickerFrecency?.stickers) != null) {
|
|
r8 = Object.keys(frecencySettings == null ? void 0 : frecencySettings.stickerFrecency?.stickers);
|
|
}
|
|
let c17354_0 = r8;
|
|
return useStateFromStoresArray([StickersStore], () => c17354_0.map((item) => StickersStore.getStickerById(item)).filter((item) => item !== void 0), [r8]);
|
|
}
|
|
export function useStickerForRenderableSticker(a0) {
|
|
let r48;
|
|
let setState, setState2, current, ref;
|
|
let r11 = arguments[1];
|
|
if (r11 === void 0) {
|
|
r11 = false;
|
|
}
|
|
let c17355_1 = r11;
|
|
setState = void 0;
|
|
setState2 = void 0;
|
|
current = void 0;
|
|
ref = void 0;
|
|
const stateFromStores5 = useStateFromStores([StickersStore], () => StickersStore.getStickerById(a0.id));
|
|
let shouldFetch;
|
|
[shouldFetch, setState] = useState(true);
|
|
let hasFetched;
|
|
[hasFetched, setState2] = useState(false);
|
|
const isReturnable = _StickersUtils.isGuildSticker(a0) || isStandardSticker(a0);
|
|
current = {
|
|
hasFetched,
|
|
isReturnable,
|
|
renderableSticker: a0,
|
|
shouldFetch,
|
|
stickersStoreDefinition: stateFromStores5
|
|
};
|
|
ref = useRef(current);
|
|
useEffect(() => {
|
|
ref.current = current;
|
|
});
|
|
useEffect(() => {
|
|
(async () => {
|
|
let c30122_2 = 0;
|
|
L18: {
|
|
L17: {
|
|
try {
|
|
const current2 = ref.current;
|
|
const { hasFetched, isReturnable, renderableSticker, shouldFetch, stickersStoreDefinition } = current2;
|
|
if (!c17355_1) {
|
|
break L18;
|
|
}
|
|
if (isReturnable) {
|
|
break L18;
|
|
}
|
|
if (stickersStoreDefinition != null) {
|
|
break L18;
|
|
}
|
|
if (!shouldFetch) {
|
|
break L18;
|
|
}
|
|
if (hasFetched) {
|
|
break L18;
|
|
}
|
|
setState(false);
|
|
c30122_2 = 1;
|
|
await fetchSticker(renderableSticker.id);
|
|
c30122_2 = 0;
|
|
(0, setState2)(true);
|
|
} catch ($e) {
|
|
let r26 = $e;
|
|
if (c30122_2 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c30122_2 = 0;
|
|
(0, setState2)(true);
|
|
break L17;
|
|
} catch ($e) {
|
|
r26 = $e;
|
|
if (c30122_2 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r26;
|
|
}
|
|
}
|
|
return void 0;
|
|
}
|
|
})();
|
|
}, [r11]);
|
|
if (isReturnable) {
|
|
r48 = [a0, hasFetched];
|
|
} else {
|
|
let r47 = stateFromStores5;
|
|
if (r47 == null) {
|
|
r47 = null;
|
|
}
|
|
r48 = [r47, hasFetched];
|
|
}
|
|
return r48;
|
|
}
|
|
export function useFilteredStickerPackCategories(a0) {
|
|
const stickerPackCategories = useStickerPackCategories(a0);
|
|
let c17356_0 = stickerPackCategories;
|
|
return useMemo(() => c17356_0.filter((item) => item.type === StickerCategoryTypes.EMPTY_GUILD_UPSELL || item.stickers.length > 0, []), [stickerPackCategories]);
|
|
}
|