refactor(client): made resolvePeer return InputPeer, and removed now redundant normalizeTo calls
This commit is contained in:
parent
b634aa01eb
commit
f7e8051a94
52 changed files with 127 additions and 166 deletions
|
@ -2756,9 +2756,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
T extends tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel
|
T extends tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel
|
||||||
>(
|
>(
|
||||||
peerIds: InputPeerLike[],
|
peerIds: InputPeerLike[],
|
||||||
normalizer: (
|
normalizer: (obj: tl.TypeInputPeer) => T | null
|
||||||
obj: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel
|
|
||||||
) => T | null
|
|
||||||
): Promise<T[]>
|
): Promise<T[]>
|
||||||
/**
|
/**
|
||||||
* Get multiple `InputPeer`s at once.
|
* Get multiple `InputPeer`s at once.
|
||||||
|
@ -2767,18 +2765,14 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
*
|
*
|
||||||
* @param peerIds Peer Ids
|
* @param peerIds Peer Ids
|
||||||
*/
|
*/
|
||||||
resolvePeerMany(
|
resolvePeerMany(peerIds: InputPeerLike[]): Promise<tl.TypeInputPeer[]>
|
||||||
peerIds: InputPeerLike[]
|
|
||||||
): Promise<(tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel)[]>
|
|
||||||
/**
|
/**
|
||||||
* Get the `InputPeer` of a known peer id.
|
* Get the `InputPeer` of a known peer id.
|
||||||
* Useful when an `InputPeer` is needed.
|
* Useful when an `InputPeer` is needed.
|
||||||
*
|
*
|
||||||
* @param peerId The peer identifier that you want to extract the `InputPeer` from.
|
* @param peerId The peer identifier that you want to extract the `InputPeer` from.
|
||||||
*/
|
*/
|
||||||
resolvePeer(
|
resolvePeer(peerId: InputPeerLike): Promise<tl.TypeInputPeer>
|
||||||
peerId: InputPeerLike
|
|
||||||
): Promise<tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel>
|
|
||||||
/**
|
/**
|
||||||
* Change user status to offline or online
|
* Change user status to offline or online
|
||||||
*
|
*
|
||||||
|
|
|
@ -5,10 +5,8 @@ import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add new members to a group, supergroup or channel.
|
* Add new members to a group, supergroup or channel.
|
||||||
|
@ -26,7 +24,7 @@ export async function addChatMembers(
|
||||||
users: MaybeArray<InputPeerLike>,
|
users: MaybeArray<InputPeerLike>,
|
||||||
forwardCount = 100
|
forwardCount = 100
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
if (!Array.isArray(users)) users = [users]
|
if (!Array.isArray(users)) users = [users]
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { TelegramClient } from '../../client'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Archive one or more chats
|
* Archive one or more chats
|
||||||
|
@ -21,7 +20,7 @@ export async function archiveChats(
|
||||||
for (const chat of chats) {
|
for (const chat of chats) {
|
||||||
folderPeers.push({
|
folderPeers.push({
|
||||||
_: 'inputFolderPeer',
|
_: 'inputFolderPeer',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chat)),
|
peer: await this.resolvePeer(chat),
|
||||||
folderId: 1
|
folderId: 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
|
|
||||||
|
@ -28,8 +27,8 @@ export async function banChatMember(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
userId: InputPeerLike
|
userId: InputPeerLike
|
||||||
): Promise<Message | null> {
|
): Promise<Message | null> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
const user = normalizeToInputPeer(await this.resolvePeer(userId))
|
const user = await this.resolvePeer(userId)
|
||||||
|
|
||||||
let res
|
let res
|
||||||
if (isInputPeerChannel(chat)) {
|
if (isInputPeerChannel(chat)) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +18,7 @@ export async function deleteChatPhoto(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
chatId: InputPeerLike
|
chatId: InputPeerLike
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
let res
|
let res
|
||||||
if (isInputPeerChat(chat)) {
|
if (isInputPeerChat(chat)) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
import { isInputPeerChat } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a legacy group chat for all members
|
* Delete a legacy group chat for all members
|
||||||
|
@ -12,8 +12,8 @@ export async function deleteGroup(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
chatId: InputPeerLike
|
chatId: InputPeerLike
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
if (chat._ !== 'inputPeerChat')
|
if (!isInputPeerChat(chat))
|
||||||
throw new MtCuteInvalidPeerTypeError(chatId, 'chat')
|
throw new MtCuteInvalidPeerTypeError(chatId, 'chat')
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputChannel, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
||||||
import { createDummyUpdate } from '../../utils/updates-utils'
|
import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ export async function deleteHistory(
|
||||||
mode: 'delete' | 'clear' | 'revoke' = 'delete',
|
mode: 'delete' | 'clear' | 'revoke' = 'delete',
|
||||||
maxId = 0
|
maxId = 0
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chat))
|
const peer = await this.resolvePeer(chat)
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.deleteHistory',
|
_: 'messages.deleteHistory',
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
||||||
import {
|
import {
|
||||||
InputPeerLike,
|
createUsersChatsIndex,
|
||||||
MtCuteInvalidPeerTypeError,
|
isInputPeerChannel,
|
||||||
} from '../../types'
|
isInputPeerChat,
|
||||||
import {
|
isInputPeerUser,
|
||||||
createUsersChatsIndex, isInputPeerChannel, isInputPeerChat, isInputPeerUser,
|
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
@ -26,8 +25,8 @@ export async function getChatMember(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
userId: InputPeerLike
|
userId: InputPeerLike
|
||||||
): Promise<ChatMember> {
|
): Promise<ChatMember> {
|
||||||
const user = normalizeToInputPeer(await this.resolvePeer(userId))
|
const user = await this.resolvePeer(userId)
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
if (isInputPeerChat(chat)) {
|
if (isInputPeerChat(chat)) {
|
||||||
if (!isInputPeerUser(user))
|
if (!isInputPeerUser(user))
|
||||||
|
@ -71,10 +70,6 @@ export async function getChatMember(
|
||||||
|
|
||||||
const { users } = createUsersChatsIndex(res)
|
const { users } = createUsersChatsIndex(res)
|
||||||
|
|
||||||
return new ChatMember(
|
return new ChatMember(this, res.participant, users)
|
||||||
this,
|
|
||||||
res.participant,
|
|
||||||
users
|
|
||||||
)
|
|
||||||
} else throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
} else throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@ import {
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
createUsersChatsIndex, isInputPeerChannel, isInputPeerChat,
|
createUsersChatsIndex,
|
||||||
|
isInputPeerChannel,
|
||||||
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
@ -70,7 +71,7 @@ export async function getChatMembers(
|
||||||
): Promise<ChatMember[]> {
|
): Promise<ChatMember[]> {
|
||||||
if (!params) params = {}
|
if (!params) params = {}
|
||||||
|
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
if (isInputPeerChat(chat)) {
|
if (isInputPeerChat(chat)) {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
@ -145,7 +146,7 @@ export async function getChatMembers(
|
||||||
)
|
)
|
||||||
|
|
||||||
const { users } = createUsersChatsIndex(res)
|
const { users } = createUsersChatsIndex(res)
|
||||||
return res.participants.map(i => new ChatMember(this, i, users))
|
return res.participants.map((i) => new ChatMember(this, i, users))
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
isInputPeerUser,
|
isInputPeerUser,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
@ -42,7 +41,7 @@ export async function getChat(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
let res: tl.TypeChat | tl.TypeUser
|
let res: tl.TypeChat | tl.TypeUser
|
||||||
if (isInputPeerChannel(peer)) {
|
if (isInputPeerChannel(peer)) {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { Chat, InputPeerLike, MtCuteArgumentError } from '../../types'
|
import { Chat, InputPeerLike, MtCuteArgumentError } from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
INVITE_LINK_REGEX, isInputPeerChannel, isInputPeerChat, isInputPeerUser,
|
INVITE_LINK_REGEX,
|
||||||
|
isInputPeerChannel,
|
||||||
|
isInputPeerChat,
|
||||||
|
isInputPeerUser,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
@ -26,11 +28,13 @@ export async function getFullChat(
|
||||||
if (m) {
|
if (m) {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.checkChatInvite',
|
_: 'messages.checkChatInvite',
|
||||||
hash: m[1]
|
hash: m[1],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res._ === 'chatInvite') {
|
if (res._ === 'chatInvite') {
|
||||||
throw new MtCuteArgumentError(`You haven't joined ${JSON.stringify(res.title)}`)
|
throw new MtCuteArgumentError(
|
||||||
|
`You haven't joined ${JSON.stringify(res.title)}`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// we still need to fetch full chat info
|
// we still need to fetch full chat info
|
||||||
|
@ -38,23 +42,23 @@ export async function getFullChat(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
let res: tl.messages.TypeChatFull | tl.TypeUserFull
|
let res: tl.messages.TypeChatFull | tl.TypeUserFull
|
||||||
if (isInputPeerChannel(peer)) {
|
if (isInputPeerChannel(peer)) {
|
||||||
res = await this.call({
|
res = await this.call({
|
||||||
_: 'channels.getFullChannel',
|
_: 'channels.getFullChannel',
|
||||||
channel: normalizeToInputChannel(peer)
|
channel: normalizeToInputChannel(peer),
|
||||||
})
|
})
|
||||||
} else if (isInputPeerUser(peer)) {
|
} else if (isInputPeerUser(peer)) {
|
||||||
res = await this.call({
|
res = await this.call({
|
||||||
_: 'users.getFullUser',
|
_: 'users.getFullUser',
|
||||||
id: normalizeToInputUser(peer)!
|
id: normalizeToInputUser(peer)!,
|
||||||
})
|
})
|
||||||
} else if (isInputPeerChat(peer)) {
|
} else if (isInputPeerChat(peer)) {
|
||||||
res = await this.call({
|
res = await this.call({
|
||||||
_: 'messages.getFullChat',
|
_: 'messages.getFullChat',
|
||||||
chatId: peer.chatId
|
chatId: peer.chatId,
|
||||||
})
|
})
|
||||||
} else throw new Error('should not happen')
|
} else throw new Error('should not happen')
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { isInputPeerChannel, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { isInputPeerChannel } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick a user from a chat.
|
* Kick a user from a chat.
|
||||||
|
@ -16,8 +16,8 @@ export async function kickChatMember(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
userId: InputPeerLike
|
userId: InputPeerLike
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
const user = normalizeToInputPeer(await this.resolvePeer(userId))
|
const user = await this.resolvePeer(userId)
|
||||||
|
|
||||||
await this.banChatMember(chat, user)
|
await this.banChatMember(chat, user)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel, isInputPeerChat,
|
isInputPeerChannel,
|
||||||
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +18,7 @@ export async function leaveChat(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
clear = false
|
clear = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
if (isInputPeerChannel(chat)) {
|
if (isInputPeerChannel(chat)) {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a chat as unread
|
* Mark a chat as unread
|
||||||
|
@ -16,7 +15,7 @@ export async function markChatUnread(
|
||||||
_: 'messages.markDialogUnread',
|
_: 'messages.markDialogUnread',
|
||||||
peer: {
|
peer: {
|
||||||
_: 'inputDialogPeer',
|
_: 'inputDialogPeer',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
},
|
},
|
||||||
unread: true
|
unread: true
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types'
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
|
@ -32,11 +31,11 @@ export async function restrictChatMember(
|
||||||
restrictions: Omit<tl.RawChatBannedRights, '_' | 'untilDate'>,
|
restrictions: Omit<tl.RawChatBannedRights, '_' | 'untilDate'>,
|
||||||
until?: number | Date
|
until?: number | Date
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
if (!isInputPeerChannel(chat))
|
if (!isInputPeerChannel(chat))
|
||||||
throw new MtCuteInvalidPeerTypeError(chatId, 'channel')
|
throw new MtCuteInvalidPeerTypeError(chatId, 'channel')
|
||||||
|
|
||||||
const user = normalizeToInputPeer(await this.resolvePeer(userId))
|
const user = await this.resolvePeer(userId)
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'channels.editBanned',
|
_: 'channels.editBanned',
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save or delete a draft message associated with some chat
|
* Save or delete a draft message associated with some chat
|
||||||
|
@ -15,7 +14,7 @@ export async function saveDraft(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
draft: null | Omit<tl.RawDraftMessage, '_' | 'date'>
|
draft: null | Omit<tl.RawDraftMessage, '_' | 'date'>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
if (draft) {
|
if (draft) {
|
||||||
await this.call({
|
await this.call({
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { Chat, InputChatPermissions, InputPeerLike, MtCuteTypeAssertionError } from '../../types'
|
import { Chat, InputPeerLike, MtCuteTypeAssertionError } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,7 +20,7 @@ export async function setChatDefaultPermissions(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
restrictions: Omit<tl.RawChatBannedRights, '_' | 'untilDate'>
|
restrictions: Omit<tl.RawChatBannedRights, '_' | 'untilDate'>
|
||||||
): Promise<Chat> {
|
): Promise<Chat> {
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.editChatDefaultBannedRights',
|
_: 'messages.editChatDefaultBannedRights',
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change chat description
|
* Change chat description
|
||||||
|
@ -16,7 +15,7 @@ export async function setChatDescription(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
description: string
|
description: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
await this.call({
|
await this.call({
|
||||||
_: 'messages.editChatAbout',
|
_: 'messages.editChatAbout',
|
||||||
|
|
|
@ -10,7 +10,6 @@ import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id'
|
import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id'
|
||||||
|
@ -35,7 +34,7 @@ export async function setChatPhoto(
|
||||||
media: InputFileLike,
|
media: InputFileLike,
|
||||||
previewSec?: number
|
previewSec?: number
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
if (!(isInputPeerChannel(chat) || isInputPeerChat(chat)))
|
if (!(isInputPeerChannel(chat) || isInputPeerChat(chat)))
|
||||||
throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +23,7 @@ export async function setChatTitle(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
title: string
|
title: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
let res
|
let res
|
||||||
if (isInputPeerChat(chat)) {
|
if (isInputPeerChat(chat)) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { TelegramClient } from '../../client'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unarchive one or more chats
|
* Unarchive one or more chats
|
||||||
|
@ -21,7 +20,7 @@ export async function unarchiveChats(
|
||||||
for (const chat of chats) {
|
for (const chat of chats) {
|
||||||
folderPeers.push({
|
folderPeers.push({
|
||||||
_: 'inputFolderPeer',
|
_: 'inputFolderPeer',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chat)),
|
peer: await this.resolvePeer(chat),
|
||||||
folderId: 0
|
folderId: 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
|
|
||||||
// @alias=unrestrictChatMember
|
// @alias=unrestrictChatMember
|
||||||
|
@ -25,8 +24,8 @@ export async function unbanChatMember(
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
userId: InputPeerLike
|
userId: InputPeerLike
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const chat = await this.resolvePeer(chatId)
|
||||||
const user = normalizeToInputPeer(await this.resolvePeer(userId))
|
const user = await this.resolvePeer(userId)
|
||||||
|
|
||||||
if (isInputPeerChannel(chat)) {
|
if (isInputPeerChannel(chat)) {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { ChatInviteLink, InputPeerLike } from '../../types'
|
import { ChatInviteLink, InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +34,7 @@ export async function createInviteLink(
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.exportChatInvite',
|
_: 'messages.exportChatInvite',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
expireDate: normalizeDate(params.expires),
|
expireDate: normalizeDate(params.expires),
|
||||||
usageLimit: params.usageLimit
|
usageLimit: params.usageLimit
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { ChatInviteLink, InputPeerLike } from '../../types'
|
import { ChatInviteLink, InputPeerLike } from '../../types'
|
||||||
import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ export async function editInviteLink(
|
||||||
): Promise<ChatInviteLink> {
|
): Promise<ChatInviteLink> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.editExportedChatInvite',
|
_: 'messages.editExportedChatInvite',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
link,
|
link,
|
||||||
expireDate: normalizeDate(params.expires),
|
expireDate: normalizeDate(params.expires),
|
||||||
usageLimit: params.usageLimit
|
usageLimit: params.usageLimit
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { ChatInviteLink, InputPeerLike } from '../../types'
|
import { ChatInviteLink, InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a new primary invite link for a chat,
|
* Generate a new primary invite link for a chat,
|
||||||
|
@ -18,7 +17,7 @@ export async function exportInviteLink(
|
||||||
): Promise<ChatInviteLink> {
|
): Promise<ChatInviteLink> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.exportChatInvite',
|
_: 'messages.exportChatInvite',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
legacyRevokePermanent: true
|
legacyRevokePermanent: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { ChatInviteLink, InputPeerLike, User } from '../../types'
|
import { ChatInviteLink, InputPeerLike, User } from '../../types'
|
||||||
import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +18,7 @@ export async function* getInviteLinkMembers(
|
||||||
link: string,
|
link: string,
|
||||||
limit = Infinity
|
limit = Infinity
|
||||||
): AsyncIterableIterator<ChatInviteLink.JoinedMember> {
|
): AsyncIterableIterator<ChatInviteLink.JoinedMember> {
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
let current = 0
|
let current = 0
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { ChatInviteLink, InputPeerLike } from '../../types'
|
import { ChatInviteLink, InputPeerLike } from '../../types'
|
||||||
import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get detailed information about an invite link
|
* Get detailed information about an invite link
|
||||||
|
@ -16,7 +16,7 @@ export async function getInviteLink(
|
||||||
): Promise<ChatInviteLink> {
|
): Promise<ChatInviteLink> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.getExportedChatInvite',
|
_: 'messages.getExportedChatInvite',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
link
|
link
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import {
|
import {
|
||||||
createUsersChatsIndex,
|
createUsersChatsIndex,
|
||||||
normalizeToInputPeer,
|
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
@ -53,7 +52,7 @@ export async function* getInviteLinks(
|
||||||
const total = params.limit || Infinity
|
const total = params.limit || Infinity
|
||||||
const chunkSize = Math.min(params.chunkSize ?? 100, total)
|
const chunkSize = Math.min(params.chunkSize ?? 100, total)
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
const admin = normalizeToInputUser(await this.resolvePeer(adminId))
|
const admin = normalizeToInputUser(await this.resolvePeer(adminId))
|
||||||
|
|
||||||
if (!admin) throw new MtCuteInvalidPeerTypeError(adminId, 'user')
|
if (!admin) throw new MtCuteInvalidPeerTypeError(adminId, 'user')
|
||||||
|
|
|
@ -4,10 +4,7 @@ import {
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
MtCuteTypeAssertionError,
|
MtCuteTypeAssertionError,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import {
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
createUsersChatsIndex,
|
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get primary invite link of a chat
|
* Get primary invite link of a chat
|
||||||
|
@ -21,7 +18,7 @@ export async function getPrimaryInviteLink(
|
||||||
): Promise<ChatInviteLink> {
|
): Promise<ChatInviteLink> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.getExportedChatInvites',
|
_: 'messages.getExportedChatInvites',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
adminId: { _: 'inputUserSelf' },
|
adminId: { _: 'inputUserSelf' },
|
||||||
limit: 1,
|
limit: 1,
|
||||||
revoked: false,
|
revoked: false,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { ChatInviteLink, InputPeerLike } from '../../types'
|
import { ChatInviteLink, InputPeerLike } from '../../types'
|
||||||
import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Revoke an invite link.
|
* Revoke an invite link.
|
||||||
|
@ -20,7 +20,7 @@ export async function revokeInviteLink(
|
||||||
): Promise<ChatInviteLink> {
|
): Promise<ChatInviteLink> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.editExportedChatInvite',
|
_: 'messages.editExportedChatInvite',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
link,
|
link,
|
||||||
revoked: true
|
revoked: true
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtCuteTypeAssertionError, Poll } from '../../types'
|
import { InputPeerLike, MtCuteTypeAssertionError, Poll } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
import {
|
|
||||||
createUsersChatsIndex,
|
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
|
||||||
import bigInt from 'big-integer'
|
import bigInt from 'big-integer'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
|
|
||||||
|
@ -25,7 +21,7 @@ export async function closePoll(
|
||||||
): Promise<Poll> {
|
): Promise<Poll> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.editMessage',
|
_: 'messages.editMessage',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
id: message,
|
id: message,
|
||||||
media: {
|
media: {
|
||||||
_: 'inputMediaPoll',
|
_: 'inputMediaPoll',
|
||||||
|
@ -49,7 +45,11 @@ export async function closePoll(
|
||||||
this._handleUpdate(res, true)
|
this._handleUpdate(res, true)
|
||||||
|
|
||||||
const upd = res.updates[0]
|
const upd = res.updates[0]
|
||||||
assertTypeIs('messages.editMessage (@ .updates[0])', upd, 'updateMessagePoll')
|
assertTypeIs(
|
||||||
|
'messages.editMessage (@ .updates[0])',
|
||||||
|
upd,
|
||||||
|
'updateMessagePoll'
|
||||||
|
)
|
||||||
if (!upd.poll) {
|
if (!upd.poll) {
|
||||||
throw new MtCuteTypeAssertionError(
|
throw new MtCuteTypeAssertionError(
|
||||||
'messages.editMessage (@ .updates[0].poll)',
|
'messages.editMessage (@ .updates[0].poll)',
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
import { isInputPeerChannel, normalizeToInputChannel, normalizeToInputPeer } from '../../utils/peer-utils'
|
import {
|
||||||
|
isInputPeerChannel,
|
||||||
|
normalizeToInputChannel,
|
||||||
|
} from '../../utils/peer-utils'
|
||||||
import { createDummyUpdate } from '../../utils/updates-utils'
|
import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete messages, including service messages.
|
* Delete messages, including service messages.
|
||||||
|
@ -21,7 +23,7 @@ export async function deleteMessages(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!Array.isArray(ids)) ids = [ids]
|
if (!Array.isArray(ids)) ids = [ids]
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
let upd
|
let upd
|
||||||
if (isInputPeerChannel(peer)) {
|
if (isInputPeerChannel(peer)) {
|
||||||
|
@ -29,14 +31,14 @@ export async function deleteMessages(
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'channels.deleteMessages',
|
_: 'channels.deleteMessages',
|
||||||
channel,
|
channel,
|
||||||
id: ids
|
id: ids,
|
||||||
})
|
})
|
||||||
upd = createDummyUpdate(res.pts, res.ptsCount, peer.channelId)
|
upd = createDummyUpdate(res.pts, res.ptsCount, peer.channelId)
|
||||||
} else {
|
} else {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.deleteMessages',
|
_: 'messages.deleteMessages',
|
||||||
id: ids,
|
id: ids,
|
||||||
revoke
|
revoke,
|
||||||
})
|
})
|
||||||
upd = createDummyUpdate(res.pts, res.ptsCount)
|
upd = createDummyUpdate(res.pts, res.ptsCount)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import {
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit message text, media, reply markup and schedule date.
|
* Edit message text, media, reply markup and schedule date.
|
||||||
|
@ -105,7 +104,7 @@ export async function editMessage(
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.editMessage',
|
_: 'messages.editMessage',
|
||||||
id: typeof message === 'number' ? message : message.id,
|
id: typeof message === 'number' ? message : message.id,
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
noWebpage: params.disableWebPreview,
|
noWebpage: params.disableWebPreview,
|
||||||
replyMarkup: BotKeyboard._convertToTl(params.replyMarkup),
|
replyMarkup: BotKeyboard._convertToTl(params.replyMarkup),
|
||||||
message: content,
|
message: content,
|
||||||
|
|
|
@ -10,7 +10,6 @@ import { MaybeArray } from '@mtcute/core'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import {
|
import {
|
||||||
createUsersChatsIndex,
|
createUsersChatsIndex,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||||
|
|
||||||
|
@ -193,7 +192,7 @@ export async function forwardMessages(
|
||||||
'You can forward no more than 100 messages at once'
|
'You can forward no more than 100 messages at once'
|
||||||
)
|
)
|
||||||
|
|
||||||
const toPeer = normalizeToInputPeer(await this.resolvePeer(toChatId))
|
const toPeer = await this.resolvePeer(toChatId)
|
||||||
|
|
||||||
let captionMessage: Message | null = null
|
let captionMessage: Message | null = null
|
||||||
if (params.caption) {
|
if (params.caption) {
|
||||||
|
@ -221,7 +220,7 @@ export async function forwardMessages(
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.forwardMessages',
|
_: 'messages.forwardMessages',
|
||||||
toPeer,
|
toPeer,
|
||||||
fromPeer: normalizeToInputPeer(await this.resolvePeer(fromChatId)),
|
fromPeer: await this.resolvePeer(fromChatId),
|
||||||
id: messages as number[],
|
id: messages as number[],
|
||||||
silent: params.silent,
|
silent: params.silent,
|
||||||
scheduleDate: normalizeDate(params.schedule),
|
scheduleDate: normalizeDate(params.schedule),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, Message, MtCuteArgumentError, MtCuteTypeAssertionError } from '../../types'
|
import { InputPeerLike, Message, MtCuteTypeAssertionError } from '../../types'
|
||||||
import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { createUsersChatsIndex, } from '../../utils/peer-utils'
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +57,7 @@ export async function getHistory(
|
||||||
params.offsetId ?? (params.reverse && !params.offsetDate ? 1 : 0)
|
params.offsetId ?? (params.reverse && !params.offsetDate ? 1 : 0)
|
||||||
const limit = params.limit || 100
|
const limit = params.limit || 100
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.getHistory',
|
_: 'messages.getHistory',
|
||||||
|
|
|
@ -4,7 +4,6 @@ import {
|
||||||
createUsersChatsIndex,
|
createUsersChatsIndex,
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { Message, InputPeerLike, MtCuteTypeAssertionError } from '../../types'
|
import { Message, InputPeerLike, MtCuteTypeAssertionError } from '../../types'
|
||||||
|
@ -53,7 +52,7 @@ export async function getMessages(
|
||||||
messageIds: MaybeArray<number>,
|
messageIds: MaybeArray<number>,
|
||||||
fromReply = false
|
fromReply = false
|
||||||
): Promise<MaybeArray<Message>> {
|
): Promise<MaybeArray<Message>> {
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
const isSingle = !Array.isArray(messageIds)
|
const isSingle = !Array.isArray(messageIds)
|
||||||
if (isSingle) messageIds = [messageIds as number]
|
if (isSingle) messageIds = [messageIds as number]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, Message } from '../../types'
|
import { InputPeerLike, Message } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate through a chat history sequentially.
|
* Iterate through a chat history sequentially.
|
||||||
|
@ -68,7 +67,7 @@ export async function* iterHistory(
|
||||||
const limit = Math.min(params.chunkSize || 100, total)
|
const limit = Math.min(params.chunkSize || 100, total)
|
||||||
|
|
||||||
// resolve peer once and pass an InputPeer afterwards
|
// resolve peer once and pass an InputPeer afterwards
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const messages = await this.getHistory(peer, {
|
const messages = await this.getHistory(peer, {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pin a message in a group, supergroup, channel or PM.
|
* Pin a message in a group, supergroup, channel or PM.
|
||||||
|
@ -23,7 +22,7 @@ export async function pinMessage(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.updatePinnedMessage',
|
_: 'messages.updatePinnedMessage',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
id: messageId,
|
id: messageId,
|
||||||
silent: !notify,
|
silent: !notify,
|
||||||
pmOneside: !bothSides
|
pmOneside: !bothSides
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { isInputPeerChannel, normalizeToInputChannel, normalizeToInputPeer } from '../../utils/peer-utils'
|
import {
|
||||||
|
isInputPeerChannel,
|
||||||
|
normalizeToInputChannel,
|
||||||
|
} from '../../utils/peer-utils'
|
||||||
import { createDummyUpdate } from '../../utils/updates-utils'
|
import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,16 +20,18 @@ export async function readHistory(
|
||||||
message = 0,
|
message = 0,
|
||||||
clearMentions = false
|
clearMentions = false
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
if (clearMentions) {
|
if (clearMentions) {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.readMentions',
|
_: 'messages.readMentions',
|
||||||
peer
|
peer,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isInputPeerChannel(peer)) {
|
if (isInputPeerChannel(peer)) {
|
||||||
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))
|
this._handleUpdate(
|
||||||
|
createDummyUpdate(res.pts, res.ptsCount, peer.channelId)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
}
|
}
|
||||||
|
@ -36,15 +41,14 @@ export async function readHistory(
|
||||||
await this.call({
|
await this.call({
|
||||||
_: 'channels.readHistory',
|
_: 'channels.readHistory',
|
||||||
channel: normalizeToInputChannel(peer),
|
channel: normalizeToInputChannel(peer),
|
||||||
maxId: message
|
maxId: message,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.readHistory',
|
_: 'messages.readHistory',
|
||||||
peer,
|
peer,
|
||||||
maxId: message
|
maxId: message,
|
||||||
})
|
})
|
||||||
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, Message, MtCuteTypeAssertionError } from '../../types'
|
import { InputPeerLike, Message, MtCuteTypeAssertionError } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import {
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
createUsersChatsIndex,
|
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
|
||||||
import { SearchFilters } from '../../types'
|
import { SearchFilters } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,11 +69,10 @@ export async function* searchMessages(
|
||||||
const total = params.limit || Infinity
|
const total = params.limit || Infinity
|
||||||
const limit = Math.min(params.chunkSize || 100, total)
|
const limit = Math.min(params.chunkSize || 100, total)
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
const fromUser =
|
const fromUser =
|
||||||
(params.fromUser
|
(params.fromUser ? await this.resolvePeer(params.fromUser) : null) ||
|
||||||
? normalizeToInputPeer(await this.resolvePeer(params.fromUser))
|
undefined
|
||||||
: null) || undefined
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, Message, ReplyMarkup } from '../../types'
|
import { InputPeerLike, Message, ReplyMarkup } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a message (i.e. send the same message,
|
* Copy a message (i.e. send the same message,
|
||||||
|
@ -79,7 +78,7 @@ export async function sendCopy(
|
||||||
clearDraft?: boolean
|
clearDraft?: boolean
|
||||||
}
|
}
|
||||||
): Promise<Message> {
|
): Promise<Message> {
|
||||||
const fromPeer = normalizeToInputPeer(await this.resolvePeer(fromChatId))
|
const fromPeer = await this.resolvePeer(fromChatId)
|
||||||
|
|
||||||
const msg = await this.getMessages(fromPeer, message)
|
const msg = await this.getMessages(fromPeer, message)
|
||||||
return msg.sendCopy(toChatId, params)
|
return msg.sendCopy(toChatId, params)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
Message,
|
Message,
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
@ -79,7 +78,7 @@ export async function sendMediaGroup(
|
||||||
): Promise<Message> {
|
): Promise<Message> {
|
||||||
if (!params) params = {}
|
if (!params) params = {}
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
||||||
|
|
||||||
const multiMedia: tl.RawInputSingleMedia[] = []
|
const multiMedia: tl.RawInputSingleMedia[] = []
|
||||||
|
|
|
@ -6,7 +6,6 @@ import {
|
||||||
Message,
|
Message,
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,7 +93,7 @@ export async function sendMedia(
|
||||||
(media as any).entities
|
(media as any).entities
|
||||||
)
|
)
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { inputPeerToPeer, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { inputPeerToPeer } from '../../utils/peer-utils'
|
||||||
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||||
import { InputPeerLike, Message, BotKeyboard, ReplyMarkup } from '../../types'
|
import { InputPeerLike, Message, BotKeyboard, ReplyMarkup } from '../../types'
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ export async function sendText(
|
||||||
params.entities
|
params.entities
|
||||||
)
|
)
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { InputPeerLike, TypingStatus } from '../../types'
|
import { InputPeerLike, TypingStatus } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a current user/bot typing event
|
* Sends a current user/bot typing event
|
||||||
|
@ -74,7 +73,7 @@ export async function sendTyping(
|
||||||
|
|
||||||
await this.call({
|
await this.call({
|
||||||
_: 'messages.setTyping',
|
_: 'messages.setTyping',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
action: status
|
action: status
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,7 @@ import {
|
||||||
Poll,
|
Poll,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
import {
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
createUsersChatsIndex,
|
|
||||||
normalizeToInputPeer,
|
|
||||||
} from '../../utils/peer-utils'
|
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +30,7 @@ export async function sendVote(
|
||||||
if (options === null) options = []
|
if (options === null) options = []
|
||||||
if (!Array.isArray(options)) options = [options]
|
if (!Array.isArray(options)) options = [options]
|
||||||
|
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
let poll: Poll | undefined = undefined
|
let poll: Poll | undefined = undefined
|
||||||
if (options.some((it) => typeof it === 'number')) {
|
if (options.some((it) => typeof it === 'number')) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { isInputPeerChannel, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { isInputPeerChannel } from '../../utils/peer-utils'
|
||||||
import { createDummyUpdate } from '../../utils/updates-utils'
|
import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +13,7 @@ export async function unpinAllMessages(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
chatId: InputPeerLike
|
chatId: InputPeerLike
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
|
const peer = await this.resolvePeer(chatId)
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.unpinAllMessages',
|
_: 'messages.unpinAllMessages',
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unpin a message in a group, supergroup, channel or PM.
|
* Unpin a message in a group, supergroup, channel or PM.
|
||||||
|
@ -19,7 +18,7 @@ export async function unpinMessage(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.updatePinnedMessage',
|
_: 'messages.updatePinnedMessage',
|
||||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
peer: await this.resolvePeer(chatId),
|
||||||
id: messageId,
|
id: messageId,
|
||||||
unpin: true
|
unpin: true
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Block a user
|
* Block a user
|
||||||
|
@ -14,6 +13,6 @@ export async function blockUser(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.call({
|
await this.call({
|
||||||
_: 'contacts.block',
|
_: 'contacts.block',
|
||||||
id: normalizeToInputPeer(await this.resolvePeer(id)),
|
id: await this.resolvePeer(id),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ export async function resolvePeerMany<
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
peerIds: InputPeerLike[],
|
peerIds: InputPeerLike[],
|
||||||
normalizer: (
|
normalizer: (
|
||||||
obj: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel
|
obj: tl.TypeInputPeer
|
||||||
) => T | null
|
) => T | null
|
||||||
): Promise<T[]>
|
): Promise<T[]>
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ export async function resolvePeerMany<
|
||||||
export async function resolvePeerMany(
|
export async function resolvePeerMany(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
peerIds: InputPeerLike[]
|
peerIds: InputPeerLike[]
|
||||||
): Promise<(tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel)[]>
|
): Promise<tl.TypeInputPeer[]>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -44,7 +44,7 @@ export async function resolvePeerMany(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
peerIds: InputPeerLike[],
|
peerIds: InputPeerLike[],
|
||||||
normalizer?: (
|
normalizer?: (
|
||||||
obj: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel
|
obj: tl.TypeInputPeer
|
||||||
) => tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | null
|
) => tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | null
|
||||||
): Promise<(tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel)[]> {
|
): Promise<(tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel)[]> {
|
||||||
const ret: (
|
const ret: (
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtCuteNotFoundError } from '../../types'
|
import { InputPeerLike, MtCuteNotFoundError } from '../../types'
|
||||||
import { getBasicPeerType, MAX_CHANNEL_ID } from '@mtcute/core'
|
import { getBasicPeerType, MAX_CHANNEL_ID } from '@mtcute/core'
|
||||||
import bigInt from 'big-integer'
|
import bigInt from 'big-integer'
|
||||||
|
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the `InputPeer` of a known peer id.
|
* Get the `InputPeer` of a known peer id.
|
||||||
|
@ -14,9 +15,9 @@ import bigInt from 'big-integer'
|
||||||
export async function resolvePeer(
|
export async function resolvePeer(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
peerId: InputPeerLike
|
peerId: InputPeerLike
|
||||||
): Promise<tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel> {
|
): Promise<tl.TypeInputPeer> {
|
||||||
// for convenience we also accept tl objects directly
|
// for convenience we also accept tl objects directly
|
||||||
if (typeof peerId === 'object') return peerId
|
if (typeof peerId === 'object') return normalizeToInputPeer(peerId)
|
||||||
|
|
||||||
if (typeof peerId === 'number') {
|
if (typeof peerId === 'number') {
|
||||||
const fromStorage = await this.storage.getPeerById(peerId)
|
const fromStorage = await this.storage.getPeerById(peerId)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unblock a user
|
* Unblock a user
|
||||||
|
@ -14,6 +13,6 @@ export async function unblockUser(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.call({
|
await this.call({
|
||||||
_: 'contacts.unblock',
|
_: 'contacts.unblock',
|
||||||
id: normalizeToInputPeer(await this.resolvePeer(id)),
|
id: await this.resolvePeer(id),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue