2021-08-05 20:38:24 +03:00
|
|
|
import { MaybeArray } from '@mtcute/core'
|
2022-06-30 16:32:56 +03:00
|
|
|
|
|
|
|
import { TelegramClient } from '../../client'
|
|
|
|
import { InputPeerLike, User } from '../../types'
|
2021-04-08 12:19:38 +03:00
|
|
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get information about a single user.
|
|
|
|
*
|
|
|
|
* @param id User's identifier. Can be ID, username, phone number, `"me"` or `"self"` or TL object
|
|
|
|
* @internal
|
|
|
|
*/
|
2023-09-24 01:32:22 +03:00
|
|
|
export async function getUsers(this: TelegramClient, id: InputPeerLike): Promise<User>
|
2021-04-08 12:19:38 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get information about multiple users.
|
2021-05-11 22:43:11 +03:00
|
|
|
* You can retrieve up to 200 users at once.
|
|
|
|
*
|
|
|
|
* Note that order is not guaranteed.
|
2021-04-08 12:19:38 +03:00
|
|
|
*
|
|
|
|
* @param ids Users' identifiers. Can be ID, username, phone number, `"me"`, `"self"` or TL object
|
|
|
|
* @internal
|
|
|
|
*/
|
2023-09-24 01:32:22 +03:00
|
|
|
export async function getUsers(this: TelegramClient, ids: InputPeerLike[]): Promise<User[]>
|
2021-04-08 12:19:38 +03:00
|
|
|
|
|
|
|
/** @internal */
|
2023-09-24 01:32:22 +03:00
|
|
|
export async function getUsers(this: TelegramClient, ids: MaybeArray<InputPeerLike>): Promise<MaybeArray<User>> {
|
2021-04-08 12:19:38 +03:00
|
|
|
const isArray = Array.isArray(ids)
|
|
|
|
if (!isArray) ids = [ids as InputPeerLike]
|
|
|
|
|
2023-09-24 01:32:22 +03:00
|
|
|
const inputPeers = await this.resolvePeerMany(ids as InputPeerLike[], normalizeToInputUser)
|
2021-04-08 12:19:38 +03:00
|
|
|
|
|
|
|
let res = await this.call({
|
|
|
|
_: 'users.getUsers',
|
|
|
|
id: inputPeers,
|
|
|
|
})
|
|
|
|
|
|
|
|
res = res.filter((it) => it._ !== 'userEmpty')
|
|
|
|
|
2023-09-24 01:32:22 +03:00
|
|
|
return isArray ? res.map((it) => new User(this, it)) : new User(this, res[0])
|
2021-04-08 12:19:38 +03:00
|
|
|
}
|