mtcute/packages/client/src/methods/users/get-common-chats.ts
2021-04-08 12:19:38 +03:00

26 lines
826 B
TypeScript

import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
import { TelegramClient } from '../../client'
import { Chat } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
/**
* Get a list of common chats you have with a given user
*
* @param userId User's ID, username or phone number
* @throws MtCuteInvalidPeerTypeError
* @internal
*/
export async function getCommonChats(
this: TelegramClient,
userId: InputPeerLike
): Promise<Chat[]> {
const peer = normalizeToInputUser(await this.resolvePeer(userId))
if (!peer) throw new MtCuteInvalidPeerTypeError(userId, 'user')
return this.call({
_: 'messages.getCommonChats',
userId: peer,
maxId: 0,
limit: 100,
}).then((res) => res.chats.map((it) => new Chat(this, it)))
}