diff --git a/packages/client/src/methods/users/set-profile-photo.ts b/packages/client/src/methods/users/set-profile-photo.ts index ac3062ae..a5dc3a96 100644 --- a/packages/client/src/methods/users/set-profile-photo.ts +++ b/packages/client/src/methods/users/set-profile-photo.ts @@ -22,21 +22,26 @@ export async function setProfilePhoto( previewSec?: number ): Promise { // try parsing media as file id or input photo - if (tdFileId.isFileIdLike(media) || typeof media === 'object' && tl.isAnyInputPhoto(media)) { + if ( + tdFileId.isFileIdLike(media) || + (typeof media === 'object' && tl.isAnyInputPhoto(media)) + ) { if (typeof media === 'string' && media.match(/^https?:\/\//)) { - throw new MtArgumentError('Profile photo can\'t be set from URL.') + throw new MtArgumentError("Profile photo can't be set from URL.") } - if (tdFileId.isFileIdLike(media)) { - media = fileIdToInputPhoto(media) + if (typeof media !== 'string' || !media.match(/^file:/)) { + if (tdFileId.isFileIdLike(media)) { + media = fileIdToInputPhoto(media) + } + + const res = await this.call({ + _: 'photos.updateProfilePhoto', + id: media, + }) + + return new Photo(this, res.photo as tl.RawPhoto) } - - const res = await this.call({ - _: 'photos.updateProfilePhoto', - id: media - }) - - return new Photo(this, res.photo as tl.RawPhoto) } const res = await this.call({ diff --git a/packages/client/src/types/media/photo.ts b/packages/client/src/types/media/photo.ts index bc27abc3..89cb8a2d 100644 --- a/packages/client/src/types/media/photo.ts +++ b/packages/client/src/types/media/photo.ts @@ -78,6 +78,13 @@ export class Photo extends FileLocation { return new Date(this.raw.date * 1000) } + /** + * Whether this photo is an animated profile picture + */ + get isAnimated(): boolean { + return !!this.raw.videoSizes?.some(s => s.type === 'u') + } + private _thumbnails?: Thumbnail[] /** * Available thumbnails. @@ -90,6 +97,9 @@ export class Photo extends FileLocation { this._thumbnails = this.raw.sizes.map( (sz) => new Thumbnail(this.client, this.raw, sz) ) + this.raw.videoSizes?.forEach((sz) => + this._thumbnails!.push(new Thumbnail(this.client, this.raw, sz)) + ) } return this._thumbnails @@ -116,9 +126,7 @@ export class Photo extends FileLocation { get fileId(): string { if (!this._fileId) { if (!this._bestSize) { - throw new MtArgumentError( - 'Cannot get File ID for this photo' - ) + throw new MtArgumentError('Cannot get File ID for this photo') } this._fileId = this.getThumbnail(this._bestSize.type)!.fileId @@ -135,12 +143,12 @@ export class Photo extends FileLocation { get uniqueFileId(): string { if (!this._uniqueFileId) { if (!this._bestSize) { - throw new MtArgumentError( - 'Cannot get File ID for this photo' - ) + throw new MtArgumentError('Cannot get File ID for this photo') } - this._uniqueFileId = this.getThumbnail(this._bestSize.type)!.uniqueFileId + this._uniqueFileId = this.getThumbnail( + this._bestSize.type + )!.uniqueFileId } return this._uniqueFileId @@ -166,9 +174,13 @@ export class Photo extends FileLocation { get inputMedia(): tl.TypeInputMedia { return { _: 'inputMediaPhoto', - id: this.inputPhoto + id: this.inputPhoto, } } } -makeInspectable(Photo, ['fileSize', 'dcId', 'width', 'height'], ['inputMedia', 'inputPhoto']) +makeInspectable( + Photo, + ['fileSize', 'dcId', 'width', 'height'], + ['inputMedia', 'inputPhoto'] +) diff --git a/packages/client/src/types/media/thumbnail.ts b/packages/client/src/types/media/thumbnail.ts index 9ead8ce5..a82853ef 100644 --- a/packages/client/src/types/media/thumbnail.ts +++ b/packages/client/src/types/media/thumbnail.ts @@ -107,7 +107,7 @@ export class Thumbnail extends FileLocation { id: media.id, fileReference: media.fileReference, accessHash: media.accessHash, - thumbSize: sz.type === 'u' ? '\x00' : sz.type, + thumbSize: sz.type, } } width = sz.w