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

164 lines
8.7 KiB
TypeScript

/* Metro module 8403; source: modules/recent_avatars/RecentAvatarUtils.tsx; dependencies: [661, 1423, 1457, 1468, 1244, 7611, 1360, 2] */
function _fun66786(global, require, importDefault, importAll, module, exports, dependencyMap) { // fn#66786, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:6, offset: 0x01c09669, size: 214 bytes, params: 8, frame: 20
const env0_0 = require;
const closure = getImageFormat_66787;
const closure2 = getArchivedAvatarURL;
const Object = global.Object;
Object.defineProperty(exports, '__esModule', {value: true});
const env0_3 = (require(661) /* metro dependency 661: Constants */).Endpoints;
(require(2) /* metro dependency 2 */).fileFinishedImporting('modules/recent_avatars/RecentAvatarUtils.tsx');
exports.getImageFormat = closure;
exports.getArchivedAvatarURL = closure2;
exports.generateAvatarDescription = generateAvatarDescription;
exports.generateRecentAvatarFileDetails = generateRecentAvatarFileDetails;
exports.createPendingImage = createPendingImage;
exports.getPendingAvatarSrc = getPendingAvatarSrc;
}
function getImageFormat_66787({storageHash, canAnimate, allowWebp}) { // fn#66787, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:116, offset: 0x01c0973f, size: 216 bytes, params: 2, frame: 18
var r0;
var moduleValue;
const SUPPORTS_WEBP = (require(1423) /* metro dependency 1423: AvatarUtils */).SUPPORTS_WEBP;
canAnimate = !(canAnimate === undefined) && canAnimate;
allowWebp = allowWebp === undefined || allowWebp;
if (canAnimate) {
moduleValue = require(1423) /* metro dependency 1423: AvatarUtils */;
r0 = moduleValue.isAnimatedIconHash(storageHash) ? allowWebp && SUPPORTS_WEBP ? 'webp' : 'gif' : global.window.GLOBAL_ENV.CDN_HOST == null ? 'jpg' : allowWebp && SUPPORTS_WEBP ? 'webp' : 'png';
} else {
r0 = global.window.GLOBAL_ENV.CDN_HOST == null ? 'jpg' : allowWebp && SUPPORTS_WEBP ? 'webp' : 'png';
}
return r0;
}
function getArchivedAvatarURL({userId, avatarId, storageHash, canAnimate, allowWebp, size}) { // fn#66788, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:343, offset: 0x01c09817, size: 375 bytes, params: 2, frame: 27
var object2;
canAnimate = !(canAnimate === undefined) && canAnimate;
allowWebp = allowWebp === undefined || allowWebp;
const GLOBAL_ENV = global.window.GLOBAL_ENV;
const CDN_HOST = GLOBAL_ENV.CDN_HOST;
const r5 = CDN_HOST != null ? 'https://' + CDN_HOST : global.location.protocol + global.window.GLOBAL_ENV.API_ENDPOINT;
const imageFormat_66787 = getImageFormat_66787({storageHash: storageHash, canAnimate: canAnimate,
allowWebp: allowWebp});
object2 = {};
const imageLoaderUtilsModule = require(1457) /* metro dependency 1457: ImageLoaderUtils */;
const getBestMediaProxySize = imageLoaderUtilsModule.getBestMediaProxySize;
const moduleValue2 = imageLoaderUtilsModule;
const getDevicePixelRatio = moduleValue2.getDevicePixelRatio;
object2.size = Reflect.apply(getBestMediaProxySize, imageLoaderUtilsModule,
[size * Reflect.apply(getDevicePixelRatio, moduleValue2, [])]);
if (imageFormat_66787 === 'webp' && canAnimate && (require(1423) /* metro dependency 1423: AvatarUtils */).isAnimatedIconHash(storageHash)) {
object2.animated = true;
}
const value4 = Endpoints.ARCHIVED_AVATAR(userId, avatarId, storageHash, imageFormat_66787);
let value = importDefault(1468) /* metro dependency 1468 */;
value = value.stringify(object2);
return '' + r5 + value4 + '?' + value;
}
function getFileTypeFromExtension(a0) { // fn#66789, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:814, offset: 0x01c0998e, size: 109 bytes, params: 2, frame: 12
if (a0 === 'gif') {
return 'image/gif';
}
if (a0 === 'png') {
return 'image/png';
}
if (a0 === 'jpg') {
return 'image/jpeg';
}
if (a0 === 'webp') {
return 'image/webp';
}
(require(1360) /* metro dependency 1360: GlobalUtils */).assertNever(a0);
}
function generateAvatarDescription(a0) { // fn#66790, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:1190, offset: 0x01c099fb, size: 374 bytes, params: 2, frame: 21
var r5;
const AssetOriginTypes = (require(7611) /* metro dependency 7611: RecentAvatarsTypes */).AssetOriginTypes;
const intl = (require(1244) /* metro dependency 1244: indexNative */).intl;
const t = (require(1244) /* metro dependency 1244: indexNative */).t;
var date;
const r0 = a0 ?? ({});
const filename = r0.filename;
const assetOrigin = r0.assetOrigin;
const r6 = assetOrigin !== undefined ? assetOrigin : AssetOriginTypes.NEW_ASSET;
const ARCHIVED_ASSET = AssetOriginTypes.ARCHIVED_ASSET;
if (r6 !== ARCHIVED_ASSET) {
r5 = filename ?? intl.string(t.lqaIxI);
date = new global.Date();
return intl.formatToPlainString(r6 === AssetOriginTypes.EDITED_ARCHIVED_ASSET ? t.eC2sZi : t.DYil93, {name: r5,
dateTime: date.toLocaleString(intl.currentLocale, {'year': 'numeric', 'day': 'numeric', 'month': 'long',
'hour': 'numeric', 'minute': 'numeric'})});
}
}
function generateRecentAvatarFileDetails(a0, a1) { // fn#66791, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:1742, offset: 0x01c09b71, size: 198 bytes, params: 3, frame: 20
var object2;
var r7;
var intl;
const getImageFormat_66787Binding = getImageFormat_66787;
const SUPPORTS_WEBP = (require(1423) /* metro dependency 1423: AvatarUtils */).SUPPORTS_WEBP;
const imageFormat_66787Binding = getImageFormat_66787Binding({storageHash: a0, canAnimate: true,
allowWebp: SUPPORTS_WEBP});
object2 = {};
if (a1 == null) {
intl = (require(1244) /* metro dependency 1244: indexNative */).intl;
r7 = intl.string((require(1244) /* metro dependency 1244: indexNative */).t.lqaIxI);
} else {
r7 = a1.split(',')[0];
}
object2.filename = '' + r7 + '.' + imageFormat_66787Binding;
object2.type = getFileTypeFromExtension(imageFormat_66787Binding);
return object2;
}
function createPendingImage({assetOrigin, imageUri, description, originalAsset, originalMd5}) { // fn#66792, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:2068, offset: 0x01c09c37, size: 284 bytes, params: 2, frame: 18
const AssetOriginTypes = (require(7611) /* metro dependency 7611: RecentAvatarsTypes */).AssetOriginTypes;
const r4 = assetOrigin !== undefined ? assetOrigin : AssetOriginTypes.NEW_ASSET;
const NEW_ASSET = AssetOriginTypes.NEW_ASSET;
if (NEW_ASSET === r4) {
return {assetOrigin: r4, imageUri: imageUri, description: description, originalMd5: originalMd5};
}
const EDITED_ARCHIVED_ASSET = AssetOriginTypes.EDITED_ARCHIVED_ASSET;
if (EDITED_ARCHIVED_ASSET === r4) {
return {assetOrigin: r4, imageUri: imageUri, description: description, originalAsset: originalAsset,
originalMd5: originalMd5};
}
const ARCHIVED_ASSET = AssetOriginTypes.ARCHIVED_ASSET;
if (ARCHIVED_ASSET === r4) {
return {assetOrigin: r4, imageUri: imageUri, originalAsset: originalAsset};
}
(require(1360) /* metro dependency 1360: GlobalUtils */).assertNever(r4);
}
function getPendingAvatarSrc({userId, image, size, canAnimate}) { // fn#66793, source: /ci/build/discord/discord/discord_android_rn/android/app/src/main/assets/index.android.bundle:8588:2592, offset: 0x01c09d53, size: 181 bytes, params: 2, frame: 19
var r1;
var r0;
var getArchivedAvatarURLBinding;
var object2;
var originalAsset;
size = size === undefined ? 80 : size;
canAnimate = canAnimate === undefined || canAnimate;
if (image == null) {
r0 = image;
} else if (typeof image === 'string') {
r0 = image;
} else {
if (image.assetOrigin === (require(7611) /* metro dependency 7611: RecentAvatarsTypes */).AssetOriginTypes.ARCHIVED_ASSET) {
getArchivedAvatarURLBinding = getArchivedAvatarURL;
object2 = {userId: userId};
originalAsset = image.originalAsset;
object2.avatarId = originalAsset.id;
originalAsset = image.originalAsset;
object2.storageHash = originalAsset.storageHash;
object2.size = size;
object2.canAnimate = canAnimate;
r1 = getArchivedAvatarURLBinding(object2);
} else {
r1 = image.imageUri;
}
r0 = r1;
}
return r0;
}