tgsnake
Version:
Telegram MTProto framework for nodejs.
97 lines (96 loc) • 3.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Photo = void 0;
const TL_js_1 = require("../../TL.js");
const platform_node_js_1 = require("../../../platform.node.js");
const PhotoSize_js_1 = require("./PhotoSize.js");
class Photo extends TL_js_1.TLObject {
fileId;
fileUniqueId;
thumb;
date;
dcId;
size;
width;
height;
hasStickers;
constructor({ fileId, fileUniqueId, thumb, date, dcId, size, width, height, hasStickers, }, client) {
super(client);
this.fileId = fileId;
this.fileUniqueId = fileUniqueId;
this.thumb = thumb;
this.date = date;
this.dcId = dcId;
this.size = size;
this.width = width;
this.height = height;
this.hasStickers = hasStickers;
}
static parse(client, photo) {
let thumb = [];
let collect = [];
if (photo.sizes) {
for (const psize of photo.sizes) {
if (psize instanceof platform_node_js_1.Raw.PhotoSize) {
thumb.push(PhotoSize_js_1.PhotoSize.parse(client, psize, photo.id, photo.accessHash, photo.fileReference, photo.dcId));
collect.push({
type: psize.type,
w: psize.w,
h: psize.h,
size: BigInt(psize.size),
});
}
if (psize instanceof platform_node_js_1.Raw.PhotoSizeProgressive) {
psize;
thumb.push(PhotoSize_js_1.PhotoSize.parse(client, new platform_node_js_1.Raw.PhotoSize({
type: psize.type,
w: psize.w,
h: psize.h,
size: Math.max(...psize.sizes),
}), photo.id, photo.accessHash, photo.fileReference, photo.dcId));
collect.push({
type: psize.type,
w: psize.w,
h: psize.h,
size: BigInt(Math.max(...psize.sizes)),
});
}
}
}
const psort = collect.sort((a, b) => {
if (a.size > b.size)
return 1;
if (a.size < b.size)
return -1;
return 0;
});
const main = psort[psort.length - 1];
const file = platform_node_js_1.FileId.encode({
version: 4,
subVersion: 32,
fileType: platform_node_js_1.FileType.PHOTO,
thumbnailSource: platform_node_js_1.ThumbnailSource.THUMBNAIL,
thumbnailFileType: platform_node_js_1.FileType.PHOTO,
thumbnailSize: main?.type ?? 'y',
fileTypeUniqueId: platform_node_js_1.FileTypeUniqueId.DOCUMENT,
volumeId: BigInt(0),
localId: 0,
dcId: photo.dcId,
id: photo.id,
accessHash: photo.accessHash,
fileReference: photo.fileReference,
});
return new Photo({
fileId: file.fileId,
fileUniqueId: file.fileUniqueId,
thumb: thumb,
date: new Date(photo.date * 1000),
dcId: photo.dcId,
size: main?.size ?? BigInt(0),
width: main?.w ?? 0,
height: main?.h ?? 0,
hasStickers: photo.hasStickers,
}, client);
}
}
exports.Photo = Photo;