From 895163c126394c6fcc485944864458b16bd77dcd Mon Sep 17 00:00:00 2001 From: Alina Sireneva Date: Sat, 2 Dec 2023 19:10:49 +0300 Subject: [PATCH] chore(client)!: renamed some peer utils breaking: `normalizeToInput*` -> `toInput*` --- .../client/src/methods/bots/get-bot-info.ts | 4 +-- .../src/methods/bots/get-bot-menu-button.ts | 4 +-- .../src/methods/bots/get-game-high-scores.ts | 6 ++--- .../methods/bots/normalize-command-scope.ts | 4 +-- .../client/src/methods/bots/set-bot-info.ts | 4 +-- .../src/methods/bots/set-bot-menu-button.ts | 4 +-- .../client/src/methods/bots/set-game-score.ts | 6 ++--- .../src/methods/chats/add-chat-members.ts | 13 +++------- .../src/methods/chats/ban-chat-member.ts | 11 +++----- .../client/src/methods/chats/create-group.ts | 4 +-- .../src/methods/chats/delete-channel.ts | 4 +-- .../src/methods/chats/delete-chat-photo.ts | 4 +-- .../src/methods/chats/delete-user-history.ts | 4 +-- .../src/methods/chats/edit-admin-rights.ts | 6 ++--- .../src/methods/chats/get-chat-event-log.ts | 8 +++--- .../src/methods/chats/get-chat-member.ts | 9 ++----- .../src/methods/chats/get-chat-members.ts | 4 +-- packages/client/src/methods/chats/get-chat.ts | 8 +++--- .../client/src/methods/chats/get-full-chat.ts | 8 +++--- .../src/methods/chats/get-similar-channels.ts | 4 +-- .../src/methods/chats/iter-chat-event-log.ts | 8 +++--- .../client/src/methods/chats/join-chat.ts | 4 +-- .../client/src/methods/chats/leave-chat.ts | 4 +-- .../src/methods/chats/reorder-usernames.ts | 6 ++--- .../src/methods/chats/restrict-chat-member.ts | 4 +-- .../src/methods/chats/set-chat-color.ts | 4 +-- .../src/methods/chats/set-chat-photo.ts | 4 +-- .../src/methods/chats/set-chat-title.ts | 4 +-- .../src/methods/chats/set-chat-username.ts | 4 +-- .../client/src/methods/chats/set-slow-mode.ts | 4 +-- .../methods/chats/toggle-fragment-username.ts | 6 ++--- .../src/methods/chats/toggle-join-requests.ts | 4 +-- .../src/methods/chats/toggle-join-to-send.ts | 4 +-- .../src/methods/chats/unban-chat-member.ts | 4 +-- .../src/methods/contacts/add-contact.ts | 4 +-- .../src/methods/contacts/delete-contacts.ts | 4 +-- .../src/methods/forums/create-forum-topic.ts | 4 +-- .../forums/delete-forum-topic-history.ts | 4 +-- .../src/methods/forums/edit-forum-topic.ts | 4 +-- .../methods/forums/get-forum-topics-by-id.ts | 4 +-- .../src/methods/forums/get-forum-topics.ts | 4 +-- .../src/methods/forums/iter-forum-topics.ts | 4 +-- .../forums/reorder-pinned-forum-topics.ts | 4 +-- .../forums/toggle-forum-topic-closed.ts | 4 +-- .../forums/toggle-forum-topic-pinned.ts | 4 +-- .../client/src/methods/forums/toggle-forum.ts | 4 +-- .../forums/toggle-general-topic-hidden.ts | 4 +-- .../invite-links/get-invite-link-members.ts | 4 +-- .../methods/invite-links/get-invite-links.ts | 4 +-- .../methods/invite-links/hide-join-request.ts | 4 +-- .../src/methods/messages/delete-messages.ts | 4 +-- .../src/methods/messages/get-messages.ts | 4 +-- .../src/methods/messages/read-history.ts | 4 +-- .../src/methods/messages/send-common.ts | 4 +-- .../methods/misc/normalize-privacy-rules.ts | 4 +-- .../client/src/methods/misc/normalize-text.ts | 4 +-- .../methods/stickers/create-sticker-set.ts | 4 +-- .../methods/stickers/set-chat-sticker-set.ts | 4 +-- .../client/src/methods/updates/manager.ts | 13 +++------- .../src/methods/users/edit-close-friends.ts | 4 +-- .../src/methods/users/get-common-chats.ts | 4 +-- .../src/methods/users/get-profile-photo.ts | 4 +-- .../src/methods/users/get-profile-photos.ts | 4 +-- .../client/src/methods/users/get-users.ts | 6 ++--- .../src/methods/users/iter-profile-photos.ts | 4 +-- .../client/src/methods/users/resolve-peer.ts | 4 +-- packages/client/src/types/bots/keyboards.ts | 4 +-- packages/client/src/utils/peer-utils.test.ts | 26 +++++++++---------- packages/client/src/utils/peer-utils.ts | 8 +++--- 69 files changed, 167 insertions(+), 193 deletions(-) diff --git a/packages/client/src/methods/bots/get-bot-info.ts b/packages/client/src/methods/bots/get-bot-info.ts index 3d655171..5c383660 100644 --- a/packages/client/src/methods/bots/get-bot-info.ts +++ b/packages/client/src/methods/bots/get-bot-info.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -27,7 +27,7 @@ export async function getBotInfo( return client.call({ _: 'bots.getBotInfo', - bot: bot ? normalizeToInputUser(await resolvePeer(client, bot), bot) : undefined, + bot: bot ? toInputUser(await resolvePeer(client, bot), bot) : undefined, langCode: langCode, }) } diff --git a/packages/client/src/methods/bots/get-bot-menu-button.ts b/packages/client/src/methods/bots/get-bot-menu-button.ts index d3f8330e..73fde523 100644 --- a/packages/client/src/methods/bots/get-bot-menu-button.ts +++ b/packages/client/src/methods/bots/get-bot-menu-button.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -10,6 +10,6 @@ import { resolvePeer } from '../users/resolve-peer.js' export async function getBotMenuButton(client: BaseTelegramClient, user: InputPeerLike): Promise { return await client.call({ _: 'bots.getBotMenuButton', - userId: normalizeToInputUser(await resolvePeer(client, user), user), + userId: toInputUser(await resolvePeer(client, user), user), }) } diff --git a/packages/client/src/methods/bots/get-game-high-scores.ts b/packages/client/src/methods/bots/get-game-high-scores.ts index 3db07066..f1225dda 100644 --- a/packages/client/src/methods/bots/get-game-high-scores.ts +++ b/packages/client/src/methods/bots/get-game-high-scores.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { GameHighScore, InputMessageId, InputPeerLike, normalizeInputMessageId, PeersIndex } from '../../types/index.js' import { normalizeInlineId } from '../../utils/inline-utils.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -23,7 +23,7 @@ export async function getGameHighScores( let user: tl.TypeInputUser if (userId) { - user = normalizeToInputUser(await resolvePeer(client, userId), userId) + user = toInputUser(await resolvePeer(client, userId), userId) } else { user = { _: 'inputUserEmpty' } } @@ -56,7 +56,7 @@ export async function getInlineGameHighScores( let user: tl.TypeInputUser if (userId) { - user = normalizeToInputUser(await resolvePeer(client, userId), userId) + user = toInputUser(await resolvePeer(client, userId), userId) } else { user = { _: 'inputUserEmpty' } } diff --git a/packages/client/src/methods/bots/normalize-command-scope.ts b/packages/client/src/methods/bots/normalize-command-scope.ts index 4a0f3673..587cd05c 100644 --- a/packages/client/src/methods/bots/normalize-command-scope.ts +++ b/packages/client/src/methods/bots/normalize-command-scope.ts @@ -1,7 +1,7 @@ import { assertNever, BaseTelegramClient, tl } from '@mtcute/core' import { BotCommands } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @internal */ @@ -22,7 +22,7 @@ export async function _normalizeCommandScope( } } case 'member': { - const user = normalizeToInputUser(await resolvePeer(client, scope.user), scope.user) + const user = toInputUser(await resolvePeer(client, scope.user), scope.user) const chat = await resolvePeer(client, scope.chat) return { diff --git a/packages/client/src/methods/bots/set-bot-info.ts b/packages/client/src/methods/bots/set-bot-info.ts index 7b43726f..6bb6543f 100644 --- a/packages/client/src/methods/bots/set-bot-info.ts +++ b/packages/client/src/methods/bots/set-bot-info.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -36,7 +36,7 @@ export async function setBotInfo( await client.call({ _: 'bots.setBotInfo', - bot: bot ? normalizeToInputUser(await resolvePeer(client, bot), bot) : undefined, + bot: bot ? toInputUser(await resolvePeer(client, bot), bot) : undefined, langCode: langCode, name, about: bio, diff --git a/packages/client/src/methods/bots/set-bot-menu-button.ts b/packages/client/src/methods/bots/set-bot-menu-button.ts index 2a095395..505d2199 100644 --- a/packages/client/src/methods/bots/set-bot-menu-button.ts +++ b/packages/client/src/methods/bots/set-bot-menu-button.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -14,7 +14,7 @@ export async function setBotMenuButton( ): Promise { await client.call({ _: 'bots.setBotMenuButton', - userId: normalizeToInputUser(await resolvePeer(client, user), user), + userId: toInputUser(await resolvePeer(client, user), user), button, }) } diff --git a/packages/client/src/methods/bots/set-game-score.ts b/packages/client/src/methods/bots/set-game-score.ts index 5fbc58bc..2dd8e439 100644 --- a/packages/client/src/methods/bots/set-game-score.ts +++ b/packages/client/src/methods/bots/set-game-score.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputMessageId, InputPeerLike, Message, normalizeInputMessageId } from '../../types/index.js' import { normalizeInlineId } from '../../utils/inline-utils.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { _findMessageInUpdate } from '../messages/find-in-update.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -43,7 +43,7 @@ export async function setGameScore( const { userId, score, noEdit, force, shouldDispatch } = params const { chatId, message } = normalizeInputMessageId(params) - const user = normalizeToInputUser(await resolvePeer(client, userId), userId) + const user = toInputUser(await resolvePeer(client, userId), userId) const chat = await resolvePeer(client, chatId) const res = await client.call({ @@ -89,7 +89,7 @@ export async function setInlineGameScore( ): Promise { 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) diff --git a/packages/client/src/methods/chats/add-chat-members.ts b/packages/client/src/methods/chats/add-chat-members.ts index e53e0b69..813ef40d 100644 --- a/packages/client/src/methods/chats/add-chat-members.ts +++ b/packages/client/src/methods/chats/add-chat-members.ts @@ -1,12 +1,7 @@ import { BaseTelegramClient, MaybeArray } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js' -import { - isInputPeerChannel, - isInputPeerChat, - normalizeToInputChannel, - normalizeToInputUser, -} from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel, toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' import { resolvePeerMany } from '../users/resolve-peer-many.js' @@ -38,7 +33,7 @@ export async function addChatMembers( if (isInputPeerChat(chat)) { for (const user of users) { - const p = normalizeToInputUser(await resolvePeer(client, user)) + const p = toInputUser(await resolvePeer(client, user)) const updates = await client.call({ _: 'messages.addChatUser', @@ -51,8 +46,8 @@ export async function addChatMembers( } else if (isInputPeerChannel(chat)) { const updates = await client.call({ _: 'channels.inviteToChannel', - channel: normalizeToInputChannel(chat), - users: await resolvePeerMany(client, users, normalizeToInputUser), + channel: toInputChannel(chat), + users: await resolvePeerMany(client, users, toInputUser), }) client.network.handleUpdate(updates) diff --git a/packages/client/src/methods/chats/ban-chat-member.ts b/packages/client/src/methods/chats/ban-chat-member.ts index 343f4e31..a112f821 100644 --- a/packages/client/src/methods/chats/ban-chat-member.ts +++ b/packages/client/src/methods/chats/ban-chat-member.ts @@ -1,12 +1,7 @@ import { BaseTelegramClient, MtTypeAssertionError } from '@mtcute/core' import { InputPeerLike, Message, MtInvalidPeerTypeError } from '../../types/index.js' -import { - isInputPeerChannel, - isInputPeerChat, - normalizeToInputChannel, - normalizeToInputUser, -} from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel, toInputUser } from '../../utils/peer-utils.js' import { _findMessageInUpdate } from '../messages/find-in-update.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -44,7 +39,7 @@ export async function banChatMember( if (isInputPeerChannel(chat)) { res = await client.call({ _: 'channels.editBanned', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), participant: peer, bannedRights: { _: 'chatBannedRights', @@ -57,7 +52,7 @@ export async function banChatMember( res = await client.call({ _: 'messages.deleteChatUser', chatId: chat.chatId, - userId: normalizeToInputUser(peer), + userId: toInputUser(peer), }) } else throw new MtInvalidPeerTypeError(chatId, 'chat or channel') diff --git a/packages/client/src/methods/chats/create-group.ts b/packages/client/src/methods/chats/create-group.ts index 2167d206..a0e01ec5 100644 --- a/packages/client/src/methods/chats/create-group.ts +++ b/packages/client/src/methods/chats/create-group.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, MaybeArray } from '@mtcute/core' import { Chat, InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { assertIsUpdatesGroup } from '../../utils/updates-utils.js' import { resolvePeerMany } from '../users/resolve-peer-many.js' @@ -38,7 +38,7 @@ export async function createGroup( if (!Array.isArray(users)) users = [users] - const peers = await resolvePeerMany(client, users, normalizeToInputUser) + const peers = await resolvePeerMany(client, users, toInputUser) const res = await client.call({ _: 'messages.createChat', diff --git a/packages/client/src/methods/chats/delete-channel.ts b/packages/client/src/methods/chats/delete-channel.ts index e4284eae..49d6dab7 100644 --- a/packages/client/src/methods/chats/delete-channel.ts +++ b/packages/client/src/methods/chats/delete-channel.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' // @alias=deleteSupergroup @@ -13,7 +13,7 @@ import { resolvePeer } from '../users/resolve-peer.js' export async function deleteChannel(client: BaseTelegramClient, chatId: InputPeerLike): Promise { const res = await client.call({ _: 'channels.deleteChannel', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), }) client.network.handleUpdate(res) } diff --git a/packages/client/src/methods/chats/delete-chat-photo.ts b/packages/client/src/methods/chats/delete-chat-photo.ts index aab09e23..49a73a70 100644 --- a/packages/client/src/methods/chats/delete-chat-photo.ts +++ b/packages/client/src/methods/chats/delete-chat-photo.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -24,7 +24,7 @@ export async function deleteChatPhoto(client: BaseTelegramClient, chatId: InputP } else if (isInputPeerChannel(chat)) { res = await client.call({ _: 'channels.editPhoto', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), photo: { _: 'inputChatPhotoEmpty' }, }) } else throw new MtInvalidPeerTypeError(chatId, 'chat or channel') diff --git a/packages/client/src/methods/chats/delete-user-history.ts b/packages/client/src/methods/chats/delete-user-history.ts index e69f9aa0..5bdc2536 100644 --- a/packages/client/src/methods/chats/delete-user-history.ts +++ b/packages/client/src/methods/chats/delete-user-history.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { createDummyUpdate } from '../../utils/updates-utils.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -19,7 +19,7 @@ export async function deleteUserHistory( ): Promise { 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) diff --git a/packages/client/src/methods/chats/edit-admin-rights.ts b/packages/client/src/methods/chats/edit-admin-rights.ts index 0b4bb1f0..830e58b7 100644 --- a/packages/client/src/methods/chats/edit-admin-rights.ts +++ b/packages/client/src/methods/chats/edit-admin-rights.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel, normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputChannel, toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -22,8 +22,8 @@ export async function editAdminRights( ): Promise { const { chatId, userId, rights, rank = '' } = params - const chat = normalizeToInputChannel(await resolvePeer(client, chatId), chatId) - const user = normalizeToInputUser(await resolvePeer(client, userId), userId) + const chat = toInputChannel(await resolvePeer(client, chatId), chatId) + const user = toInputUser(await resolvePeer(client, userId), userId) const res = await client.call({ _: 'channels.editAdmin', diff --git a/packages/client/src/methods/chats/get-chat-event-log.ts b/packages/client/src/methods/chats/get-chat-event-log.ts index e62d16ae..87c9b276 100644 --- a/packages/client/src/methods/chats/get-chat-event-log.ts +++ b/packages/client/src/methods/chats/get-chat-event-log.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, Long, tl } from '@mtcute/core' import { ChatEvent, InputPeerLike, PeersIndex } from '../../types/index.js' import { InputChatEventFilters, normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js' -import { normalizeToInputChannel, normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputChannel, toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' import { resolvePeerMany } from '../users/resolve-peer-many.js' @@ -74,11 +74,9 @@ export async function getChatEventLog( ): Promise { const { maxId = Long.ZERO, minId = Long.ZERO, query = '', limit = 100, users, filters } = params ?? {} - const channel = normalizeToInputChannel(await resolvePeer(client, chatId), chatId) + const channel = toInputChannel(await resolvePeer(client, chatId), chatId) - const admins: tl.TypeInputUser[] | undefined = users ? - await resolvePeerMany(client, users, normalizeToInputUser) : - undefined + const admins: tl.TypeInputUser[] | undefined = users ? await resolvePeerMany(client, users, toInputUser) : undefined const { serverFilter, localFilter } = normalizeChatEventFilters(filters) diff --git a/packages/client/src/methods/chats/get-chat-member.ts b/packages/client/src/methods/chats/get-chat-member.ts index 31c19216..4234afc1 100644 --- a/packages/client/src/methods/chats/get-chat-member.ts +++ b/packages/client/src/methods/chats/get-chat-member.ts @@ -2,12 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { assertTypeIs } from '@mtcute/core/utils.js' import { ChatMember, InputPeerLike, MtInvalidPeerTypeError, PeersIndex } from '../../types/index.js' -import { - isInputPeerChannel, - isInputPeerChat, - isInputPeerUser, - normalizeToInputChannel, -} from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, isInputPeerUser, toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -62,7 +57,7 @@ export async function getChatMember( try { const res = await client.call({ _: 'channels.getParticipant', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), participant: user, }) diff --git a/packages/client/src/methods/chats/get-chat-members.ts b/packages/client/src/methods/chats/get-chat-members.ts index bc801a21..b1911394 100644 --- a/packages/client/src/methods/chats/get-chat-members.ts +++ b/packages/client/src/methods/chats/get-chat-members.ts @@ -3,7 +3,7 @@ import { assertTypeIs } from '@mtcute/core/utils.js' import { ArrayWithTotal, ChatMember, InputPeerLike, MtInvalidPeerTypeError, PeersIndex } from '../../types/index.js' import { makeArrayWithTotal } from '../../utils/index.js' -import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -123,7 +123,7 @@ export async function getChatMembers( const res = await client.call({ _: 'channels.getParticipants', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), filter, offset, limit, diff --git a/packages/client/src/methods/chats/get-chat.ts b/packages/client/src/methods/chats/get-chat.ts index ca7eeb11..e03e11cc 100644 --- a/packages/client/src/methods/chats/get-chat.ts +++ b/packages/client/src/methods/chats/get-chat.ts @@ -6,8 +6,8 @@ import { isInputPeerChannel, isInputPeerChat, isInputPeerUser, - normalizeToInputChannel, - normalizeToInputUser, + toInputChannel, + toInputUser, } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' import { _getChannelsBatched, _getChatsBatched, _getUsersBatched } from './batched-queries.js' @@ -43,9 +43,9 @@ export async function getChat(client: BaseTelegramClient, chatId: InputPeerLike) let res: tl.TypeChat | tl.TypeUser | null if (isInputPeerChannel(peer)) { - res = await _getChannelsBatched(client, normalizeToInputChannel(peer)) + res = await _getChannelsBatched(client, toInputChannel(peer)) } else if (isInputPeerUser(peer)) { - res = await _getUsersBatched(client, normalizeToInputUser(peer)) + res = await _getUsersBatched(client, toInputUser(peer)) } else if (isInputPeerChat(peer)) { res = await _getChatsBatched(client, peer.chatId) } else throw new Error('should not happen') diff --git a/packages/client/src/methods/chats/get-full-chat.ts b/packages/client/src/methods/chats/get-full-chat.ts index cb806171..c2596ee5 100644 --- a/packages/client/src/methods/chats/get-full-chat.ts +++ b/packages/client/src/methods/chats/get-full-chat.ts @@ -6,8 +6,8 @@ import { isInputPeerChannel, isInputPeerChat, isInputPeerUser, - normalizeToInputChannel, - normalizeToInputUser, + toInputChannel, + toInputUser, } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -45,12 +45,12 @@ export async function getFullChat(client: BaseTelegramClient, chatId: InputPeerL if (isInputPeerChannel(peer)) { res = await client.call({ _: 'channels.getFullChannel', - channel: normalizeToInputChannel(peer), + channel: toInputChannel(peer), }) } else if (isInputPeerUser(peer)) { res = await client.call({ _: 'users.getFullUser', - id: normalizeToInputUser(peer)!, + id: toInputUser(peer)!, }) } else if (isInputPeerChat(peer)) { res = await client.call({ diff --git a/packages/client/src/methods/chats/get-similar-channels.ts b/packages/client/src/methods/chats/get-similar-channels.ts index d187346b..4dc37d9c 100644 --- a/packages/client/src/methods/chats/get-similar-channels.ts +++ b/packages/client/src/methods/chats/get-similar-channels.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { ArrayWithTotal, Chat, InputPeerLike } from '../../types/index.js' import { makeArrayWithTotal } from '../../utils/misc-utils.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' // @available=user @@ -21,7 +21,7 @@ export async function getSimilarChannels( ): Promise> { const res = await client.call({ _: 'channels.getChannelRecommendations', - channel: normalizeToInputChannel(await resolvePeer(client, channel), channel), + channel: toInputChannel(await resolvePeer(client, channel), channel), }) const parsed = res.chats.map((chat) => new Chat(chat)) diff --git a/packages/client/src/methods/chats/iter-chat-event-log.ts b/packages/client/src/methods/chats/iter-chat-event-log.ts index 52e634d1..706efc94 100644 --- a/packages/client/src/methods/chats/iter-chat-event-log.ts +++ b/packages/client/src/methods/chats/iter-chat-event-log.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, Long, tl } from '@mtcute/core' import { ChatEvent, InputPeerLike } from '../../types/index.js' import { normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js' -import { normalizeToInputChannel, normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputChannel, toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' import { resolvePeerMany } from '../users/resolve-peer-many.js' import { getChatEventLog } from './get-chat-event-log.js' @@ -37,13 +37,11 @@ export async function* iterChatEventLog( ): AsyncIterableIterator { if (!params) params = {} - const channel = normalizeToInputChannel(await resolvePeer(client, chatId), chatId) + const channel = toInputChannel(await resolvePeer(client, chatId), chatId) const { minId = Long.ZERO, query = '', limit = Infinity, chunkSize = 100, users, filters } = params - const admins: tl.TypeInputUser[] | undefined = users ? - await resolvePeerMany(client, users, normalizeToInputUser) : - undefined + const admins: tl.TypeInputUser[] | undefined = users ? await resolvePeerMany(client, users, toInputUser) : undefined const { serverFilter, localFilter } = normalizeChatEventFilters(filters) diff --git a/packages/client/src/methods/chats/join-chat.ts b/packages/client/src/methods/chats/join-chat.ts index c630adc3..7fb3d5f6 100644 --- a/packages/client/src/methods/chats/join-chat.ts +++ b/packages/client/src/methods/chats/join-chat.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { Chat, InputPeerLike } from '../../types/index.js' -import { INVITE_LINK_REGEX, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { INVITE_LINK_REGEX, toInputChannel } from '../../utils/peer-utils.js' import { assertIsUpdatesGroup } from '../../utils/updates-utils.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -35,7 +35,7 @@ export async function joinChat(client: BaseTelegramClient, chatId: InputPeerLike const res = await client.call({ _: 'channels.joinChannel', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), }) assertIsUpdatesGroup('channels.joinChannel', res) diff --git a/packages/client/src/methods/chats/leave-chat.ts b/packages/client/src/methods/chats/leave-chat.ts index 1b308fd0..65f16f28 100644 --- a/packages/client/src/methods/chats/leave-chat.ts +++ b/packages/client/src/methods/chats/leave-chat.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' import { deleteHistory } from './delete-history.js' @@ -25,7 +25,7 @@ export async function leaveChat( if (isInputPeerChannel(chat)) { const res = await client.call({ _: 'channels.leaveChannel', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), }) client.network.handleUpdate(res) } else if (isInputPeerChat(chat)) { diff --git a/packages/client/src/methods/chats/reorder-usernames.ts b/packages/client/src/methods/chats/reorder-usernames.ts index 09b0c9e3..5567dc17 100644 --- a/packages/client/src/methods/chats/reorder-usernames.ts +++ b/packages/client/src/methods/chats/reorder-usernames.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerUser, normalizeToInputChannel, normalizeToInputUser } from '../../utils/index.js' +import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js' import { getAuthState } from '../auth/_state.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -33,13 +33,13 @@ export async function reorderUsernames( // bot await client.call({ _: 'bots.reorderUsernames', - bot: normalizeToInputUser(peer, peerId), + bot: toInputUser(peer, peerId), order, }) } else if (isInputPeerChannel(peer)) { await client.call({ _: 'channels.reorderUsernames', - channel: normalizeToInputChannel(peer, peerId), + channel: toInputChannel(peer, peerId), order, }) } diff --git a/packages/client/src/methods/chats/restrict-chat-member.ts b/packages/client/src/methods/chats/restrict-chat-member.ts index 81a306f0..290cfb0e 100644 --- a/packages/client/src/methods/chats/restrict-chat-member.ts +++ b/packages/client/src/methods/chats/restrict-chat-member.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js' import { normalizeDate } from '../../utils/misc-utils.js' -import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -48,7 +48,7 @@ export async function restrictChatMember( const res = await client.call({ _: 'channels.editBanned', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), participant: user, bannedRights: { _: 'chatBannedRights', diff --git a/packages/client/src/methods/chats/set-chat-color.ts b/packages/client/src/methods/chats/set-chat-color.ts index 758577a4..80d56955 100644 --- a/packages/client/src/methods/chats/set-chat-color.ts +++ b/packages/client/src/methods/chats/set-chat-color.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, MtTypeAssertionError, tl } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerUser, normalizeToInputChannel } from '../../utils/index.js' +import { isInputPeerChannel, isInputPeerUser, toInputChannel } from '../../utils/index.js' import { getAuthState } from '../auth/_state.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -45,7 +45,7 @@ export async function setChatColor( if (isInputPeerChannel(peer)) { const res = await client.call({ _: 'channels.updateColor', - channel: normalizeToInputChannel(peer), + channel: toInputChannel(peer), color, backgroundEmojiId, }) diff --git a/packages/client/src/methods/chats/set-chat-photo.ts b/packages/client/src/methods/chats/set-chat-photo.ts index bbd48a4f..931da031 100644 --- a/packages/client/src/methods/chats/set-chat-photo.ts +++ b/packages/client/src/methods/chats/set-chat-photo.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, MtArgumentError, tl } from '@mtcute/core' import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id' import { InputFileLike, InputPeerLike, isUploadedFile, MtInvalidPeerTypeError } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js' import { uploadFile } from '../files/upload-file.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -95,7 +95,7 @@ export async function setChatPhoto( } else { res = await client.call({ _: 'channels.editPhoto', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), photo, }) } diff --git a/packages/client/src/methods/chats/set-chat-title.ts b/packages/client/src/methods/chats/set-chat-title.ts index 35f54865..1765b10e 100644 --- a/packages/client/src/methods/chats/set-chat-title.ts +++ b/packages/client/src/methods/chats/set-chat-title.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -25,7 +25,7 @@ export async function setChatTitle(client: BaseTelegramClient, chatId: InputPeer } else if (isInputPeerChannel(chat)) { res = await client.call({ _: 'channels.editTitle', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), title, }) } else throw new MtInvalidPeerTypeError(chatId, 'chat or channel') diff --git a/packages/client/src/methods/chats/set-chat-username.ts b/packages/client/src/methods/chats/set-chat-username.ts index 0f475084..96fde3e9 100644 --- a/packages/client/src/methods/chats/set-chat-username.ts +++ b/packages/client/src/methods/chats/set-chat-username.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -19,7 +19,7 @@ export async function setChatUsername( ): Promise { await client.call({ _: 'channels.updateUsername', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), username: username || '', }) } diff --git a/packages/client/src/methods/chats/set-slow-mode.ts b/packages/client/src/methods/chats/set-slow-mode.ts index 5ebfa939..c684597f 100644 --- a/packages/client/src/methods/chats/set-slow-mode.ts +++ b/packages/client/src/methods/chats/set-slow-mode.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -16,7 +16,7 @@ import { resolvePeer } from '../users/resolve-peer.js' export async function setSlowMode(client: BaseTelegramClient, chatId: InputPeerLike, seconds = 0): Promise { const res = await client.call({ _: 'channels.toggleSlowMode', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), seconds, }) client.network.handleUpdate(res) diff --git a/packages/client/src/methods/chats/toggle-fragment-username.ts b/packages/client/src/methods/chats/toggle-fragment-username.ts index 5d09fdb2..3b0ffe47 100644 --- a/packages/client/src/methods/chats/toggle-fragment-username.ts +++ b/packages/client/src/methods/chats/toggle-fragment-username.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerUser, normalizeToInputChannel, normalizeToInputUser } from '../../utils/index.js' +import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/index.js' import { getAuthState } from '../auth/_state.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -49,14 +49,14 @@ export async function toggleFragmentUsername( // bot await client.call({ _: 'bots.toggleUsername', - bot: normalizeToInputUser(peer, peerId), + bot: toInputUser(peer, peerId), username, active, }) } else if (isInputPeerChannel(peer)) { await client.call({ _: 'channels.toggleUsername', - channel: normalizeToInputChannel(peer, peerId), + channel: toInputChannel(peer, peerId), username, active, }) diff --git a/packages/client/src/methods/chats/toggle-join-requests.ts b/packages/client/src/methods/chats/toggle-join-requests.ts index d3e9e7cc..ebae5309 100644 --- a/packages/client/src/methods/chats/toggle-join-requests.ts +++ b/packages/client/src/methods/chats/toggle-join-requests.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -20,7 +20,7 @@ export async function toggleJoinRequests( ): Promise { const res = await client.call({ _: 'channels.toggleJoinRequest', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), enabled, }) client.network.handleUpdate(res) diff --git a/packages/client/src/methods/chats/toggle-join-to-send.ts b/packages/client/src/methods/chats/toggle-join-to-send.ts index cde28beb..a1f9a35e 100644 --- a/packages/client/src/methods/chats/toggle-join-to-send.ts +++ b/packages/client/src/methods/chats/toggle-join-to-send.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -20,7 +20,7 @@ export async function toggleJoinToSend( ): Promise { const res = await client.call({ _: 'channels.toggleJoinToSend', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), enabled, }) client.network.handleUpdate(res) diff --git a/packages/client/src/methods/chats/unban-chat-member.ts b/packages/client/src/methods/chats/unban-chat-member.ts index 11f5db78..9407dad1 100644 --- a/packages/client/src/methods/chats/unban-chat-member.ts +++ b/packages/client/src/methods/chats/unban-chat-member.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js' -import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerChat, toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' // @alias=unrestrictChatMember @@ -30,7 +30,7 @@ export async function unbanChatMember( if (isInputPeerChannel(chat)) { const res = await client.call({ _: 'channels.editBanned', - channel: normalizeToInputChannel(chat), + channel: toInputChannel(chat), participant: peer, bannedRights: { _: 'chatBannedRights', diff --git a/packages/client/src/methods/contacts/add-contact.ts b/packages/client/src/methods/contacts/add-contact.ts index 358bf4af..79e06379 100644 --- a/packages/client/src/methods/contacts/add-contact.ts +++ b/packages/client/src/methods/contacts/add-contact.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, User } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { assertIsUpdatesGroup } from '../../utils/updates-utils.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -39,7 +39,7 @@ export async function addContact( }, ): Promise { const { userId, firstName, lastName = '', phone = '', sharePhone = false } = params - const peer = normalizeToInputUser(await resolvePeer(client, userId), userId) + const peer = toInputUser(await resolvePeer(client, userId), userId) const res = await client.call({ _: 'contacts.addContact', diff --git a/packages/client/src/methods/contacts/delete-contacts.ts b/packages/client/src/methods/contacts/delete-contacts.ts index 3f2b7320..b28313d7 100644 --- a/packages/client/src/methods/contacts/delete-contacts.ts +++ b/packages/client/src/methods/contacts/delete-contacts.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, MaybeArray } from '@mtcute/core' import { InputPeerLike, MtInvalidPeerTypeError, User } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { assertIsUpdatesGroup } from '../../utils/updates-utils.js' import { resolvePeerMany } from '../users/resolve-peer-many.js' @@ -16,7 +16,7 @@ import { resolvePeerMany } from '../users/resolve-peer-many.js' export async function deleteContacts(client: BaseTelegramClient, userIds: MaybeArray): Promise { if (!Array.isArray(userIds)) userIds = [userIds] - const inputPeers = await resolvePeerMany(client, userIds, normalizeToInputUser) + const inputPeers = await resolvePeerMany(client, userIds, toInputUser) if (!inputPeers.length) { throw new MtInvalidPeerTypeError('all provided ids', 'user') diff --git a/packages/client/src/methods/forums/create-forum-topic.ts b/packages/client/src/methods/forums/create-forum-topic.ts index 9acc7e42..8c5b138b 100644 --- a/packages/client/src/methods/forums/create-forum-topic.ts +++ b/packages/client/src/methods/forums/create-forum-topic.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { randomLong } from '@mtcute/core/utils.js' import { InputPeerLike, Message } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { _findMessageInUpdate } from '../messages/find-in-update.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -50,7 +50,7 @@ export async function createForumTopic( const res = await client.call({ _: 'channels.createForumTopic', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), title, iconColor: typeof icon === 'number' ? icon : undefined, iconEmojiId: typeof icon !== 'number' ? icon : undefined, diff --git a/packages/client/src/methods/forums/delete-forum-topic-history.ts b/packages/client/src/methods/forums/delete-forum-topic-history.ts index 85b9d9b3..aeb686b3 100644 --- a/packages/client/src/methods/forums/delete-forum-topic-history.ts +++ b/packages/client/src/methods/forums/delete-forum-topic-history.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { assertTypeIsNot } from '@mtcute/core/utils.js' import type { ForumTopic, InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { createDummyUpdate } from '../../utils/updates-utils.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -17,7 +17,7 @@ export async function deleteForumTopicHistory( chat: InputPeerLike, topicId: number | ForumTopic, ): Promise { - const channel = normalizeToInputChannel(await resolvePeer(client, chat), chat) + const channel = toInputChannel(await resolvePeer(client, chat), chat) assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty') const res = await client.call({ diff --git a/packages/client/src/methods/forums/edit-forum-topic.ts b/packages/client/src/methods/forums/edit-forum-topic.ts index 0ad4a8be..60f8889d 100644 --- a/packages/client/src/methods/forums/edit-forum-topic.ts +++ b/packages/client/src/methods/forums/edit-forum-topic.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, Long, tl } from '@mtcute/core' import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { _findMessageInUpdate } from '../messages/find-in-update.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -47,7 +47,7 @@ export async function editForumTopic( const res = await client.call({ _: 'channels.editForumTopic', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), topicId: typeof topicId === 'number' ? topicId : topicId.id, title, iconEmojiId: icon ? icon ?? Long.ZERO : undefined, diff --git a/packages/client/src/methods/forums/get-forum-topics-by-id.ts b/packages/client/src/methods/forums/get-forum-topics-by-id.ts index 203441b5..01bbb15f 100644 --- a/packages/client/src/methods/forums/get-forum-topics-by-id.ts +++ b/packages/client/src/methods/forums/get-forum-topics-by-id.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, MaybeArray } from '@mtcute/core' import { ForumTopic, InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/index.js' +import { toInputChannel } from '../../utils/index.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -18,7 +18,7 @@ export async function getForumTopicsById( const res = await client.call({ _: 'channels.getForumTopicsByID', - channel: normalizeToInputChannel(await resolvePeer(client, chatId)), + channel: toInputChannel(await resolvePeer(client, chatId)), topics: ids, }) diff --git a/packages/client/src/methods/forums/get-forum-topics.ts b/packages/client/src/methods/forums/get-forum-topics.ts index 6575a371..f2e870eb 100644 --- a/packages/client/src/methods/forums/get-forum-topics.ts +++ b/packages/client/src/methods/forums/get-forum-topics.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { ArrayPaginated, ForumTopic, InputPeerLike } from '../../types/index.js' import { makeArrayPaginated } from '../../utils/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' // @exported @@ -55,7 +55,7 @@ export async function getForumTopics( const res = await client.call({ _: 'channels.getForumTopics', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), q: query, offsetDate, offsetId, diff --git a/packages/client/src/methods/forums/iter-forum-topics.ts b/packages/client/src/methods/forums/iter-forum-topics.ts index 556b08cb..ee8db2d9 100644 --- a/packages/client/src/methods/forums/iter-forum-topics.ts +++ b/packages/client/src/methods/forums/iter-forum-topics.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { ForumTopic, InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' import { getForumTopics } from './get-forum-topics.js' @@ -31,7 +31,7 @@ export async function* iterForumTopics( const { query, limit = Infinity, chunkSize = 100 } = params - const peer = normalizeToInputChannel(await resolvePeer(client, chatId)) + const peer = toInputChannel(await resolvePeer(client, chatId)) let { offset } = params let current = 0 diff --git a/packages/client/src/methods/forums/reorder-pinned-forum-topics.ts b/packages/client/src/methods/forums/reorder-pinned-forum-topics.ts index c2dfe281..73e0cc2c 100644 --- a/packages/client/src/methods/forums/reorder-pinned-forum-topics.ts +++ b/packages/client/src/methods/forums/reorder-pinned-forum-topics.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import type { ForumTopic, InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -29,7 +29,7 @@ export async function reorderPinnedForumTopics( const { chatId, order, force } = params await client.call({ _: 'channels.reorderPinnedForumTopics', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), order: order.map((it) => (typeof it === 'number' ? it : it.id)), force, }) diff --git a/packages/client/src/methods/forums/toggle-forum-topic-closed.ts b/packages/client/src/methods/forums/toggle-forum-topic-closed.ts index ebacd204..db0730ed 100644 --- a/packages/client/src/methods/forums/toggle-forum-topic-closed.ts +++ b/packages/client/src/methods/forums/toggle-forum-topic-closed.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { _findMessageInUpdate } from '../messages/find-in-update.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -35,7 +35,7 @@ export async function toggleForumTopicClosed( const res = await client.call({ _: 'channels.editForumTopic', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), topicId: typeof topicId === 'number' ? topicId : topicId.id, closed, }) diff --git a/packages/client/src/methods/forums/toggle-forum-topic-pinned.ts b/packages/client/src/methods/forums/toggle-forum-topic-pinned.ts index 7d105386..903bd856 100644 --- a/packages/client/src/methods/forums/toggle-forum-topic-pinned.ts +++ b/packages/client/src/methods/forums/toggle-forum-topic-pinned.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { ForumTopic, InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -24,7 +24,7 @@ export async function toggleForumTopicPinned( await client.call({ _: 'channels.updatePinnedForumTopic', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), topicId: typeof topicId === 'number' ? topicId : topicId.id, pinned, }) diff --git a/packages/client/src/methods/forums/toggle-forum.ts b/packages/client/src/methods/forums/toggle-forum.ts index a1fb0f82..186422d7 100644 --- a/packages/client/src/methods/forums/toggle-forum.ts +++ b/packages/client/src/methods/forums/toggle-forum.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -15,7 +15,7 @@ import { resolvePeer } from '../users/resolve-peer.js' export async function toggleForum(client: BaseTelegramClient, chatId: InputPeerLike, enabled = false): Promise { const res = await client.call({ _: 'channels.toggleForum', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), enabled, }) client.network.handleUpdate(res) diff --git a/packages/client/src/methods/forums/toggle-general-topic-hidden.ts b/packages/client/src/methods/forums/toggle-general-topic-hidden.ts index 8535aecc..f7a1427b 100644 --- a/packages/client/src/methods/forums/toggle-general-topic-hidden.ts +++ b/packages/client/src/methods/forums/toggle-general-topic-hidden.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, Message } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/peer-utils.js' +import { toInputChannel } from '../../utils/peer-utils.js' import { _findMessageInUpdate } from '../messages/find-in-update.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -30,7 +30,7 @@ export async function toggleGeneralTopicHidden( const { chatId, hidden, shouldDispatch } = params const res = await client.call({ _: 'channels.editForumTopic', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), topicId: 1, hidden, }) diff --git a/packages/client/src/methods/invite-links/get-invite-link-members.ts b/packages/client/src/methods/invite-links/get-invite-link-members.ts index b2ffebe7..0fd4acb7 100644 --- a/packages/client/src/methods/invite-links/get-invite-link-members.ts +++ b/packages/client/src/methods/invite-links/get-invite-link-members.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { ArrayPaginated, ChatInviteLink, ChatInviteLinkMember, InputPeerLike, PeersIndex } from '../../types/index.js' -import { makeArrayPaginated, normalizeDate, normalizeToInputUser } from '../../utils/index.js' +import { makeArrayPaginated, normalizeDate, toInputUser } from '../../utils/index.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -80,7 +80,7 @@ export async function getInviteLinkMembers( const nextOffset = last ? { date: last.raw.date, - user: normalizeToInputUser(last.user.inputPeer), + user: toInputUser(last.user.inputPeer), } : undefined diff --git a/packages/client/src/methods/invite-links/get-invite-links.ts b/packages/client/src/methods/invite-links/get-invite-links.ts index c7b5fe8c..58990952 100644 --- a/packages/client/src/methods/invite-links/get-invite-links.ts +++ b/packages/client/src/methods/invite-links/get-invite-links.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { ArrayPaginated, ChatInviteLink, InputPeerLike, PeersIndex } from '../../types/index.js' import { makeArrayPaginated } from '../../utils/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' // @exported @@ -59,7 +59,7 @@ export async function getInviteLinks( _: 'messages.getExportedChatInvites', peer: await resolvePeer(client, chatId), revoked, - adminId: admin ? normalizeToInputUser(await resolvePeer(client, admin), admin) : { _: 'inputUserSelf' }, + adminId: admin ? toInputUser(await resolvePeer(client, admin), admin) : { _: 'inputUserSelf' }, limit, offsetDate: offset?.date, offsetLink: offset?.link, diff --git a/packages/client/src/methods/invite-links/hide-join-request.ts b/packages/client/src/methods/invite-links/hide-join-request.ts index 357a4ec5..0ee2029e 100644 --- a/packages/client/src/methods/invite-links/hide-join-request.ts +++ b/packages/client/src/methods/invite-links/hide-join-request.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -20,7 +20,7 @@ export async function hideJoinRequest( ): Promise { const { chatId, user, action } = params - const userId = normalizeToInputUser(await resolvePeer(client, user), user) + const userId = toInputUser(await resolvePeer(client, user), user) await client.call({ _: 'messages.hideChatJoinRequest', diff --git a/packages/client/src/methods/messages/delete-messages.ts b/packages/client/src/methods/messages/delete-messages.ts index f8cb805d..98cb3093 100644 --- a/packages/client/src/methods/messages/delete-messages.ts +++ b/packages/client/src/methods/messages/delete-messages.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPeerLike, Message } from '../../types/index.js' -import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js' import { createDummyUpdate } from '../../utils/updates-utils.js' import { resolvePeer } from '../users/resolve-peer.js' import { deleteScheduledMessages } from './delete-scheduled-messages.js' @@ -36,7 +36,7 @@ export async function deleteMessagesById( let upd if (isInputPeerChannel(peer)) { - const channel = normalizeToInputChannel(peer) + const channel = toInputChannel(peer) const res = await client.call({ _: 'channels.deleteMessages', channel, diff --git a/packages/client/src/methods/messages/get-messages.ts b/packages/client/src/methods/messages/get-messages.ts index d4a5189d..d79bbc9c 100644 --- a/packages/client/src/methods/messages/get-messages.ts +++ b/packages/client/src/methods/messages/get-messages.ts @@ -3,7 +3,7 @@ import { assertTypeIsNot } from '@mtcute/core/utils.js' import { Message } from '../../types/messages/index.js' import { InputPeerLike, PeersIndex } from '../../types/peers/index.js' -import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js' import { getAuthState } from '../auth/_state.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -42,7 +42,7 @@ export async function getMessages( { _: 'channels.getMessages', id: ids, - channel: normalizeToInputChannel(peer), + channel: toInputChannel(peer), } : { _: 'messages.getMessages', diff --git a/packages/client/src/methods/messages/read-history.ts b/packages/client/src/methods/messages/read-history.ts index ed6b97ab..b290e4ac 100644 --- a/packages/client/src/methods/messages/read-history.ts +++ b/packages/client/src/methods/messages/read-history.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils.js' +import { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js' import { createDummyUpdate } from '../../utils/updates-utils.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -47,7 +47,7 @@ export async function readHistory( if (isInputPeerChannel(peer)) { await client.call({ _: 'channels.readHistory', - channel: normalizeToInputChannel(peer), + channel: toInputChannel(peer), maxId, }) } else { diff --git a/packages/client/src/methods/messages/send-common.ts b/packages/client/src/methods/messages/send-common.ts index 30e31c28..fe65ad05 100644 --- a/packages/client/src/methods/messages/send-common.ts +++ b/packages/client/src/methods/messages/send-common.ts @@ -4,7 +4,7 @@ import { MtMessageNotFoundError } from '../../types/errors.js' import { Message } from '../../types/messages/message.js' import { TextWithEntities } from '../../types/misc/entities.js' import { InputPeerLike } from '../../types/peers/index.js' -import { normalizeMessageId, normalizeToInputUser } from '../../utils/index.js' +import { normalizeMessageId, toInputUser } from '../../utils/index.js' import { _normalizeInputText } from '../misc/normalize-text.js' import { resolvePeer } from '../users/resolve-peer.js' import { _getDiscussionMessage } from './get-discussion-message.js' @@ -145,7 +145,7 @@ export async function _processCommonSendParameters( tlReplyTo = { _: 'inputReplyToStory', storyId: params.replyToStory, - userId: normalizeToInputUser(peer), + userId: toInputUser(peer), } } diff --git a/packages/client/src/methods/misc/normalize-privacy-rules.ts b/packages/client/src/methods/misc/normalize-privacy-rules.ts index 5cf69cef..60100f31 100644 --- a/packages/client/src/methods/misc/normalize-privacy-rules.ts +++ b/packages/client/src/methods/misc/normalize-privacy-rules.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputPrivacyRule } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/index.js' +import { toInputUser } from '../../utils/index.js' import { resolvePeerMany } from '../users/resolve-peer-many.js' /** @@ -21,7 +21,7 @@ export async function _normalizePrivacyRules( } if ('users' in rule) { - const users = await resolvePeerMany(client, rule.users, normalizeToInputUser) + const users = await resolvePeerMany(client, rule.users, toInputUser) res.push({ _: rule.allow ? 'inputPrivacyValueAllowUsers' : 'inputPrivacyValueDisallowUsers', diff --git a/packages/client/src/methods/misc/normalize-text.ts b/packages/client/src/methods/misc/normalize-text.ts index f04646fa..cce1afec 100644 --- a/packages/client/src/methods/misc/normalize-text.ts +++ b/packages/client/src/methods/misc/normalize-text.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { InputText } from '../../types/misc/entities.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from '../users/resolve-peer.js' const empty: [string, undefined] = ['', undefined] @@ -26,7 +26,7 @@ export async function _normalizeInputText( for (const ent of entities) { if (ent._ === 'messageEntityMentionName') { try { - const inputPeer = normalizeToInputUser(await resolvePeer(client, ent.userId), ent.userId) + const inputPeer = toInputUser(await resolvePeer(client, ent.userId), ent.userId) const ent_ = ent as unknown as tl.RawInputMessageEntityMentionName ent_._ = 'inputMessageEntityMentionName' diff --git a/packages/client/src/methods/stickers/create-sticker-set.ts b/packages/client/src/methods/stickers/create-sticker-set.ts index 6e41c63e..419abdee 100644 --- a/packages/client/src/methods/stickers/create-sticker-set.ts +++ b/packages/client/src/methods/stickers/create-sticker-set.ts @@ -9,7 +9,7 @@ import { StickerSourceType, StickerType, } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { _normalizeFileToDocument } from '../files/normalize-file-to-document.js' import { resolvePeer } from '../users/resolve-peer.js' @@ -97,7 +97,7 @@ export async function createStickerSet( progressCallback?: (idx: number, uploaded: number, total: number) => void }, ): Promise { - const owner = normalizeToInputUser(await resolvePeer(client, params.owner), params.owner) + const owner = toInputUser(await resolvePeer(client, params.owner), params.owner) const inputStickers: tl.TypeInputStickerSetItem[] = [] diff --git a/packages/client/src/methods/stickers/set-chat-sticker-set.ts b/packages/client/src/methods/stickers/set-chat-sticker-set.ts index ab2ede8f..beffc165 100644 --- a/packages/client/src/methods/stickers/set-chat-sticker-set.ts +++ b/packages/client/src/methods/stickers/set-chat-sticker-set.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, InputStickerSet, normalizeInputStickerSet } from '../../types/index.js' -import { normalizeToInputChannel } from '../../utils/index.js' +import { toInputChannel } from '../../utils/index.js' import { resolvePeer } from '../users/resolve-peer.js' /** @@ -19,7 +19,7 @@ export async function setChatStickerSet( ): Promise { await client.call({ _: 'channels.setStickers', - channel: normalizeToInputChannel(await resolvePeer(client, chatId), chatId), + channel: toInputChannel(await resolvePeer(client, chatId), chatId), stickerset: normalizeInputStickerSet(setId), }) } diff --git a/packages/client/src/methods/updates/manager.ts b/packages/client/src/methods/updates/manager.ts index e136e46f..ab86cac2 100644 --- a/packages/client/src/methods/updates/manager.ts +++ b/packages/client/src/methods/updates/manager.ts @@ -3,12 +3,7 @@ import { assertNever, BaseTelegramClient, MaybeAsync, MtArgumentError, tl } from import { getBarePeerId, getMarkedPeerId, markedPeerIdToBare, toggleChannelIdMark } from '@mtcute/core/utils.js' import { PeersIndex } from '../../types/index.js' -import { - isInputPeerChannel, - isInputPeerUser, - normalizeToInputChannel, - normalizeToInputUser, -} from '../../utils/peer-utils.js' +import { isInputPeerChannel, isInputPeerUser, toInputChannel, toInputUser } from '../../utils/peer-utils.js' import { RpsMeter } from '../../utils/rps-meter.js' import { getAuthState } from '../auth/_state.js' import { _getChannelsBatched, _getUsersBatched } from '../chats/batched-queries.js' @@ -688,7 +683,7 @@ async function fetchChannelDifference( return false } - const channel = normalizeToInputChannel(await resolvePeer(client, toggleChannelIdMark(channelId))) + const channel = toInputChannel(await resolvePeer(client, toggleChannelIdMark(channelId))) if (channel._ === 'inputChannel' && channel.accessHash.isZero()) { state.log.debug('fetchChannelDifference failed for channel %d: input peer not found', channelId) @@ -1115,9 +1110,9 @@ async function onUpdate( // the peer will be automatically cached by the `.call()`, we don't have to do anything if (isInputPeerChannel(peer)) { - return _getChannelsBatched(client, normalizeToInputChannel(peer)) + return _getChannelsBatched(client, toInputChannel(peer)) } else if (isInputPeerUser(peer)) { - return _getUsersBatched(client, normalizeToInputUser(peer)) + return _getUsersBatched(client, toInputUser(peer)) } state.log.warn('cannot fetch full peer %d - unknown peer type %s', id, peer._) diff --git a/packages/client/src/methods/users/edit-close-friends.ts b/packages/client/src/methods/users/edit-close-friends.ts index b2a82125..593d6956 100644 --- a/packages/client/src/methods/users/edit-close-friends.ts +++ b/packages/client/src/methods/users/edit-close-friends.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/index.js' +import { toInputUser } from '../../utils/index.js' import { resolvePeerMany } from './resolve-peer-many.js' /** @@ -24,7 +24,7 @@ export async function editCloseFriendsRaw(client: BaseTelegramClient, ids: numbe export async function editCloseFriends(client: BaseTelegramClient, ids: InputPeerLike[]): Promise { await client.call({ _: 'contacts.editCloseFriends', - id: await resolvePeerMany(client, ids, normalizeToInputUser).then((r) => + id: await resolvePeerMany(client, ids, toInputUser).then((r) => r.map((u) => { if ('userId' in u) return u.userId diff --git a/packages/client/src/methods/users/get-common-chats.ts b/packages/client/src/methods/users/get-common-chats.ts index 53f9fded..eb56194f 100644 --- a/packages/client/src/methods/users/get-common-chats.ts +++ b/packages/client/src/methods/users/get-common-chats.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { Chat, InputPeerLike } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from './resolve-peer.js' /** @@ -14,7 +14,7 @@ export async function getCommonChats(client: BaseTelegramClient, userId: InputPe return client .call({ _: 'messages.getCommonChats', - userId: normalizeToInputUser(await resolvePeer(client, userId), userId), + userId: toInputUser(await resolvePeer(client, userId), userId), maxId: 0, limit: 100, }) diff --git a/packages/client/src/methods/users/get-profile-photo.ts b/packages/client/src/methods/users/get-profile-photo.ts index 12a8fb5c..a2cbcce0 100644 --- a/packages/client/src/methods/users/get-profile-photo.ts +++ b/packages/client/src/methods/users/get-profile-photo.ts @@ -2,7 +2,7 @@ import { BaseTelegramClient, tl } from '@mtcute/core' import { assertTypeIs } from '@mtcute/core/utils.js' import { InputPeerLike, Photo } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from './resolve-peer.js' /** @@ -19,7 +19,7 @@ export async function getProfilePhoto( ): Promise { const res = await client.call({ _: 'photos.getUserPhotos', - userId: normalizeToInputUser(await resolvePeer(client, userId), userId), + userId: toInputUser(await resolvePeer(client, userId), userId), offset: -1, limit: 1, maxId: photoId, diff --git a/packages/client/src/methods/users/get-profile-photos.ts b/packages/client/src/methods/users/get-profile-photos.ts index de53a0a7..c79d2d29 100644 --- a/packages/client/src/methods/users/get-profile-photos.ts +++ b/packages/client/src/methods/users/get-profile-photos.ts @@ -3,7 +3,7 @@ import { assertTypeIs } from '@mtcute/core/utils.js' import { ArrayPaginated, InputPeerLike, Photo } from '../../types/index.js' import { makeArrayPaginated } from '../../utils/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { resolvePeer } from './resolve-peer.js' /** @@ -37,7 +37,7 @@ export async function getProfilePhotos( const res = await client.call({ _: 'photos.getUserPhotos', - userId: normalizeToInputUser(await resolvePeer(client, userId), userId), + userId: toInputUser(await resolvePeer(client, userId), userId), offset, limit, maxId: Long.ZERO, diff --git a/packages/client/src/methods/users/get-users.ts b/packages/client/src/methods/users/get-users.ts index c4b749e4..61be0420 100644 --- a/packages/client/src/methods/users/get-users.ts +++ b/packages/client/src/methods/users/get-users.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient, MaybeArray } from '@mtcute/core' import { InputPeerLike, User } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { _getUsersBatched } from '../chats/batched-queries.js' import { resolvePeer } from './resolve-peer.js' import { resolvePeerMany } from './resolve-peer-many.js' @@ -17,12 +17,12 @@ import { resolvePeerMany } from './resolve-peer-many.js' export async function getUsers(client: BaseTelegramClient, ids: MaybeArray): Promise<(User | null)[]> { if (!Array.isArray(ids)) { // avoid unnecessary overhead of Promise.all and resolvePeerMany - const res = await _getUsersBatched(client, normalizeToInputUser(await resolvePeer(client, ids))) + const res = await _getUsersBatched(client, toInputUser(await resolvePeer(client, ids))) return [res ? new User(res) : null] } - const inputPeers = await resolvePeerMany(client, ids, normalizeToInputUser) + const inputPeers = await resolvePeerMany(client, ids, toInputUser) // pooling will be done by the helper const res = await Promise.all(inputPeers.map((peer) => _getUsersBatched(client, peer))) diff --git a/packages/client/src/methods/users/iter-profile-photos.ts b/packages/client/src/methods/users/iter-profile-photos.ts index 5d2dd9f9..92ce1b0b 100644 --- a/packages/client/src/methods/users/iter-profile-photos.ts +++ b/packages/client/src/methods/users/iter-profile-photos.ts @@ -1,7 +1,7 @@ import { BaseTelegramClient } from '@mtcute/core' import { InputPeerLike, Photo } from '../../types/index.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { getProfilePhotos } from './get-profile-photos.js' import { resolvePeer } from './resolve-peer.js' @@ -32,7 +32,7 @@ export async function* iterProfilePhotos( ): AsyncIterableIterator { 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 diff --git a/packages/client/src/methods/users/resolve-peer.ts b/packages/client/src/methods/users/resolve-peer.ts index 1db41e2a..1db862b7 100644 --- a/packages/client/src/methods/users/resolve-peer.ts +++ b/packages/client/src/methods/users/resolve-peer.ts @@ -10,7 +10,7 @@ import { import { MtPeerNotFoundError } from '../../types/errors.js' import { InputPeerLike } from '../../types/peers/index.js' -import { normalizeToInputPeer } from '../../utils/peer-utils.js' +import { toInputPeer } from '../../utils/peer-utils.js' // @available=both /** @@ -33,7 +33,7 @@ export async function resolvePeer( // User | Chat peerId = peerId.inputPeer } else { - peerId = normalizeToInputPeer(peerId) + peerId = toInputPeer(peerId) } } diff --git a/packages/client/src/types/bots/keyboards.ts b/packages/client/src/types/bots/keyboards.ts index 5f6c4fd3..371bb084 100644 --- a/packages/client/src/types/bots/keyboards.ts +++ b/packages/client/src/types/bots/keyboards.ts @@ -1,7 +1,7 @@ import { assertNever, tl } from '@mtcute/core' import { utf8EncodeToBuffer } from '@mtcute/core/utils.js' -import { normalizeToInputUser } from '../../utils/peer-utils.js' +import { toInputUser } from '../../utils/peer-utils.js' import { BotKeyboardBuilder } from './keyboard-builder.js' /** @@ -345,7 +345,7 @@ export namespace BotKeyboard { return { _: 'inputKeyboardButtonUserProfile', text, - userId: normalizeToInputUser(user), + userId: toInputUser(user), } } diff --git a/packages/client/src/utils/peer-utils.test.ts b/packages/client/src/utils/peer-utils.test.ts index e7ced882..eb1e65ba 100644 --- a/packages/client/src/utils/peer-utils.test.ts +++ b/packages/client/src/utils/peer-utils.test.ts @@ -8,12 +8,12 @@ import { isInputPeerChannel, isInputPeerChat, isInputPeerUser, - normalizeToInputChannel, - normalizeToInputPeer, - normalizeToInputUser, + toInputChannel, + toInputPeer, + toInputUser, } from './peer-utils.js' -describe('normalizeToInputPeer', () => { +describe('toInputPeer', () => { it.each([ ['inputChannelEmpty', 'inputPeerEmpty'], ['inputUserEmpty', 'inputPeerEmpty'], @@ -27,7 +27,7 @@ describe('normalizeToInputPeer', () => { const from = createStub(fromType) const to = createStub(toType) - expect(normalizeToInputPeer(from)).toEqual(to) + expect(toInputPeer(from)).toEqual(to) }) it.each([ @@ -40,11 +40,11 @@ describe('normalizeToInputPeer', () => { ] as const)('should keep %s as is', (type) => { const obj = createStub(type) - expect(normalizeToInputPeer(obj)).toBe(obj) + expect(toInputPeer(obj)).toBe(obj) }) }) -describe('normalizeToInputUser', () => { +describe('toInputUser', () => { it.each([ ['inputPeerSelf', 'inputUserSelf'], ['inputPeerUser', 'inputUser'], @@ -53,17 +53,15 @@ describe('normalizeToInputUser', () => { const from = createStub(fromType) const to = createStub(toType) - expect(normalizeToInputUser(from)).toEqual(to) + expect(toInputUser(from)).toEqual(to) }) it('should throw for other types', () => { - expect(() => normalizeToInputUser(createStub('inputPeerChannel'), 'some_channel')).toThrow( - MtInvalidPeerTypeError, - ) + expect(() => toInputUser(createStub('inputPeerChannel'), 'some_channel')).toThrow(MtInvalidPeerTypeError) }) }) -describe('normalizeToInputChannel', () => { +describe('toInputChannel', () => { it.each([ ['inputPeerChannel', 'inputChannel'], ['inputPeerChannelFromMessage', 'inputChannelFromMessage'], @@ -71,11 +69,11 @@ describe('normalizeToInputChannel', () => { const from = createStub(fromType) const to = createStub(toType) - expect(normalizeToInputChannel(from)).toEqual(to) + expect(toInputChannel(from)).toEqual(to) }) it('should throw for other types', () => { - expect(() => normalizeToInputChannel(createStub('inputPeerUser'), 'some_user')).toThrow(MtInvalidPeerTypeError) + expect(() => toInputChannel(createStub('inputPeerUser'), 'some_user')).toThrow(MtInvalidPeerTypeError) }) }) diff --git a/packages/client/src/utils/peer-utils.ts b/packages/client/src/utils/peer-utils.ts index da39d784..02adc632 100644 --- a/packages/client/src/utils/peer-utils.ts +++ b/packages/client/src/utils/peer-utils.ts @@ -6,9 +6,9 @@ import { InputPeerLike } from '../types/peers/index.js' export const INVITE_LINK_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)\/(?:joinchat\/|\+))([\w-]+)$/i -// helpers to normalize result of `resolvePeer` function +// helpers to convert result of `resolvePeer` function -export function normalizeToInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): tl.TypeInputPeer { +export function toInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): tl.TypeInputPeer { if (tl.isAnyInputPeer(res)) return res switch (res._) { @@ -48,7 +48,7 @@ export function normalizeToInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | } } -export function normalizeToInputUser( +export function toInputUser( res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel, input?: InputPeerLike, ): tl.TypeInputUser { @@ -75,7 +75,7 @@ export function normalizeToInputUser( throw new MtInvalidPeerTypeError(input ?? res, 'user') } -export function normalizeToInputChannel( +export function toInputChannel( res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel, input?: InputPeerLike, ): tl.TypeInputChannel {