193 lines
7.4 KiB
TypeScript
193 lines
7.4 KiB
TypeScript
// Metro module 4524 (f4525).
|
|
import UserSettingsProtoStore from "../user_settings/UserSettingsProtoStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import UploadAttachmentStore from "../../stores/UploadAttachmentStore";
|
|
import StickerMessagePreviewStore from "./StickerMessagePreviewStore";
|
|
import { DEFAULT_STICKER_DIMENSIONS, STICKER_APPLICATION_ID, StickerAnimationSettings } from "./StickersConstants";
|
|
import { Endpoints } from "../../Constants";
|
|
import { StickerFormat, StickerExtensions, StickerCategoryTypes, StickerSelectLocation, MetaStickerType } from "./StickersTypes";
|
|
import { SUPPORTS_WEBP } from "../../utils/AvatarUtils";
|
|
import { getForceSdrEmojisStickersConfig } from "../image_upload/ForceSdrEmojisStickersExperiment";
|
|
import { isAndroid, isWeb } from "../../utils/PlatformUtils";
|
|
import { getBestMediaProxySize, getDevicePixelRatio } from "../image_upload/ImageLoaderUtils";
|
|
import { getQueriesFromUserInput } from "./StickersSuggestionUtils";
|
|
function $mk74719($env) {
|
|
return (a0) => a0.id === $env[0].cover_sticker_id;
|
|
}
|
|
let API_ENDPOINT, MEDIA_PROXY_ENDPOINT, PROJECT_ENV, ASSET_ENDPOINT, CDN_HOST, c2731_15, c2731_16, c2731_18;
|
|
const getStickerExtensionFromFormatType = function getStickerExtensionFromFormatType(format_type) {
|
|
if (StickerFormat.PNG === format_type) {
|
|
return SUPPORTS_WEBP ? StickerExtensions.WEBP : StickerExtensions.PNG;
|
|
}
|
|
if (StickerFormat.APNG === format_type) {
|
|
return StickerExtensions.APNG;
|
|
}
|
|
if (StickerFormat.LOTTIE === format_type) {
|
|
return StickerExtensions.LOTTIE;
|
|
}
|
|
if (StickerFormat.GIF === format_type) {
|
|
return StickerExtensions.GIF;
|
|
}
|
|
throw new Error(`Unexpected format type: ${format_type}`);
|
|
};
|
|
const GLOBAL_ENV = window.GLOBAL_ENV;
|
|
API_ENDPOINT = GLOBAL_ENV.API_ENDPOINT;
|
|
MEDIA_PROXY_ENDPOINT = GLOBAL_ENV.MEDIA_PROXY_ENDPOINT;
|
|
PROJECT_ENV = GLOBAL_ENV.PROJECT_ENV;
|
|
ASSET_ENDPOINT = GLOBAL_ENV.ASSET_ENDPOINT;
|
|
CDN_HOST = GLOBAL_ENV.CDN_HOST;
|
|
const r64 = decodeURIComponent(Endpoints.STICKER_ASSET("[\\d]+", `(${Object.values(StickerExtensions).join("|")})`));
|
|
c2731_15 = new RegExp(`(${location.protocol}${ASSET_ENDPOINT}|${location.protocol}${MEDIA_PROXY_ENDPOINT})(${r64})`, "ig");
|
|
c2731_16 = new RegExp(`${location.protocol}${API_ENDPOINT}(${r64})`, "ig");
|
|
c2731_18 = [];
|
|
export function getStickerPackPreviewSticker(a0) {
|
|
let env14293;
|
|
const r1 = env14293 = {};
|
|
env14293[0] = a0;
|
|
if (a0.cover_sticker_id != null) {
|
|
const r7 = a0.stickers.find($mk74719(r1));
|
|
if (r7 != null) {
|
|
return r7;
|
|
}
|
|
}
|
|
return a0.stickers[0];
|
|
}
|
|
export { getStickerExtensionFromFormatType };
|
|
export function getStickerFormatTypeFromFileType(a0) {
|
|
if (a0 === "application/json") {
|
|
return StickerFormat.LOTTIE;
|
|
}
|
|
if (a0 === "image/apng") {
|
|
return StickerFormat.APNG;
|
|
}
|
|
if (a0 !== "image/png" && a0 !== "image/webp") {
|
|
if (a0 === "image/gif") {
|
|
return StickerFormat.GIF;
|
|
}
|
|
throw new Error(`Unexpected file type: ${a0}`);
|
|
}
|
|
return StickerFormat.PNG;
|
|
}
|
|
export function getFilenameForSticker(a0) {
|
|
return a0 != null ? `${a0.name}.${getStickerExtensionFromFormatType(a0.format_type)}` : null;
|
|
}
|
|
export function getStickerTagForEmoji(a0) {
|
|
return a0.id != null ? a0.id : a0.optionallyDiverseSequence;
|
|
}
|
|
export const getStickerAssetUrl = function(a0, r0 = {}) {
|
|
let enabled;
|
|
const { isPreview = false, size = DEFAULT_STICKER_DIMENSIONS } = r0;
|
|
if (a0.format_type == null) {
|
|
return null;
|
|
}
|
|
let format_type = a0.format_type;
|
|
if (a0.format_type === StickerFormat.GIF && isPreview) {
|
|
format_type = StickerFormat.PNG;
|
|
}
|
|
const stickerExtensionFromFormatType = getStickerExtensionFromFormatType(format_type);
|
|
const r39 = Endpoints.STICKER_ASSET(a0.id, stickerExtensionFromFormatType);
|
|
try {
|
|
enabled = (0, getForceSdrEmojisStickersConfig)({
|
|
location: "sticker_url"
|
|
}).enabled;
|
|
} catch ($e) {}
|
|
const r11 = enabled ? "&force_sdr=true" : "";
|
|
const r10 = stickerExtensionFromFormatType === StickerExtensions.WEBP ? "&quality=lossless" : "";
|
|
if (PROJECT_ENV !== "development") {
|
|
if (a0.format_type === StickerFormat.LOTTIE) {
|
|
return `${location.protocol}${ASSET_ENDPOINT}${r39}`;
|
|
}
|
|
const r85 = a0.format_type === StickerFormat.APNG ? isPreview ? isAndroid() ? "" : "&passthrough=false" : "" : "";
|
|
return `${location.protocol}${MEDIA_PROXY_ENDPOINT}${r39}?size=${getBestMediaProxySize(size * Math.min(2, getDevicePixelRatio()))}${r85}${r10}${r11}`;
|
|
}
|
|
if (a0.format_type === StickerFormat.LOTTIE && isWeb()) {
|
|
return r39;
|
|
}
|
|
const r69 = `${location.protocol}${MEDIA_PROXY_ENDPOINT}${r39}`;
|
|
return enabled ? `${r69}?force_sdr=true` : r69;
|
|
};
|
|
export function getStickerPackBannerAssetUrl({ banner_asset_id }, a1) {
|
|
if (banner_asset_id == null) {
|
|
return null;
|
|
}
|
|
const r12 = SUPPORTS_WEBP ? "webp" : "png";
|
|
const r31 = CDN_HOST != null ? `https://${CDN_HOST}/app-assets/${STICKER_APPLICATION_ID}/store/${banner_asset_id}.${r12}` : `${location.protocol}${API_ENDPOINT}${Endpoints.STORE_ASSET(STICKER_APPLICATION_ID, banner_asset_id, r12)}`;
|
|
return a1 != null ? r31 + `?size=${getBestMediaProxySize(a1)}` : r31;
|
|
}
|
|
export function isStickerAssetUrl(a0) {
|
|
return a0.match.call(a0, PROJECT_ENV !== "development" ? c2731_15 : c2731_16) != null;
|
|
}
|
|
export function isStickerPackAnimated(a0) {
|
|
return a0.stickers.some(({ format_type }) => format_type === StickerFormat.APNG || format_type === StickerFormat.LOTTIE || format_type === StickerFormat.GIF);
|
|
}
|
|
export function createStickerPackCategory(a0) {
|
|
let previewSticker;
|
|
let env14294;
|
|
const r14 = env14294 = {};
|
|
env14294[0] = a0;
|
|
if (a0.cover_sticker_id != null) {
|
|
previewSticker = a0.stickers.find($mk74719(r14));
|
|
if (previewSticker == null) {
|
|
previewSticker = a0.stickers[0];
|
|
}
|
|
} else {
|
|
previewSticker = a0.stickers[0];
|
|
}
|
|
return {
|
|
type: StickerCategoryTypes.PACK,
|
|
id: a0.id,
|
|
name: a0.name,
|
|
stickers: a0.stickers,
|
|
previewSticker
|
|
};
|
|
}
|
|
export function shouldAnimateSticker(a0, a1) {
|
|
return a0 !== StickerAnimationSettings.ANIMATE_ON_INTERACTION ? a0 !== StickerAnimationSettings.NEVER_ANIMATE : a1;
|
|
}
|
|
export function shouldAttachSticker(a0, a1, a2, a3) {
|
|
if (UploadAttachmentStore.getUploadCount(a2, a3) > 0) {
|
|
return true;
|
|
}
|
|
const stickerPreview = StickerMessagePreviewStore.getStickerPreview(a2, a3);
|
|
if (stickerPreview != null && stickerPreview.length > 0) {
|
|
return true;
|
|
}
|
|
if (StickerSelectLocation.STICKER_PICKER === a0) {
|
|
return a1.trim() !== "";
|
|
}
|
|
if (StickerSelectLocation.AUTOCOMPLETE === a0) {
|
|
return getQueriesFromUserInput(a1).length > 1;
|
|
}
|
|
StickerSelectLocation.BUILT_IN_INTEGRATION;
|
|
return false;
|
|
}
|
|
export function isGuildSticker(a0) {
|
|
return a0.type === MetaStickerType.GUILD;
|
|
}
|
|
export function isStandardSticker(a0) {
|
|
return a0.type === MetaStickerType.STANDARD;
|
|
}
|
|
export function getMessageStickers(a0) {
|
|
return a0.stickerItems.length > 0 ? a0.stickerItems : a0.stickers.length > 0 ? a0.stickers : [];
|
|
}
|
|
export function isAvailableGuildSticker(a0) {
|
|
if (a0 === null) {
|
|
return false;
|
|
}
|
|
return GuildStore.getGuild(a0.guild_id) !== void 0;
|
|
}
|
|
export function getFavoriteStickerIds() {
|
|
let r6 = UserSettingsProtoStore.frecencyWithoutFetchingLatest.favoriteStickers?.stickerIds;
|
|
if (r6 == null) {
|
|
r6 = c2731_18;
|
|
}
|
|
return r6;
|
|
}
|
|
export function isFavoriteSticker(a0) {
|
|
let r4 = UserSettingsProtoStore.frecencyWithoutFetchingLatest.favoriteStickers?.stickerIds;
|
|
if (r4 == null) {
|
|
r4 = c2731_18;
|
|
}
|
|
return r4.includes(a0);
|
|
}
|