diff --git a/packages/client/src/types/media/document.ts b/packages/client/src/types/media/document.ts index cd7ffb28..4315e583 100644 --- a/packages/client/src/types/media/document.ts +++ b/packages/client/src/types/media/document.ts @@ -67,11 +67,16 @@ export class RawDocument extends FileLocation { */ get thumbnails(): ReadonlyArray { if (!this._thumbnails) { - this._thumbnails = this.raw.thumbs - ? this.raw.thumbs.map( - (sz) => new Thumbnail(this.client, this.raw, sz) - ) - : [] + const arr: Thumbnail[] = [] + + this.raw.thumbs?.forEach((sz) => + arr.push(new Thumbnail(this.client, this.raw, sz)) + ) + this.raw.videoThumbs?.forEach((sz) => + arr.push(new Thumbnail(this.client, this.raw, sz)) + ) + + this._thumbnails = arr } return this._thumbnails diff --git a/packages/client/src/types/media/sticker.ts b/packages/client/src/types/media/sticker.ts index 3170272d..015fa412 100644 --- a/packages/client/src/types/media/sticker.ts +++ b/packages/client/src/types/media/sticker.ts @@ -76,6 +76,13 @@ export class Sticker extends RawDocument { return this.attr2?._ === 'documentAttributeVideo' } + /** + * Whether this sticker is a video (WEBM) sticker + */ + get isPremiumSticker(): boolean { + return !!this.raw.videoThumbs?.some(s => s.type === 'f') + } + /** * Whether this sticker is a valid sticker. * diff --git a/packages/client/src/types/media/thumbnail.ts b/packages/client/src/types/media/thumbnail.ts index 375cd1be..9ead8ce5 100644 --- a/packages/client/src/types/media/thumbnail.ts +++ b/packages/client/src/types/media/thumbnail.ts @@ -31,7 +31,14 @@ export class Thumbnail extends FileLocation { static readonly THUMB_STRIP = 'i' static readonly THUMB_OUTLINE = 'j' - readonly raw: tl.TypePhotoSize + /** Animated profile pictures preview */ + static readonly THUMB_VIDEO_PROFILE = 'u' + /** Trimmed and downscaled video previews */ + static readonly THUMB_VIDEO_PREVIEW = 'v' + /** Fullscreen animation for Premium stickers */ + static readonly THUMB_VIDEO_FULLSCREEN = 'f' + + readonly raw: tl.TypePhotoSize | tl.TypeVideoSize /** * Thumbnail width @@ -51,7 +58,7 @@ export class Thumbnail extends FileLocation { constructor( client: TelegramClient, media: tl.RawPhoto | tl.RawDocument | tl.RawStickerSet, - sz: tl.TypePhotoSize + sz: tl.TypePhotoSize | tl.TypeVideoSize ) { switch (sz._) { case 'photoSizeEmpty': @@ -87,9 +94,9 @@ export class Thumbnail extends FileLocation { stickerset: { _: 'inputStickerSetID', id: media.id, - accessHash: media.accessHash + accessHash: media.accessHash, }, - thumbVersion: media.thumbVersion! + thumbVersion: media.thumbVersion!, } } else { location = { @@ -100,12 +107,15 @@ export class Thumbnail extends FileLocation { id: media.id, fileReference: media.fileReference, accessHash: media.accessHash, - thumbSize: sz.type, + thumbSize: sz.type === 'u' ? '\x00' : sz.type, } } width = sz.w height = sz.h - size = sz._ === 'photoSize' ? sz.size : Math.max(...sz.sizes) + size = + sz._ === 'photoSizeProgressive' + ? Math.max(...sz.sizes) + : sz.size break } @@ -125,6 +135,10 @@ export class Thumbnail extends FileLocation { } } + get isVideo(): boolean { + return this.raw._ === 'videoSize' + } + /** * Thumbnail type */ @@ -152,12 +166,16 @@ export class Thumbnail extends FileLocation { /** * Get TDLib and Bot API compatible File ID * representing this thumbnail. + * + * > **Note:** You can't use this file id to send a thumbnail, + * > only to download it. */ get fileId(): string { if (!this._fileId) { if ( this.raw._ !== 'photoSize' && - this.raw._ !== 'photoSizeProgressive' + this.raw._ !== 'photoSizeProgressive' && + this.raw._ !== 'videoSize' ) { throw new MtArgumentError( `Cannot generate a file ID for "${this.raw.type}"` @@ -177,9 +195,9 @@ export class Thumbnail extends FileLocation { _: 'stickerSetThumbnailVersion', id: this._media.id, accessHash: this._media.accessHash, - version: this._media.thumbVersion! - } - } + version: this._media.thumbVersion!, + }, + }, }) } else { this._fileId = toFileId({ @@ -195,10 +213,12 @@ export class Thumbnail extends FileLocation { accessHash: this._media.accessHash, source: { _: 'thumbnail', - fileType: this._media._ === 'photo' - ? td.FileType.Photo - : td.FileType.Thumbnail, - thumbnailType: this.raw.type, + fileType: + this._media._ === 'photo' + ? td.FileType.Photo + : td.FileType.Thumbnail, + thumbnailType: + this.raw.type === 'u' ? '\x00' : this.raw.type, }, }, }) @@ -216,7 +236,8 @@ export class Thumbnail extends FileLocation { if (!this._uniqueFileId) { if ( this.raw._ !== 'photoSize' && - this.raw._ !== 'photoSizeProgressive' + this.raw._ !== 'photoSizeProgressive' && + this.raw._ !== 'videoSize' ) { throw new MtArgumentError( `Cannot generate a unique file ID for "${this.raw.type}"` @@ -231,8 +252,8 @@ export class Thumbnail extends FileLocation { _: 'stickerSetThumbnailVersion', id: this._media.id, accessHash: this._media.accessHash, - version: this._media.thumbVersion! - } + version: this._media.thumbVersion!, + }, }) } else { this._uniqueFileId = toUniqueFileId( @@ -244,10 +265,11 @@ export class Thumbnail extends FileLocation { id: this._media.id, source: { _: 'thumbnail', - fileType: this._media._ === 'photo' - ? td.FileType.Photo - : td.FileType.Thumbnail, - thumbnailType: this.raw.type, + fileType: + this._media._ === 'photo' + ? td.FileType.Photo + : td.FileType.Thumbnail, + thumbnailType: this.raw.type === 'u' ? '\x00' : this.raw.type, }, } ) diff --git a/packages/client/src/types/messages/message.ts b/packages/client/src/types/messages/message.ts index 55f00263..089567f7 100644 --- a/packages/client/src/types/messages/message.ts +++ b/packages/client/src/types/messages/message.ts @@ -440,8 +440,9 @@ export class Message { /** * Whether this is a premium media * (e.g. >2gb file or fullscreen sticker) + * that was forwarded without author by a non-premium user */ - get isPremiumMedia(): boolean { + get isForwardedPremiumMedia(): boolean { return ( this.raw._ === 'message' && this.raw.media?._ === 'messageMediaDocument' &&