2021-05-09 14:35:58 +03:00
|
|
|
import { TelegramClient } from '../../client'
|
2021-07-25 21:03:40 +03:00
|
|
|
import { InputPeerLike, MtqtInvalidPeerTypeError, Photo } from '../../types'
|
2021-05-09 14:35:58 +03:00
|
|
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
|
|
|
import bigInt from 'big-integer'
|
2021-07-25 21:03:40 +03:00
|
|
|
import { tl } from '@mtqt/tl'
|
2021-05-09 14:35:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of profile pictures of a user
|
|
|
|
*
|
|
|
|
* @param userId User ID, username, phone number, `"me"` or `"self"`
|
|
|
|
* @param params
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
export async function getProfilePhotos(
|
|
|
|
this: TelegramClient,
|
|
|
|
userId: InputPeerLike,
|
|
|
|
params?: {
|
|
|
|
/**
|
|
|
|
* Offset from which to fetch.
|
|
|
|
*
|
|
|
|
* Defaults to `0`
|
|
|
|
*/
|
|
|
|
offset?: number
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum number of items to fetch (up to 100)
|
|
|
|
*
|
|
|
|
* Defaults to `100`
|
|
|
|
*/
|
|
|
|
limit?: number
|
|
|
|
}
|
|
|
|
): Promise<Photo[]> {
|
|
|
|
if (!params) params = {}
|
|
|
|
|
|
|
|
const peer = normalizeToInputUser(await this.resolvePeer(userId))
|
2021-07-25 21:03:40 +03:00
|
|
|
if (!peer) throw new MtqtInvalidPeerTypeError(userId, 'user')
|
2021-05-09 14:35:58 +03:00
|
|
|
|
|
|
|
const res = await this.call({
|
|
|
|
_: 'photos.getUserPhotos',
|
|
|
|
userId: peer,
|
|
|
|
offset: params.offset ?? 0,
|
|
|
|
limit: params.limit ?? 100,
|
2021-06-06 15:20:41 +03:00
|
|
|
maxId: bigInt.zero,
|
2021-05-09 14:35:58 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
return res.photos.map((it) => new Photo(this, it as tl.RawPhoto))
|
|
|
|
}
|