chore(client)!: renamed some peer utils
breaking: `normalizeToInput*` -> `toInput*`
This commit is contained in:
parent
8b2debb0aa
commit
895163c126
69 changed files with 167 additions and 193 deletions
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -27,7 +27,7 @@ export async function getBotInfo(
|
|||
|
||||
return client.call({
|
||||
_: 'bots.getBotInfo',
|
||||
bot: bot ? normalizeToInputUser(await resolvePeer(client, bot), bot) : undefined,
|
||||
bot: bot ? toInputUser(await resolvePeer(client, bot), bot) : undefined,
|
||||
langCode: langCode,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,6 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
|||
export async function getBotMenuButton(client: BaseTelegramClient, user: InputPeerLike): Promise<tl.TypeBotMenuButton> {
|
||||
return await client.call({
|
||||
_: 'bots.getBotMenuButton',
|
||||
userId: normalizeToInputUser(await resolvePeer(client, user), user),
|
||||
userId: toInputUser(await resolvePeer(client, user), user),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core'
|
|||
|
||||
import { GameHighScore, InputMessageId, InputPeerLike, normalizeInputMessageId, PeersIndex } from '../../types/index.js'
|
||||
import { normalizeInlineId } from '../../utils/inline-utils.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@ export async function getGameHighScores(
|
|||
let user: tl.TypeInputUser
|
||||
|
||||
if (userId) {
|
||||
user = normalizeToInputUser(await resolvePeer(client, userId), userId)
|
||||
user = toInputUser(await resolvePeer(client, userId), userId)
|
||||
} else {
|
||||
user = { _: 'inputUserEmpty' }
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ export async function getInlineGameHighScores(
|
|||
let user: tl.TypeInputUser
|
||||
|
||||
if (userId) {
|
||||
user = normalizeToInputUser(await resolvePeer(client, userId), userId)
|
||||
user = toInputUser(await resolvePeer(client, userId), userId)
|
||||
} else {
|
||||
user = { _: 'inputUserEmpty' }
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { assertNever, BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { BotCommands } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/** @internal */
|
||||
|
@ -22,7 +22,7 @@ export async function _normalizeCommandScope(
|
|||
}
|
||||
}
|
||||
case 'member': {
|
||||
const user = normalizeToInputUser(await resolvePeer(client, scope.user), scope.user)
|
||||
const user = toInputUser(await resolvePeer(client, scope.user), scope.user)
|
||||
const chat = await resolvePeer(client, scope.chat)
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ export async function setBotInfo(
|
|||
|
||||
await client.call({
|
||||
_: 'bots.setBotInfo',
|
||||
bot: bot ? normalizeToInputUser(await resolvePeer(client, bot), bot) : undefined,
|
||||
bot: bot ? toInputUser(await resolvePeer(client, bot), bot) : undefined,
|
||||
langCode: langCode,
|
||||
name,
|
||||
about: bio,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ export async function setBotMenuButton(
|
|||
): Promise<void> {
|
||||
await client.call({
|
||||
_: 'bots.setBotMenuButton',
|
||||
userId: normalizeToInputUser(await resolvePeer(client, user), user),
|
||||
userId: toInputUser(await resolvePeer(client, user), user),
|
||||
button,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core'
|
|||
|
||||
import { InputMessageId, InputPeerLike, Message, normalizeInputMessageId } from '../../types/index.js'
|
||||
import { normalizeInlineId } from '../../utils/inline-utils.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -43,7 +43,7 @@ export async function setGameScore(
|
|||
const { userId, score, noEdit, force, shouldDispatch } = params
|
||||
const { chatId, message } = normalizeInputMessageId(params)
|
||||
|
||||
const user = normalizeToInputUser(await resolvePeer(client, userId), userId)
|
||||
const user = toInputUser(await resolvePeer(client, userId), userId)
|
||||
const chat = await resolvePeer(client, chatId)
|
||||
|
||||
const res = await client.call({
|
||||
|
@ -89,7 +89,7 @@ export async function setInlineGameScore(
|
|||
): Promise<void> {
|
||||
const { messageId, userId, score, noEdit, force } = params
|
||||
|
||||
const user = normalizeToInputUser(await resolvePeer(client, userId), userId)
|
||||
const user = toInputUser(await resolvePeer(client, userId), userId)
|
||||
|
||||
const id = normalizeInlineId(messageId)
|
||||
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
import { BaseTelegramClient, MaybeArray } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import {
|
||||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
normalizeToInputChannel,
|
||||
normalizeToInputUser,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||
|
||||
|
@ -38,7 +33,7 @@ export async function addChatMembers(
|
|||
|
||||
if (isInputPeerChat(chat)) {
|
||||
for (const user of users) {
|
||||
const p = normalizeToInputUser(await resolvePeer(client, user))
|
||||
const p = toInputUser(await resolvePeer(client, user))
|
||||
|
||||
const updates = await client.call({
|
||||
_: 'messages.addChatUser',
|
||||
|
@ -51,8 +46,8 @@ export async function addChatMembers(
|
|||
} else if (isInputPeerChannel(chat)) {
|
||||
const updates = await client.call({
|
||||
_: 'channels.inviteToChannel',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
users: await resolvePeerMany(client, users, normalizeToInputUser),
|
||||
channel: toInputChannel(chat),
|
||||
users: await resolvePeerMany(client, users, toInputUser),
|
||||
})
|
||||
|
||||
client.network.handleUpdate(updates)
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
import { BaseTelegramClient, MtTypeAssertionError } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, Message, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import {
|
||||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
normalizeToInputChannel,
|
||||
normalizeToInputUser,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -44,7 +39,7 @@ export async function banChatMember(
|
|||
if (isInputPeerChannel(chat)) {
|
||||
res = await client.call({
|
||||
_: 'channels.editBanned',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
participant: peer,
|
||||
bannedRights: {
|
||||
_: 'chatBannedRights',
|
||||
|
@ -57,7 +52,7 @@ export async function banChatMember(
|
|||
res = await client.call({
|
||||
_: 'messages.deleteChatUser',
|
||||
chatId: chat.chatId,
|
||||
userId: normalizeToInputUser(peer),
|
||||
userId: toInputUser(peer),
|
||||
})
|
||||
} else throw new MtInvalidPeerTypeError(chatId, 'chat or channel')
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, MaybeArray } from '@mtcute/core'
|
||||
|
||||
import { Chat, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils.js'
|
||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||
|
||||
|
@ -38,7 +38,7 @@ export async function createGroup(
|
|||
|
||||
if (!Array.isArray(users)) users = [users]
|
||||
|
||||
const peers = await resolvePeerMany(client, users, normalizeToInputUser)
|
||||
const peers = await resolvePeerMany(client, users, toInputUser)
|
||||
|
||||
const res = await client.call({
|
||||
_: 'messages.createChat',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
// @alias=deleteSupergroup
|
||||
|
@ -13,7 +13,7 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
|||
export async function deleteChannel(client: BaseTelegramClient, chatId: InputPeerLike): Promise<void> {
|
||||
const res = await client.call({
|
||||
_: 'channels.deleteChannel',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
})
|
||||
client.network.handleUpdate(res)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ export async function deleteChatPhoto(client: BaseTelegramClient, chatId: InputP
|
|||
} else if (isInputPeerChannel(chat)) {
|
||||
res = await client.call({
|
||||
_: 'channels.editPhoto',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
photo: { _: 'inputChatPhotoEmpty' },
|
||||
})
|
||||
} else throw new MtInvalidPeerTypeError(chatId, 'chat or channel')
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { createDummyUpdate } from '../../utils/updates-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -19,7 +19,7 @@ export async function deleteUserHistory(
|
|||
): Promise<void> {
|
||||
const { chatId, participantId } = params
|
||||
|
||||
const channel = normalizeToInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
const channel = toInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
|
||||
const peer = await resolvePeer(client, participantId)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel, normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -22,8 +22,8 @@ export async function editAdminRights(
|
|||
): Promise<void> {
|
||||
const { chatId, userId, rights, rank = '' } = params
|
||||
|
||||
const chat = normalizeToInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
const user = normalizeToInputUser(await resolvePeer(client, userId), userId)
|
||||
const chat = toInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
const user = toInputUser(await resolvePeer(client, userId), userId)
|
||||
|
||||
const res = await client.call({
|
||||
_: 'channels.editAdmin',
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, Long, tl } from '@mtcute/core'
|
|||
|
||||
import { ChatEvent, InputPeerLike, PeersIndex } from '../../types/index.js'
|
||||
import { InputChatEventFilters, normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js'
|
||||
import { normalizeToInputChannel, normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||
|
||||
|
@ -74,11 +74,9 @@ export async function getChatEventLog(
|
|||
): Promise<ChatEvent[]> {
|
||||
const { maxId = Long.ZERO, minId = Long.ZERO, query = '', limit = 100, users, filters } = params ?? {}
|
||||
|
||||
const channel = normalizeToInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
const channel = toInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
|
||||
const admins: tl.TypeInputUser[] | undefined = users ?
|
||||
await resolvePeerMany(client, users, normalizeToInputUser) :
|
||||
undefined
|
||||
const admins: tl.TypeInputUser[] | undefined = users ? await resolvePeerMany(client, users, toInputUser) : undefined
|
||||
|
||||
const { serverFilter, localFilter } = normalizeChatEventFilters(filters)
|
||||
|
||||
|
|
|
@ -2,12 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core'
|
|||
import { assertTypeIs } from '@mtcute/core/utils.js'
|
||||
|
||||
import { ChatMember, InputPeerLike, MtInvalidPeerTypeError, PeersIndex } from '../../types/index.js'
|
||||
import {
|
||||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
isInputPeerUser,
|
||||
normalizeToInputChannel,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, isInputPeerUser, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -62,7 +57,7 @@ export async function getChatMember(
|
|||
try {
|
||||
const res = await client.call({
|
||||
_: 'channels.getParticipant',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
participant: user,
|
||||
})
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import { assertTypeIs } from '@mtcute/core/utils.js'
|
|||
|
||||
import { ArrayWithTotal, ChatMember, InputPeerLike, MtInvalidPeerTypeError, PeersIndex } from '../../types/index.js'
|
||||
import { makeArrayWithTotal } from '../../utils/index.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -123,7 +123,7 @@ export async function getChatMembers(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.getParticipants',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
filter,
|
||||
offset,
|
||||
limit,
|
||||
|
|
|
@ -6,8 +6,8 @@ import {
|
|||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
isInputPeerUser,
|
||||
normalizeToInputChannel,
|
||||
normalizeToInputUser,
|
||||
toInputChannel,
|
||||
toInputUser,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { _getChannelsBatched, _getChatsBatched, _getUsersBatched } from './batched-queries.js'
|
||||
|
@ -43,9 +43,9 @@ export async function getChat(client: BaseTelegramClient, chatId: InputPeerLike)
|
|||
|
||||
let res: tl.TypeChat | tl.TypeUser | null
|
||||
if (isInputPeerChannel(peer)) {
|
||||
res = await _getChannelsBatched(client, normalizeToInputChannel(peer))
|
||||
res = await _getChannelsBatched(client, toInputChannel(peer))
|
||||
} else if (isInputPeerUser(peer)) {
|
||||
res = await _getUsersBatched(client, normalizeToInputUser(peer))
|
||||
res = await _getUsersBatched(client, toInputUser(peer))
|
||||
} else if (isInputPeerChat(peer)) {
|
||||
res = await _getChatsBatched(client, peer.chatId)
|
||||
} else throw new Error('should not happen')
|
||||
|
|
|
@ -6,8 +6,8 @@ import {
|
|||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
isInputPeerUser,
|
||||
normalizeToInputChannel,
|
||||
normalizeToInputUser,
|
||||
toInputChannel,
|
||||
toInputUser,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -45,12 +45,12 @@ export async function getFullChat(client: BaseTelegramClient, chatId: InputPeerL
|
|||
if (isInputPeerChannel(peer)) {
|
||||
res = await client.call({
|
||||
_: 'channels.getFullChannel',
|
||||
channel: normalizeToInputChannel(peer),
|
||||
channel: toInputChannel(peer),
|
||||
})
|
||||
} else if (isInputPeerUser(peer)) {
|
||||
res = await client.call({
|
||||
_: 'users.getFullUser',
|
||||
id: normalizeToInputUser(peer)!,
|
||||
id: toInputUser(peer)!,
|
||||
})
|
||||
} else if (isInputPeerChat(peer)) {
|
||||
res = await client.call({
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
|
||||
import { ArrayWithTotal, Chat, InputPeerLike } from '../../types/index.js'
|
||||
import { makeArrayWithTotal } from '../../utils/misc-utils.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
// @available=user
|
||||
|
@ -21,7 +21,7 @@ export async function getSimilarChannels(
|
|||
): Promise<ArrayWithTotal<Chat>> {
|
||||
const res = await client.call({
|
||||
_: 'channels.getChannelRecommendations',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, channel), channel),
|
||||
channel: toInputChannel(await resolvePeer(client, channel), channel),
|
||||
})
|
||||
|
||||
const parsed = res.chats.map((chat) => new Chat(chat))
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, Long, tl } from '@mtcute/core'
|
|||
|
||||
import { ChatEvent, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js'
|
||||
import { normalizeToInputChannel, normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||
import { getChatEventLog } from './get-chat-event-log.js'
|
||||
|
@ -37,13 +37,11 @@ export async function* iterChatEventLog(
|
|||
): AsyncIterableIterator<ChatEvent> {
|
||||
if (!params) params = {}
|
||||
|
||||
const channel = normalizeToInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
const channel = toInputChannel(await resolvePeer(client, chatId), chatId)
|
||||
|
||||
const { minId = Long.ZERO, query = '', limit = Infinity, chunkSize = 100, users, filters } = params
|
||||
|
||||
const admins: tl.TypeInputUser[] | undefined = users ?
|
||||
await resolvePeerMany(client, users, normalizeToInputUser) :
|
||||
undefined
|
||||
const admins: tl.TypeInputUser[] | undefined = users ? await resolvePeerMany(client, users, toInputUser) : undefined
|
||||
|
||||
const { serverFilter, localFilter } = normalizeChatEventFilters(filters)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { Chat, InputPeerLike } from '../../types/index.js'
|
||||
import { INVITE_LINK_REGEX, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { INVITE_LINK_REGEX, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -35,7 +35,7 @@ export async function joinChat(client: BaseTelegramClient, chatId: InputPeerLike
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.joinChannel',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
})
|
||||
|
||||
assertIsUpdatesGroup('channels.joinChannel', res)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { deleteHistory } from './delete-history.js'
|
||||
|
||||
|
@ -25,7 +25,7 @@ export async function leaveChat(
|
|||
if (isInputPeerChannel(chat)) {
|
||||
const res = await client.call({
|
||||
_: 'channels.leaveChannel',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
})
|
||||
client.network.handleUpdate(res)
|
||||
} else if (isInputPeerChat(chat)) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, normalizeToInputChannel, normalizeToInputUser } from '../../utils/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -33,13 +33,13 @@ export async function reorderUsernames(
|
|||
// bot
|
||||
await client.call({
|
||||
_: 'bots.reorderUsernames',
|
||||
bot: normalizeToInputUser(peer, peerId),
|
||||
bot: toInputUser(peer, peerId),
|
||||
order,
|
||||
})
|
||||
} else if (isInputPeerChannel(peer)) {
|
||||
await client.call({
|
||||
_: 'channels.reorderUsernames',
|
||||
channel: normalizeToInputChannel(peer, peerId),
|
||||
channel: toInputChannel(peer, peerId),
|
||||
order,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core'
|
|||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { normalizeDate } from '../../utils/misc-utils.js'
|
||||
import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ export async function restrictChatMember(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.editBanned',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
participant: user,
|
||||
bannedRights: {
|
||||
_: 'chatBannedRights',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, MtTypeAssertionError, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, normalizeToInputChannel } from '../../utils/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, toInputChannel } from '../../utils/index.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -45,7 +45,7 @@ export async function setChatColor(
|
|||
if (isInputPeerChannel(peer)) {
|
||||
const res = await client.call({
|
||||
_: 'channels.updateColor',
|
||||
channel: normalizeToInputChannel(peer),
|
||||
channel: toInputChannel(peer),
|
||||
color,
|
||||
backgroundEmojiId,
|
||||
})
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, MtArgumentError, tl } from '@mtcute/core'
|
|||
import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id'
|
||||
|
||||
import { InputFileLike, InputPeerLike, isUploadedFile, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { uploadFile } from '../files/upload-file.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -95,7 +95,7 @@ export async function setChatPhoto(
|
|||
} else {
|
||||
res = await client.call({
|
||||
_: 'channels.editPhoto',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
photo,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,7 @@ export async function setChatTitle(client: BaseTelegramClient, chatId: InputPeer
|
|||
} else if (isInputPeerChannel(chat)) {
|
||||
res = await client.call({
|
||||
_: 'channels.editTitle',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
title,
|
||||
})
|
||||
} else throw new MtInvalidPeerTypeError(chatId, 'chat or channel')
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ export async function setChatUsername(
|
|||
): Promise<void> {
|
||||
await client.call({
|
||||
_: 'channels.updateUsername',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
username: username || '',
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
|||
export async function setSlowMode(client: BaseTelegramClient, chatId: InputPeerLike, seconds = 0): Promise<void> {
|
||||
const res = await client.call({
|
||||
_: 'channels.toggleSlowMode',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
seconds,
|
||||
})
|
||||
client.network.handleUpdate(res)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, normalizeToInputChannel, normalizeToInputUser } from '../../utils/index.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -49,14 +49,14 @@ export async function toggleFragmentUsername(
|
|||
// bot
|
||||
await client.call({
|
||||
_: 'bots.toggleUsername',
|
||||
bot: normalizeToInputUser(peer, peerId),
|
||||
bot: toInputUser(peer, peerId),
|
||||
username,
|
||||
active,
|
||||
})
|
||||
} else if (isInputPeerChannel(peer)) {
|
||||
await client.call({
|
||||
_: 'channels.toggleUsername',
|
||||
channel: normalizeToInputChannel(peer, peerId),
|
||||
channel: toInputChannel(peer, peerId),
|
||||
username,
|
||||
active,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ export async function toggleJoinRequests(
|
|||
): Promise<void> {
|
||||
const res = await client.call({
|
||||
_: 'channels.toggleJoinRequest',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
enabled,
|
||||
})
|
||||
client.network.handleUpdate(res)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ export async function toggleJoinToSend(
|
|||
): Promise<void> {
|
||||
const res = await client.call({
|
||||
_: 'channels.toggleJoinToSend',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
enabled,
|
||||
})
|
||||
client.network.handleUpdate(res)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
// @alias=unrestrictChatMember
|
||||
|
@ -30,7 +30,7 @@ export async function unbanChatMember(
|
|||
if (isInputPeerChannel(chat)) {
|
||||
const res = await client.call({
|
||||
_: 'channels.editBanned',
|
||||
channel: normalizeToInputChannel(chat),
|
||||
channel: toInputChannel(chat),
|
||||
participant: peer,
|
||||
bannedRights: {
|
||||
_: 'chatBannedRights',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, User } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -39,7 +39,7 @@ export async function addContact(
|
|||
},
|
||||
): Promise<User> {
|
||||
const { userId, firstName, lastName = '', phone = '', sharePhone = false } = params
|
||||
const peer = normalizeToInputUser(await resolvePeer(client, userId), userId)
|
||||
const peer = toInputUser(await resolvePeer(client, userId), userId)
|
||||
|
||||
const res = await client.call({
|
||||
_: 'contacts.addContact',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, MaybeArray } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, MtInvalidPeerTypeError, User } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils.js'
|
||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||
|
||||
|
@ -16,7 +16,7 @@ import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
|||
export async function deleteContacts(client: BaseTelegramClient, userIds: MaybeArray<InputPeerLike>): Promise<User[]> {
|
||||
if (!Array.isArray(userIds)) userIds = [userIds]
|
||||
|
||||
const inputPeers = await resolvePeerMany(client, userIds, normalizeToInputUser)
|
||||
const inputPeers = await resolvePeerMany(client, userIds, toInputUser)
|
||||
|
||||
if (!inputPeers.length) {
|
||||
throw new MtInvalidPeerTypeError('all provided ids', 'user')
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core'
|
|||
import { randomLong } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike, Message } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -50,7 +50,7 @@ export async function createForumTopic(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.createForumTopic',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
title,
|
||||
iconColor: typeof icon === 'number' ? icon : undefined,
|
||||
iconEmojiId: typeof icon !== 'number' ? icon : undefined,
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
import { assertTypeIsNot } from '@mtcute/core/utils.js'
|
||||
|
||||
import type { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { createDummyUpdate } from '../../utils/updates-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -17,7 +17,7 @@ export async function deleteForumTopicHistory(
|
|||
chat: InputPeerLike,
|
||||
topicId: number | ForumTopic,
|
||||
): Promise<void> {
|
||||
const channel = normalizeToInputChannel(await resolvePeer(client, chat), chat)
|
||||
const channel = toInputChannel(await resolvePeer(client, chat), chat)
|
||||
assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty')
|
||||
|
||||
const res = await client.call({
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, Long, tl } from '@mtcute/core'
|
||||
|
||||
import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -47,7 +47,7 @@ export async function editForumTopic(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.editForumTopic',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
||||
title,
|
||||
iconEmojiId: icon ? icon ?? Long.ZERO : undefined,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, MaybeArray } from '@mtcute/core'
|
||||
|
||||
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/index.js'
|
||||
import { toInputChannel } from '../../utils/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@ export async function getForumTopicsById(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.getForumTopicsByID',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId)),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId)),
|
||||
topics: ids,
|
||||
})
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
|
||||
import { ArrayPaginated, ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||
import { makeArrayPaginated } from '../../utils/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
// @exported
|
||||
|
@ -55,7 +55,7 @@ export async function getForumTopics(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.getForumTopics',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
q: query,
|
||||
offsetDate,
|
||||
offsetId,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { getForumTopics } from './get-forum-topics.js'
|
||||
|
||||
|
@ -31,7 +31,7 @@ export async function* iterForumTopics(
|
|||
|
||||
const { query, limit = Infinity, chunkSize = 100 } = params
|
||||
|
||||
const peer = normalizeToInputChannel(await resolvePeer(client, chatId))
|
||||
const peer = toInputChannel(await resolvePeer(client, chatId))
|
||||
|
||||
let { offset } = params
|
||||
let current = 0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import type { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -29,7 +29,7 @@ export async function reorderPinnedForumTopics(
|
|||
const { chatId, order, force } = params
|
||||
await client.call({
|
||||
_: 'channels.reorderPinnedForumTopics',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
order: order.map((it) => (typeof it === 'number' ? it : it.id)),
|
||||
force,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -35,7 +35,7 @@ export async function toggleForumTopicClosed(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'channels.editForumTopic',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
||||
closed,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ export async function toggleForumTopicPinned(
|
|||
|
||||
await client.call({
|
||||
_: 'channels.updatePinnedForumTopic',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
||||
pinned,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,7 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
|||
export async function toggleForum(client: BaseTelegramClient, chatId: InputPeerLike, enabled = false): Promise<void> {
|
||||
const res = await client.call({
|
||||
_: 'channels.toggleForum',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
enabled,
|
||||
})
|
||||
client.network.handleUpdate(res)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, Message } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -30,7 +30,7 @@ export async function toggleGeneralTopicHidden(
|
|||
const { chatId, hidden, shouldDispatch } = params
|
||||
const res = await client.call({
|
||||
_: 'channels.editForumTopic',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
topicId: 1,
|
||||
hidden,
|
||||
})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { ArrayPaginated, ChatInviteLink, ChatInviteLinkMember, InputPeerLike, PeersIndex } from '../../types/index.js'
|
||||
import { makeArrayPaginated, normalizeDate, normalizeToInputUser } from '../../utils/index.js'
|
||||
import { makeArrayPaginated, normalizeDate, toInputUser } from '../../utils/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ export async function getInviteLinkMembers(
|
|||
const nextOffset = last ?
|
||||
{
|
||||
date: last.raw.date,
|
||||
user: normalizeToInputUser(last.user.inputPeer),
|
||||
user: toInputUser(last.user.inputPeer),
|
||||
} :
|
||||
undefined
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core'
|
|||
|
||||
import { ArrayPaginated, ChatInviteLink, InputPeerLike, PeersIndex } from '../../types/index.js'
|
||||
import { makeArrayPaginated } from '../../utils/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
// @exported
|
||||
|
@ -59,7 +59,7 @@ export async function getInviteLinks(
|
|||
_: 'messages.getExportedChatInvites',
|
||||
peer: await resolvePeer(client, chatId),
|
||||
revoked,
|
||||
adminId: admin ? normalizeToInputUser(await resolvePeer(client, admin), admin) : { _: 'inputUserSelf' },
|
||||
adminId: admin ? toInputUser(await resolvePeer(client, admin), admin) : { _: 'inputUserSelf' },
|
||||
limit,
|
||||
offsetDate: offset?.date,
|
||||
offsetLink: offset?.link,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ export async function hideJoinRequest(
|
|||
): Promise<void> {
|
||||
const { chatId, user, action } = params
|
||||
|
||||
const userId = normalizeToInputUser(await resolvePeer(client, user), user)
|
||||
const userId = toInputUser(await resolvePeer(client, user), user)
|
||||
|
||||
await client.call({
|
||||
_: 'messages.hideChatJoinRequest',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, Message } from '../../types/index.js'
|
||||
import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { createDummyUpdate } from '../../utils/updates-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { deleteScheduledMessages } from './delete-scheduled-messages.js'
|
||||
|
@ -36,7 +36,7 @@ export async function deleteMessagesById(
|
|||
let upd
|
||||
|
||||
if (isInputPeerChannel(peer)) {
|
||||
const channel = normalizeToInputChannel(peer)
|
||||
const channel = toInputChannel(peer)
|
||||
const res = await client.call({
|
||||
_: 'channels.deleteMessages',
|
||||
channel,
|
||||
|
|
|
@ -3,7 +3,7 @@ import { assertTypeIsNot } from '@mtcute/core/utils.js'
|
|||
|
||||
import { Message } from '../../types/messages/index.js'
|
||||
import { InputPeerLike, PeersIndex } from '../../types/peers/index.js'
|
||||
import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -42,7 +42,7 @@ export async function getMessages(
|
|||
{
|
||||
_: 'channels.getMessages',
|
||||
id: ids,
|
||||
channel: normalizeToInputChannel(peer),
|
||||
channel: toInputChannel(peer),
|
||||
} :
|
||||
{
|
||||
_: 'messages.getMessages',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js'
|
||||
import { createDummyUpdate } from '../../utils/updates-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -47,7 +47,7 @@ export async function readHistory(
|
|||
if (isInputPeerChannel(peer)) {
|
||||
await client.call({
|
||||
_: 'channels.readHistory',
|
||||
channel: normalizeToInputChannel(peer),
|
||||
channel: toInputChannel(peer),
|
||||
maxId,
|
||||
})
|
||||
} else {
|
||||
|
|
|
@ -4,7 +4,7 @@ import { MtMessageNotFoundError } from '../../types/errors.js'
|
|||
import { Message } from '../../types/messages/message.js'
|
||||
import { TextWithEntities } from '../../types/misc/entities.js'
|
||||
import { InputPeerLike } from '../../types/peers/index.js'
|
||||
import { normalizeMessageId, normalizeToInputUser } from '../../utils/index.js'
|
||||
import { normalizeMessageId, toInputUser } from '../../utils/index.js'
|
||||
import { _normalizeInputText } from '../misc/normalize-text.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { _getDiscussionMessage } from './get-discussion-message.js'
|
||||
|
@ -145,7 +145,7 @@ export async function _processCommonSendParameters(
|
|||
tlReplyTo = {
|
||||
_: 'inputReplyToStory',
|
||||
storyId: params.replyToStory,
|
||||
userId: normalizeToInputUser(peer),
|
||||
userId: toInputUser(peer),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputPrivacyRule } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/index.js'
|
||||
import { toInputUser } from '../../utils/index.js'
|
||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ export async function _normalizePrivacyRules(
|
|||
}
|
||||
|
||||
if ('users' in rule) {
|
||||
const users = await resolvePeerMany(client, rule.users, normalizeToInputUser)
|
||||
const users = await resolvePeerMany(client, rule.users, toInputUser)
|
||||
|
||||
res.push({
|
||||
_: rule.allow ? 'inputPrivacyValueAllowUsers' : 'inputPrivacyValueDisallowUsers',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, tl } from '@mtcute/core'
|
||||
|
||||
import { InputText } from '../../types/misc/entities.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
const empty: [string, undefined] = ['', undefined]
|
||||
|
@ -26,7 +26,7 @@ export async function _normalizeInputText(
|
|||
for (const ent of entities) {
|
||||
if (ent._ === 'messageEntityMentionName') {
|
||||
try {
|
||||
const inputPeer = normalizeToInputUser(await resolvePeer(client, ent.userId), ent.userId)
|
||||
const inputPeer = toInputUser(await resolvePeer(client, ent.userId), ent.userId)
|
||||
|
||||
const ent_ = ent as unknown as tl.RawInputMessageEntityMentionName
|
||||
ent_._ = 'inputMessageEntityMentionName'
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
StickerSourceType,
|
||||
StickerType,
|
||||
} from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { _normalizeFileToDocument } from '../files/normalize-file-to-document.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
|
@ -97,7 +97,7 @@ export async function createStickerSet(
|
|||
progressCallback?: (idx: number, uploaded: number, total: number) => void
|
||||
},
|
||||
): Promise<StickerSet> {
|
||||
const owner = normalizeToInputUser(await resolvePeer(client, params.owner), params.owner)
|
||||
const owner = toInputUser(await resolvePeer(client, params.owner), params.owner)
|
||||
|
||||
const inputStickers: tl.TypeInputStickerSetItem[] = []
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, InputStickerSet, normalizeInputStickerSet } from '../../types/index.js'
|
||||
import { normalizeToInputChannel } from '../../utils/index.js'
|
||||
import { toInputChannel } from '../../utils/index.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ export async function setChatStickerSet(
|
|||
): Promise<void> {
|
||||
await client.call({
|
||||
_: 'channels.setStickers',
|
||||
channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
||||
stickerset: normalizeInputStickerSet(setId),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -3,12 +3,7 @@ import { assertNever, BaseTelegramClient, MaybeAsync, MtArgumentError, tl } from
|
|||
import { getBarePeerId, getMarkedPeerId, markedPeerIdToBare, toggleChannelIdMark } from '@mtcute/core/utils.js'
|
||||
|
||||
import { PeersIndex } from '../../types/index.js'
|
||||
import {
|
||||
isInputPeerChannel,
|
||||
isInputPeerUser,
|
||||
normalizeToInputChannel,
|
||||
normalizeToInputUser,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
||||
import { RpsMeter } from '../../utils/rps-meter.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { _getChannelsBatched, _getUsersBatched } from '../chats/batched-queries.js'
|
||||
|
@ -688,7 +683,7 @@ async function fetchChannelDifference(
|
|||
return false
|
||||
}
|
||||
|
||||
const channel = normalizeToInputChannel(await resolvePeer(client, toggleChannelIdMark(channelId)))
|
||||
const channel = toInputChannel(await resolvePeer(client, toggleChannelIdMark(channelId)))
|
||||
|
||||
if (channel._ === 'inputChannel' && channel.accessHash.isZero()) {
|
||||
state.log.debug('fetchChannelDifference failed for channel %d: input peer not found', channelId)
|
||||
|
@ -1115,9 +1110,9 @@ async function onUpdate(
|
|||
|
||||
// the peer will be automatically cached by the `.call()`, we don't have to do anything
|
||||
if (isInputPeerChannel(peer)) {
|
||||
return _getChannelsBatched(client, normalizeToInputChannel(peer))
|
||||
return _getChannelsBatched(client, toInputChannel(peer))
|
||||
} else if (isInputPeerUser(peer)) {
|
||||
return _getUsersBatched(client, normalizeToInputUser(peer))
|
||||
return _getUsersBatched(client, toInputUser(peer))
|
||||
}
|
||||
|
||||
state.log.warn('cannot fetch full peer %d - unknown peer type %s', id, peer._)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/index.js'
|
||||
import { toInputUser } from '../../utils/index.js'
|
||||
import { resolvePeerMany } from './resolve-peer-many.js'
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ export async function editCloseFriendsRaw(client: BaseTelegramClient, ids: numbe
|
|||
export async function editCloseFriends(client: BaseTelegramClient, ids: InputPeerLike[]): Promise<void> {
|
||||
await client.call({
|
||||
_: 'contacts.editCloseFriends',
|
||||
id: await resolvePeerMany(client, ids, normalizeToInputUser).then((r) =>
|
||||
id: await resolvePeerMany(client, ids, toInputUser).then((r) =>
|
||||
r.map((u) => {
|
||||
if ('userId' in u) return u.userId
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { Chat, InputPeerLike } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from './resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -14,7 +14,7 @@ export async function getCommonChats(client: BaseTelegramClient, userId: InputPe
|
|||
return client
|
||||
.call({
|
||||
_: 'messages.getCommonChats',
|
||||
userId: normalizeToInputUser(await resolvePeer(client, userId), userId),
|
||||
userId: toInputUser(await resolvePeer(client, userId), userId),
|
||||
maxId: 0,
|
||||
limit: 100,
|
||||
})
|
||||
|
|
|
@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core'
|
|||
import { assertTypeIs } from '@mtcute/core/utils.js'
|
||||
|
||||
import { InputPeerLike, Photo } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from './resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,7 @@ export async function getProfilePhoto(
|
|||
): Promise<Photo> {
|
||||
const res = await client.call({
|
||||
_: 'photos.getUserPhotos',
|
||||
userId: normalizeToInputUser(await resolvePeer(client, userId), userId),
|
||||
userId: toInputUser(await resolvePeer(client, userId), userId),
|
||||
offset: -1,
|
||||
limit: 1,
|
||||
maxId: photoId,
|
||||
|
|
|
@ -3,7 +3,7 @@ import { assertTypeIs } from '@mtcute/core/utils.js'
|
|||
|
||||
import { ArrayPaginated, InputPeerLike, Photo } from '../../types/index.js'
|
||||
import { makeArrayPaginated } from '../../utils/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from './resolve-peer.js'
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ export async function getProfilePhotos(
|
|||
|
||||
const res = await client.call({
|
||||
_: 'photos.getUserPhotos',
|
||||
userId: normalizeToInputUser(await resolvePeer(client, userId), userId),
|
||||
userId: toInputUser(await resolvePeer(client, userId), userId),
|
||||
offset,
|
||||
limit,
|
||||
maxId: Long.ZERO,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient, MaybeArray } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, User } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { _getUsersBatched } from '../chats/batched-queries.js'
|
||||
import { resolvePeer } from './resolve-peer.js'
|
||||
import { resolvePeerMany } from './resolve-peer-many.js'
|
||||
|
@ -17,12 +17,12 @@ import { resolvePeerMany } from './resolve-peer-many.js'
|
|||
export async function getUsers(client: BaseTelegramClient, ids: MaybeArray<InputPeerLike>): Promise<(User | null)[]> {
|
||||
if (!Array.isArray(ids)) {
|
||||
// avoid unnecessary overhead of Promise.all and resolvePeerMany
|
||||
const res = await _getUsersBatched(client, normalizeToInputUser(await resolvePeer(client, ids)))
|
||||
const res = await _getUsersBatched(client, toInputUser(await resolvePeer(client, ids)))
|
||||
|
||||
return [res ? new User(res) : null]
|
||||
}
|
||||
|
||||
const inputPeers = await resolvePeerMany(client, ids, normalizeToInputUser)
|
||||
const inputPeers = await resolvePeerMany(client, ids, toInputUser)
|
||||
|
||||
// pooling will be done by the helper
|
||||
const res = await Promise.all(inputPeers.map((peer) => _getUsersBatched(client, peer)))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BaseTelegramClient } from '@mtcute/core'
|
||||
|
||||
import { InputPeerLike, Photo } from '../../types/index.js'
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { getProfilePhotos } from './get-profile-photos.js'
|
||||
import { resolvePeer } from './resolve-peer.js'
|
||||
|
||||
|
@ -32,7 +32,7 @@ export async function* iterProfilePhotos(
|
|||
): AsyncIterableIterator<Photo> {
|
||||
if (!params) params = {}
|
||||
|
||||
const peer = normalizeToInputUser(await resolvePeer(client, userId), userId)
|
||||
const peer = toInputUser(await resolvePeer(client, userId), userId)
|
||||
|
||||
const { limit = Infinity, chunkSize = 100 } = params
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
|
||||
import { MtPeerNotFoundError } from '../../types/errors.js'
|
||||
import { InputPeerLike } from '../../types/peers/index.js'
|
||||
import { normalizeToInputPeer } from '../../utils/peer-utils.js'
|
||||
import { toInputPeer } from '../../utils/peer-utils.js'
|
||||
|
||||
// @available=both
|
||||
/**
|
||||
|
@ -33,7 +33,7 @@ export async function resolvePeer(
|
|||
// User | Chat
|
||||
peerId = peerId.inputPeer
|
||||
} else {
|
||||
peerId = normalizeToInputPeer(peerId)
|
||||
peerId = toInputPeer(peerId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { assertNever, tl } from '@mtcute/core'
|
||||
import { utf8EncodeToBuffer } from '@mtcute/core/utils.js'
|
||||
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils.js'
|
||||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { BotKeyboardBuilder } from './keyboard-builder.js'
|
||||
|
||||
/**
|
||||
|
@ -345,7 +345,7 @@ export namespace BotKeyboard {
|
|||
return {
|
||||
_: 'inputKeyboardButtonUserProfile',
|
||||
text,
|
||||
userId: normalizeToInputUser(user),
|
||||
userId: toInputUser(user),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ import {
|
|||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
isInputPeerUser,
|
||||
normalizeToInputChannel,
|
||||
normalizeToInputPeer,
|
||||
normalizeToInputUser,
|
||||
toInputChannel,
|
||||
toInputPeer,
|
||||
toInputUser,
|
||||
} from './peer-utils.js'
|
||||
|
||||
describe('normalizeToInputPeer', () => {
|
||||
describe('toInputPeer', () => {
|
||||
it.each([
|
||||
['inputChannelEmpty', 'inputPeerEmpty'],
|
||||
['inputUserEmpty', 'inputPeerEmpty'],
|
||||
|
@ -27,7 +27,7 @@ describe('normalizeToInputPeer', () => {
|
|||
const from = createStub(fromType)
|
||||
const to = createStub(toType)
|
||||
|
||||
expect(normalizeToInputPeer(from)).toEqual(to)
|
||||
expect(toInputPeer(from)).toEqual(to)
|
||||
})
|
||||
|
||||
it.each([
|
||||
|
@ -40,11 +40,11 @@ describe('normalizeToInputPeer', () => {
|
|||
] as const)('should keep %s as is', (type) => {
|
||||
const obj = createStub(type)
|
||||
|
||||
expect(normalizeToInputPeer(obj)).toBe(obj)
|
||||
expect(toInputPeer(obj)).toBe(obj)
|
||||
})
|
||||
})
|
||||
|
||||
describe('normalizeToInputUser', () => {
|
||||
describe('toInputUser', () => {
|
||||
it.each([
|
||||
['inputPeerSelf', 'inputUserSelf'],
|
||||
['inputPeerUser', 'inputUser'],
|
||||
|
@ -53,17 +53,15 @@ describe('normalizeToInputUser', () => {
|
|||
const from = createStub(fromType)
|
||||
const to = createStub(toType)
|
||||
|
||||
expect(normalizeToInputUser(from)).toEqual(to)
|
||||
expect(toInputUser(from)).toEqual(to)
|
||||
})
|
||||
|
||||
it('should throw for other types', () => {
|
||||
expect(() => normalizeToInputUser(createStub('inputPeerChannel'), 'some_channel')).toThrow(
|
||||
MtInvalidPeerTypeError,
|
||||
)
|
||||
expect(() => toInputUser(createStub('inputPeerChannel'), 'some_channel')).toThrow(MtInvalidPeerTypeError)
|
||||
})
|
||||
})
|
||||
|
||||
describe('normalizeToInputChannel', () => {
|
||||
describe('toInputChannel', () => {
|
||||
it.each([
|
||||
['inputPeerChannel', 'inputChannel'],
|
||||
['inputPeerChannelFromMessage', 'inputChannelFromMessage'],
|
||||
|
@ -71,11 +69,11 @@ describe('normalizeToInputChannel', () => {
|
|||
const from = createStub(fromType)
|
||||
const to = createStub(toType)
|
||||
|
||||
expect(normalizeToInputChannel(from)).toEqual(to)
|
||||
expect(toInputChannel(from)).toEqual(to)
|
||||
})
|
||||
|
||||
it('should throw for other types', () => {
|
||||
expect(() => normalizeToInputChannel(createStub('inputPeerUser'), 'some_user')).toThrow(MtInvalidPeerTypeError)
|
||||
expect(() => toInputChannel(createStub('inputPeerUser'), 'some_user')).toThrow(MtInvalidPeerTypeError)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import { InputPeerLike } from '../types/peers/index.js'
|
|||
export const INVITE_LINK_REGEX =
|
||||
/^(?:https?:\/\/)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)\/(?:joinchat\/|\+))([\w-]+)$/i
|
||||
|
||||
// helpers to normalize result of `resolvePeer` function
|
||||
// helpers to convert result of `resolvePeer` function
|
||||
|
||||
export function normalizeToInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): tl.TypeInputPeer {
|
||||
export function toInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): tl.TypeInputPeer {
|
||||
if (tl.isAnyInputPeer(res)) return res
|
||||
|
||||
switch (res._) {
|
||||
|
@ -48,7 +48,7 @@ export function normalizeToInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser |
|
|||
}
|
||||
}
|
||||
|
||||
export function normalizeToInputUser(
|
||||
export function toInputUser(
|
||||
res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel,
|
||||
input?: InputPeerLike,
|
||||
): tl.TypeInputUser {
|
||||
|
@ -75,7 +75,7 @@ export function normalizeToInputUser(
|
|||
throw new MtInvalidPeerTypeError(input ?? res, 'user')
|
||||
}
|
||||
|
||||
export function normalizeToInputChannel(
|
||||
export function toInputChannel(
|
||||
res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel,
|
||||
input?: InputPeerLike,
|
||||
): tl.TypeInputChannel {
|
||||
|
|
Loading…
Reference in a new issue