2022-06-30 16:32:56 +03:00
|
|
|
import Long from 'long'
|
2023-06-05 03:30:48 +03:00
|
|
|
|
2022-06-30 16:32:56 +03:00
|
|
|
import { tl } from '@mtcute/tl'
|
|
|
|
|
2021-05-09 14:35:58 +03:00
|
|
|
import { TelegramClient } from '../../client'
|
2021-08-05 20:38:24 +03:00
|
|
|
import { InputPeerLike, MtInvalidPeerTypeError, Photo } from '../../types'
|
2021-05-09 14:35:58 +03:00
|
|
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2023-06-05 03:30:48 +03:00
|
|
|
},
|
2021-05-09 14:35:58 +03:00
|
|
|
): Promise<Photo[]> {
|
|
|
|
if (!params) params = {}
|
|
|
|
|
|
|
|
const res = await this.call({
|
|
|
|
_: 'photos.getUserPhotos',
|
2022-08-29 16:15:37 +03:00
|
|
|
userId: normalizeToInputUser(await this.resolvePeer(userId), userId),
|
2021-05-09 14:35:58 +03:00
|
|
|
offset: params.offset ?? 0,
|
|
|
|
limit: params.limit ?? 100,
|
2021-11-23 00:03:59 +03:00
|
|
|
maxId: Long.ZERO,
|
2021-05-09 14:35:58 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
return res.photos.map((it) => new Photo(this, it as tl.RawPhoto))
|
|
|
|
}
|