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