From f7e8051a947e4a64a21226d63bd8ee5cea9929a2 Mon Sep 17 00:00:00 2001 From: teidesu Date: Sat, 15 May 2021 20:25:59 +0300 Subject: [PATCH] refactor(client): made resolvePeer return InputPeer, and removed now redundant normalizeTo calls --- packages/client/src/client.ts | 12 +++-------- .../src/methods/chats/add-chat-members.ts | 4 +--- .../client/src/methods/chats/archive-chats.ts | 3 +-- .../src/methods/chats/ban-chat-member.ts | 5 ++--- .../src/methods/chats/delete-chat-photo.ts | 3 +-- .../client/src/methods/chats/delete-group.ts | 6 +++--- .../src/methods/chats/delete-history.ts | 4 ++-- .../src/methods/chats/get-chat-member.ts | 21 +++++++------------ .../src/methods/chats/get-chat-members.ts | 9 ++++---- packages/client/src/methods/chats/get-chat.ts | 3 +-- .../client/src/methods/chats/get-full-chat.ts | 20 +++++++++++------- .../src/methods/chats/kick-chat-member.ts | 6 +++--- .../client/src/methods/chats/leave-chat.ts | 6 +++--- .../src/methods/chats/mark-chat-unread.ts | 3 +-- .../src/methods/chats/restrict-chat-member.ts | 5 ++--- .../client/src/methods/chats/save-draft.ts | 3 +-- .../chats/set-chat-default-permissions.ts | 5 ++--- .../src/methods/chats/set-chat-description.ts | 3 +-- .../src/methods/chats/set-chat-photo.ts | 3 +-- .../src/methods/chats/set-chat-title.ts | 3 +-- .../src/methods/chats/unarchive-chats.ts | 3 +-- .../src/methods/chats/unban-chat-member.ts | 5 ++--- .../invite-links/create-invite-link.ts | 3 +-- .../methods/invite-links/edit-invite-link.ts | 4 ++-- .../invite-links/export-invite-link.ts | 3 +-- .../invite-links/get-invite-link-members.ts | 4 ++-- .../methods/invite-links/get-invite-link.ts | 4 ++-- .../methods/invite-links/get-invite-links.ts | 3 +-- .../invite-links/get-primary-invite-link.ts | 7 ++----- .../invite-links/revoke-invite-link.ts | 4 ++-- .../client/src/methods/messages/close-poll.ts | 14 ++++++------- .../src/methods/messages/delete-messages.ts | 12 ++++++----- .../src/methods/messages/edit-message.ts | 3 +-- .../src/methods/messages/forward-messages.ts | 5 ++--- .../src/methods/messages/get-history.ts | 6 +++--- .../src/methods/messages/get-messages.ts | 3 +-- .../src/methods/messages/iter-history.ts | 3 +-- .../src/methods/messages/pin-message.ts | 3 +-- .../src/methods/messages/read-history.ts | 18 +++++++++------- .../src/methods/messages/search-messages.ts | 12 ++++------- .../client/src/methods/messages/send-copy.ts | 3 +-- .../src/methods/messages/send-media-group.ts | 3 +-- .../client/src/methods/messages/send-media.ts | 3 +-- .../client/src/methods/messages/send-text.ts | 4 ++-- .../src/methods/messages/send-typing.ts | 3 +-- .../client/src/methods/messages/send-vote.ts | 7 ++----- .../methods/messages/unpin-all-messages.ts | 4 ++-- .../src/methods/messages/unpin-message.ts | 3 +-- .../client/src/methods/users/block-user.ts | 3 +-- .../src/methods/users/resolve-peer-many.ts | 6 +++--- .../client/src/methods/users/resolve-peer.ts | 5 +++-- .../client/src/methods/users/unblock-user.ts | 3 +-- 52 files changed, 127 insertions(+), 166 deletions(-) diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index ed68f6eb..ea73fbfe 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -2756,9 +2756,7 @@ export interface TelegramClient extends BaseTelegramClient { T extends tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel >( peerIds: InputPeerLike[], - normalizer: ( - obj: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel - ) => T | null + normalizer: (obj: tl.TypeInputPeer) => T | null ): Promise /** * Get multiple `InputPeer`s at once. @@ -2767,18 +2765,14 @@ export interface TelegramClient extends BaseTelegramClient { * * @param peerIds Peer Ids */ - resolvePeerMany( - peerIds: InputPeerLike[] - ): Promise<(tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel)[]> + resolvePeerMany(peerIds: InputPeerLike[]): Promise /** * Get the `InputPeer` of a known peer id. * Useful when an `InputPeer` is needed. * * @param peerId The peer identifier that you want to extract the `InputPeer` from. */ - resolvePeer( - peerId: InputPeerLike - ): Promise + resolvePeer(peerId: InputPeerLike): Promise /** * Change user status to offline or online * diff --git a/packages/client/src/methods/chats/add-chat-members.ts b/packages/client/src/methods/chats/add-chat-members.ts index a83ac039..9ef9dae8 100644 --- a/packages/client/src/methods/chats/add-chat-members.ts +++ b/packages/client/src/methods/chats/add-chat-members.ts @@ -5,10 +5,8 @@ import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, normalizeToInputUser, } from '../../utils/peer-utils' -import { tl } from '@mtcute/tl' /** * Add new members to a group, supergroup or channel. @@ -26,7 +24,7 @@ export async function addChatMembers( users: MaybeArray, forwardCount = 100 ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) if (!Array.isArray(users)) users = [users] diff --git a/packages/client/src/methods/chats/archive-chats.ts b/packages/client/src/methods/chats/archive-chats.ts index 0bca6f6c..7247c168 100644 --- a/packages/client/src/methods/chats/archive-chats.ts +++ b/packages/client/src/methods/chats/archive-chats.ts @@ -2,7 +2,6 @@ import { TelegramClient } from '../../client' import { MaybeArray } from '@mtcute/core' import { InputPeerLike } from '../../types' import { tl } from '@mtcute/tl' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Archive one or more chats @@ -21,7 +20,7 @@ export async function archiveChats( for (const chat of chats) { folderPeers.push({ _: 'inputFolderPeer', - peer: normalizeToInputPeer(await this.resolvePeer(chat)), + peer: await this.resolvePeer(chat), folderId: 1 }) } diff --git a/packages/client/src/methods/chats/ban-chat-member.ts b/packages/client/src/methods/chats/ban-chat-member.ts index d1d5f70e..438a37b9 100644 --- a/packages/client/src/methods/chats/ban-chat-member.ts +++ b/packages/client/src/methods/chats/ban-chat-member.ts @@ -9,7 +9,6 @@ import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, normalizeToInputUser, } from '../../utils/peer-utils' @@ -28,8 +27,8 @@ export async function banChatMember( chatId: InputPeerLike, userId: InputPeerLike ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) - const user = normalizeToInputPeer(await this.resolvePeer(userId)) + const chat = await this.resolvePeer(chatId) + const user = await this.resolvePeer(userId) let res if (isInputPeerChannel(chat)) { diff --git a/packages/client/src/methods/chats/delete-chat-photo.ts b/packages/client/src/methods/chats/delete-chat-photo.ts index 9aeffef0..c4098e33 100644 --- a/packages/client/src/methods/chats/delete-chat-photo.ts +++ b/packages/client/src/methods/chats/delete-chat-photo.ts @@ -4,7 +4,6 @@ import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' /** @@ -19,7 +18,7 @@ export async function deleteChatPhoto( this: TelegramClient, chatId: InputPeerLike ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) let res if (isInputPeerChat(chat)) { diff --git a/packages/client/src/methods/chats/delete-group.ts b/packages/client/src/methods/chats/delete-group.ts index 0e7970cf..b8c8b66a 100644 --- a/packages/client/src/methods/chats/delete-group.ts +++ b/packages/client/src/methods/chats/delete-group.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' +import { isInputPeerChat } from '../../utils/peer-utils' /** * Delete a legacy group chat for all members @@ -12,8 +12,8 @@ export async function deleteGroup( this: TelegramClient, chatId: InputPeerLike ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) - if (chat._ !== 'inputPeerChat') + const chat = await this.resolvePeer(chatId) + if (!isInputPeerChat(chat)) throw new MtCuteInvalidPeerTypeError(chatId, 'chat') const res = await this.call({ diff --git a/packages/client/src/methods/chats/delete-history.ts b/packages/client/src/methods/chats/delete-history.ts index 885a96c6..b9a7abf8 100644 --- a/packages/client/src/methods/chats/delete-history.ts +++ b/packages/client/src/methods/chats/delete-history.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { normalizeToInputChannel, normalizeToInputPeer } from '../../utils/peer-utils' +import { normalizeToInputChannel } from '../../utils/peer-utils' import { createDummyUpdate } from '../../utils/updates-utils' import { tl } from '@mtcute/tl' @@ -25,7 +25,7 @@ export async function deleteHistory( mode: 'delete' | 'clear' | 'revoke' = 'delete', maxId = 0 ): Promise { - const peer = normalizeToInputPeer(await this.resolvePeer(chat)) + const peer = await this.resolvePeer(chat) const res = await this.call({ _: 'messages.deleteHistory', diff --git a/packages/client/src/methods/chats/get-chat-member.ts b/packages/client/src/methods/chats/get-chat-member.ts index a3f02503..2ea04c54 100644 --- a/packages/client/src/methods/chats/get-chat-member.ts +++ b/packages/client/src/methods/chats/get-chat-member.ts @@ -1,12 +1,11 @@ import { TelegramClient } from '../../client' +import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types' import { - InputPeerLike, - MtCuteInvalidPeerTypeError, -} from '../../types' -import { - createUsersChatsIndex, isInputPeerChannel, isInputPeerChat, isInputPeerUser, + createUsersChatsIndex, + isInputPeerChannel, + isInputPeerChat, + isInputPeerUser, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' import { assertTypeIs } from '../../utils/type-assertion' import { tl } from '@mtcute/tl' @@ -26,8 +25,8 @@ export async function getChatMember( chatId: InputPeerLike, userId: InputPeerLike ): Promise { - const user = normalizeToInputPeer(await this.resolvePeer(userId)) - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const user = await this.resolvePeer(userId) + const chat = await this.resolvePeer(chatId) if (isInputPeerChat(chat)) { if (!isInputPeerUser(user)) @@ -71,10 +70,6 @@ export async function getChatMember( const { users } = createUsersChatsIndex(res) - return new ChatMember( - this, - res.participant, - users - ) + return new ChatMember(this, res.participant, users) } else throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel') } diff --git a/packages/client/src/methods/chats/get-chat-members.ts b/packages/client/src/methods/chats/get-chat-members.ts index 39495062..91dd4301 100644 --- a/packages/client/src/methods/chats/get-chat-members.ts +++ b/packages/client/src/methods/chats/get-chat-members.ts @@ -5,9 +5,10 @@ import { } from '../../types' import { TelegramClient } from '../../client' import { - createUsersChatsIndex, isInputPeerChannel, isInputPeerChat, + createUsersChatsIndex, + isInputPeerChannel, + isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' import { assertTypeIs } from '../../utils/type-assertion' import { tl } from '@mtcute/tl' @@ -70,7 +71,7 @@ export async function getChatMembers( ): Promise { if (!params) params = {} - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) if (isInputPeerChat(chat)) { const res = await this.call({ @@ -145,7 +146,7 @@ export async function getChatMembers( ) const { users } = createUsersChatsIndex(res) - return res.participants.map(i => new ChatMember(this, i, users)) + return res.participants.map((i) => new ChatMember(this, i, users)) } throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel') diff --git a/packages/client/src/methods/chats/get-chat.ts b/packages/client/src/methods/chats/get-chat.ts index 1b2d9708..203d2631 100644 --- a/packages/client/src/methods/chats/get-chat.ts +++ b/packages/client/src/methods/chats/get-chat.ts @@ -6,7 +6,6 @@ import { isInputPeerChat, isInputPeerUser, normalizeToInputChannel, - normalizeToInputPeer, normalizeToInputUser, } from '../../utils/peer-utils' import { tl } from '@mtcute/tl' @@ -42,7 +41,7 @@ export async function getChat( } } - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) let res: tl.TypeChat | tl.TypeUser if (isInputPeerChannel(peer)) { diff --git a/packages/client/src/methods/chats/get-full-chat.ts b/packages/client/src/methods/chats/get-full-chat.ts index d3a09980..2c50daf9 100644 --- a/packages/client/src/methods/chats/get-full-chat.ts +++ b/packages/client/src/methods/chats/get-full-chat.ts @@ -1,9 +1,11 @@ import { Chat, InputPeerLike, MtCuteArgumentError } from '../../types' import { TelegramClient } from '../../client' import { - INVITE_LINK_REGEX, isInputPeerChannel, isInputPeerChat, isInputPeerUser, + INVITE_LINK_REGEX, + isInputPeerChannel, + isInputPeerChat, + isInputPeerUser, normalizeToInputChannel, - normalizeToInputPeer, normalizeToInputUser, } from '../../utils/peer-utils' import { tl } from '@mtcute/tl' @@ -26,11 +28,13 @@ export async function getFullChat( if (m) { const res = await this.call({ _: 'messages.checkChatInvite', - hash: m[1] + hash: m[1], }) if (res._ === 'chatInvite') { - throw new MtCuteArgumentError(`You haven't joined ${JSON.stringify(res.title)}`) + throw new MtCuteArgumentError( + `You haven't joined ${JSON.stringify(res.title)}` + ) } // we still need to fetch full chat info @@ -38,23 +42,23 @@ export async function getFullChat( } } - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) let res: tl.messages.TypeChatFull | tl.TypeUserFull if (isInputPeerChannel(peer)) { res = await this.call({ _: 'channels.getFullChannel', - channel: normalizeToInputChannel(peer) + channel: normalizeToInputChannel(peer), }) } else if (isInputPeerUser(peer)) { res = await this.call({ _: 'users.getFullUser', - id: normalizeToInputUser(peer)! + id: normalizeToInputUser(peer)!, }) } else if (isInputPeerChat(peer)) { res = await this.call({ _: 'messages.getFullChat', - chatId: peer.chatId + chatId: peer.chatId, }) } else throw new Error('should not happen') diff --git a/packages/client/src/methods/chats/kick-chat-member.ts b/packages/client/src/methods/chats/kick-chat-member.ts index 065b7558..d6325ae8 100644 --- a/packages/client/src/methods/chats/kick-chat-member.ts +++ b/packages/client/src/methods/chats/kick-chat-member.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { isInputPeerChannel, normalizeToInputPeer } from '../../utils/peer-utils' +import { isInputPeerChannel } from '../../utils/peer-utils' /** * Kick a user from a chat. @@ -16,8 +16,8 @@ export async function kickChatMember( chatId: InputPeerLike, userId: InputPeerLike ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) - const user = normalizeToInputPeer(await this.resolvePeer(userId)) + const chat = await this.resolvePeer(chatId) + const user = await this.resolvePeer(userId) await this.banChatMember(chat, user) diff --git a/packages/client/src/methods/chats/leave-chat.ts b/packages/client/src/methods/chats/leave-chat.ts index 1e833503..f2553132 100644 --- a/packages/client/src/methods/chats/leave-chat.ts +++ b/packages/client/src/methods/chats/leave-chat.ts @@ -1,9 +1,9 @@ import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types' import { TelegramClient } from '../../client' import { - isInputPeerChannel, isInputPeerChat, + isInputPeerChannel, + isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' /** @@ -18,7 +18,7 @@ export async function leaveChat( chatId: InputPeerLike, clear = false ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) if (isInputPeerChannel(chat)) { const res = await this.call({ diff --git a/packages/client/src/methods/chats/mark-chat-unread.ts b/packages/client/src/methods/chats/mark-chat-unread.ts index 5aad28d7..6fd778a8 100644 --- a/packages/client/src/methods/chats/mark-chat-unread.ts +++ b/packages/client/src/methods/chats/mark-chat-unread.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Mark a chat as unread @@ -16,7 +15,7 @@ export async function markChatUnread( _: 'messages.markDialogUnread', peer: { _: 'inputDialogPeer', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), }, unread: true }) diff --git a/packages/client/src/methods/chats/restrict-chat-member.ts b/packages/client/src/methods/chats/restrict-chat-member.ts index 7434837d..67ec7d37 100644 --- a/packages/client/src/methods/chats/restrict-chat-member.ts +++ b/packages/client/src/methods/chats/restrict-chat-member.ts @@ -3,7 +3,6 @@ import { InputPeerLike, MtCuteInvalidPeerTypeError } from '../../types' import { isInputPeerChannel, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' import { tl } from '@mtcute/tl' import { normalizeDate } from '../../utils/misc-utils' @@ -32,11 +31,11 @@ export async function restrictChatMember( restrictions: Omit, until?: number | Date ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) if (!isInputPeerChannel(chat)) throw new MtCuteInvalidPeerTypeError(chatId, 'channel') - const user = normalizeToInputPeer(await this.resolvePeer(userId)) + const user = await this.resolvePeer(userId) const res = await this.call({ _: 'channels.editBanned', diff --git a/packages/client/src/methods/chats/save-draft.ts b/packages/client/src/methods/chats/save-draft.ts index 30008a72..e412be08 100644 --- a/packages/client/src/methods/chats/save-draft.ts +++ b/packages/client/src/methods/chats/save-draft.ts @@ -1,7 +1,6 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' import { tl } from '@mtcute/tl' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Save or delete a draft message associated with some chat @@ -15,7 +14,7 @@ export async function saveDraft( chatId: InputPeerLike, draft: null | Omit ): Promise { - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) if (draft) { await this.call({ diff --git a/packages/client/src/methods/chats/set-chat-default-permissions.ts b/packages/client/src/methods/chats/set-chat-default-permissions.ts index bd87e482..2a47c38a 100644 --- a/packages/client/src/methods/chats/set-chat-default-permissions.ts +++ b/packages/client/src/methods/chats/set-chat-default-permissions.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' -import { Chat, InputChatPermissions, InputPeerLike, MtCuteTypeAssertionError } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' +import { Chat, InputPeerLike, MtCuteTypeAssertionError } from '../../types' import { tl } from '@mtcute/tl' /** @@ -21,7 +20,7 @@ export async function setChatDefaultPermissions( chatId: InputPeerLike, restrictions: Omit ): Promise { - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const res = await this.call({ _: 'messages.editChatDefaultBannedRights', diff --git a/packages/client/src/methods/chats/set-chat-description.ts b/packages/client/src/methods/chats/set-chat-description.ts index 1e870ffa..60163e11 100644 --- a/packages/client/src/methods/chats/set-chat-description.ts +++ b/packages/client/src/methods/chats/set-chat-description.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Change chat description @@ -16,7 +15,7 @@ export async function setChatDescription( chatId: InputPeerLike, description: string ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) await this.call({ _: 'messages.editChatAbout', diff --git a/packages/client/src/methods/chats/set-chat-photo.ts b/packages/client/src/methods/chats/set-chat-photo.ts index b9b4b843..529629e5 100644 --- a/packages/client/src/methods/chats/set-chat-photo.ts +++ b/packages/client/src/methods/chats/set-chat-photo.ts @@ -10,7 +10,6 @@ import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' import { tl } from '@mtcute/tl' import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id' @@ -35,7 +34,7 @@ export async function setChatPhoto( media: InputFileLike, previewSec?: number ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) if (!(isInputPeerChannel(chat) || isInputPeerChat(chat))) throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel') diff --git a/packages/client/src/methods/chats/set-chat-title.ts b/packages/client/src/methods/chats/set-chat-title.ts index 6a370b4b..4366fb23 100644 --- a/packages/client/src/methods/chats/set-chat-title.ts +++ b/packages/client/src/methods/chats/set-chat-title.ts @@ -7,7 +7,6 @@ import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' /** @@ -24,7 +23,7 @@ export async function setChatTitle( chatId: InputPeerLike, title: string ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) + const chat = await this.resolvePeer(chatId) let res if (isInputPeerChat(chat)) { diff --git a/packages/client/src/methods/chats/unarchive-chats.ts b/packages/client/src/methods/chats/unarchive-chats.ts index 42ce33d6..62c95c84 100644 --- a/packages/client/src/methods/chats/unarchive-chats.ts +++ b/packages/client/src/methods/chats/unarchive-chats.ts @@ -2,7 +2,6 @@ import { TelegramClient } from '../../client' import { MaybeArray } from '@mtcute/core' import { InputPeerLike } from '../../types' import { tl } from '@mtcute/tl' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Unarchive one or more chats @@ -21,7 +20,7 @@ export async function unarchiveChats( for (const chat of chats) { folderPeers.push({ _: 'inputFolderPeer', - peer: normalizeToInputPeer(await this.resolvePeer(chat)), + peer: await this.resolvePeer(chat), folderId: 0 }) } diff --git a/packages/client/src/methods/chats/unban-chat-member.ts b/packages/client/src/methods/chats/unban-chat-member.ts index 10e34a48..d888bbd0 100644 --- a/packages/client/src/methods/chats/unban-chat-member.ts +++ b/packages/client/src/methods/chats/unban-chat-member.ts @@ -4,7 +4,6 @@ import { isInputPeerChannel, isInputPeerChat, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' // @alias=unrestrictChatMember @@ -25,8 +24,8 @@ export async function unbanChatMember( chatId: InputPeerLike, userId: InputPeerLike ): Promise { - const chat = normalizeToInputPeer(await this.resolvePeer(chatId)) - const user = normalizeToInputPeer(await this.resolvePeer(userId)) + const chat = await this.resolvePeer(chatId) + const user = await this.resolvePeer(userId) if (isInputPeerChannel(chat)) { const res = await this.call({ diff --git a/packages/client/src/methods/invite-links/create-invite-link.ts b/packages/client/src/methods/invite-links/create-invite-link.ts index 45244928..c97e10f5 100644 --- a/packages/client/src/methods/invite-links/create-invite-link.ts +++ b/packages/client/src/methods/invite-links/create-invite-link.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { ChatInviteLink, InputPeerLike } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' import { normalizeDate } from '../../utils/misc-utils' /** @@ -35,7 +34,7 @@ export async function createInviteLink( const res = await this.call({ _: 'messages.exportChatInvite', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), expireDate: normalizeDate(params.expires), usageLimit: params.usageLimit }) diff --git a/packages/client/src/methods/invite-links/edit-invite-link.ts b/packages/client/src/methods/invite-links/edit-invite-link.ts index ff106d0a..f541004b 100644 --- a/packages/client/src/methods/invite-links/edit-invite-link.ts +++ b/packages/client/src/methods/invite-links/edit-invite-link.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { ChatInviteLink, InputPeerLike } from '../../types' -import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' import { normalizeDate } from '../../utils/misc-utils' /** @@ -37,7 +37,7 @@ export async function editInviteLink( ): Promise { const res = await this.call({ _: 'messages.editExportedChatInvite', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), link, expireDate: normalizeDate(params.expires), usageLimit: params.usageLimit diff --git a/packages/client/src/methods/invite-links/export-invite-link.ts b/packages/client/src/methods/invite-links/export-invite-link.ts index 7123a8d0..2599aec4 100644 --- a/packages/client/src/methods/invite-links/export-invite-link.ts +++ b/packages/client/src/methods/invite-links/export-invite-link.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { ChatInviteLink, InputPeerLike } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Generate a new primary invite link for a chat, @@ -18,7 +17,7 @@ export async function exportInviteLink( ): Promise { const res = await this.call({ _: 'messages.exportChatInvite', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), legacyRevokePermanent: true }) 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 c0bb26af..3c9707b9 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,6 +1,6 @@ import { TelegramClient } from '../../client' import { ChatInviteLink, InputPeerLike, User } from '../../types' -import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' import { tl } from '@mtcute/tl' /** @@ -18,7 +18,7 @@ export async function* getInviteLinkMembers( link: string, limit = Infinity ): AsyncIterableIterator { - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) let current = 0 diff --git a/packages/client/src/methods/invite-links/get-invite-link.ts b/packages/client/src/methods/invite-links/get-invite-link.ts index 082214cb..1004d7fa 100644 --- a/packages/client/src/methods/invite-links/get-invite-link.ts +++ b/packages/client/src/methods/invite-links/get-invite-link.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { ChatInviteLink, InputPeerLike } from '../../types' -import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' /** * Get detailed information about an invite link @@ -16,7 +16,7 @@ export async function getInviteLink( ): Promise { const res = await this.call({ _: 'messages.getExportedChatInvite', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), link }) 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 65772d87..1a11a46c 100644 --- a/packages/client/src/methods/invite-links/get-invite-links.ts +++ b/packages/client/src/methods/invite-links/get-invite-links.ts @@ -6,7 +6,6 @@ import { } from '../../types' import { createUsersChatsIndex, - normalizeToInputPeer, normalizeToInputUser, } from '../../utils/peer-utils' import { tl } from '@mtcute/tl' @@ -53,7 +52,7 @@ export async function* getInviteLinks( const total = params.limit || Infinity const chunkSize = Math.min(params.chunkSize ?? 100, total) - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const admin = normalizeToInputUser(await this.resolvePeer(adminId)) if (!admin) throw new MtCuteInvalidPeerTypeError(adminId, 'user') diff --git a/packages/client/src/methods/invite-links/get-primary-invite-link.ts b/packages/client/src/methods/invite-links/get-primary-invite-link.ts index 25e0ce2e..1d176cd3 100644 --- a/packages/client/src/methods/invite-links/get-primary-invite-link.ts +++ b/packages/client/src/methods/invite-links/get-primary-invite-link.ts @@ -4,10 +4,7 @@ import { InputPeerLike, MtCuteTypeAssertionError, } from '../../types' -import { - createUsersChatsIndex, - normalizeToInputPeer, -} from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' /** * Get primary invite link of a chat @@ -21,7 +18,7 @@ export async function getPrimaryInviteLink( ): Promise { const res = await this.call({ _: 'messages.getExportedChatInvites', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), adminId: { _: 'inputUserSelf' }, limit: 1, revoked: false, diff --git a/packages/client/src/methods/invite-links/revoke-invite-link.ts b/packages/client/src/methods/invite-links/revoke-invite-link.ts index 9075c6b9..347a1788 100644 --- a/packages/client/src/methods/invite-links/revoke-invite-link.ts +++ b/packages/client/src/methods/invite-links/revoke-invite-link.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { ChatInviteLink, InputPeerLike } from '../../types' -import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' /** * Revoke an invite link. @@ -20,7 +20,7 @@ export async function revokeInviteLink( ): Promise { const res = await this.call({ _: 'messages.editExportedChatInvite', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), link, revoked: true }) diff --git a/packages/client/src/methods/messages/close-poll.ts b/packages/client/src/methods/messages/close-poll.ts index 89dfa1cd..dc6ea0f4 100644 --- a/packages/client/src/methods/messages/close-poll.ts +++ b/packages/client/src/methods/messages/close-poll.ts @@ -1,10 +1,6 @@ import { TelegramClient } from '../../client' import { InputPeerLike, MtCuteTypeAssertionError, Poll } from '../../types' -import { tl } from '@mtcute/tl' -import { - createUsersChatsIndex, - normalizeToInputPeer, -} from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' import bigInt from 'big-integer' import { assertTypeIs } from '../../utils/type-assertion' @@ -25,7 +21,7 @@ export async function closePoll( ): Promise { const res = await this.call({ _: 'messages.editMessage', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), id: message, media: { _: 'inputMediaPoll', @@ -49,7 +45,11 @@ export async function closePoll( this._handleUpdate(res, true) const upd = res.updates[0] - assertTypeIs('messages.editMessage (@ .updates[0])', upd, 'updateMessagePoll') + assertTypeIs( + 'messages.editMessage (@ .updates[0])', + upd, + 'updateMessagePoll' + ) if (!upd.poll) { throw new MtCuteTypeAssertionError( 'messages.editMessage (@ .updates[0].poll)', diff --git a/packages/client/src/methods/messages/delete-messages.ts b/packages/client/src/methods/messages/delete-messages.ts index b9926f89..d6e8c21d 100644 --- a/packages/client/src/methods/messages/delete-messages.ts +++ b/packages/client/src/methods/messages/delete-messages.ts @@ -1,9 +1,11 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' import { MaybeArray } from '@mtcute/core' -import { isInputPeerChannel, normalizeToInputChannel, normalizeToInputPeer } from '../../utils/peer-utils' +import { + isInputPeerChannel, + normalizeToInputChannel, +} from '../../utils/peer-utils' import { createDummyUpdate } from '../../utils/updates-utils' -import { tl } from '@mtcute/tl' /** * Delete messages, including service messages. @@ -21,7 +23,7 @@ export async function deleteMessages( ): Promise { if (!Array.isArray(ids)) ids = [ids] - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) let upd if (isInputPeerChannel(peer)) { @@ -29,14 +31,14 @@ export async function deleteMessages( const res = await this.call({ _: 'channels.deleteMessages', channel, - id: ids + id: ids, }) upd = createDummyUpdate(res.pts, res.ptsCount, peer.channelId) } else { const res = await this.call({ _: 'messages.deleteMessages', id: ids, - revoke + revoke, }) upd = createDummyUpdate(res.pts, res.ptsCount) } diff --git a/packages/client/src/methods/messages/edit-message.ts b/packages/client/src/methods/messages/edit-message.ts index 665a8491..b93e6940 100644 --- a/packages/client/src/methods/messages/edit-message.ts +++ b/packages/client/src/methods/messages/edit-message.ts @@ -7,7 +7,6 @@ import { ReplyMarkup, } from '../../types' import { tl } from '@mtcute/tl' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Edit message text, media, reply markup and schedule date. @@ -105,7 +104,7 @@ export async function editMessage( const res = await this.call({ _: 'messages.editMessage', id: typeof message === 'number' ? message : message.id, - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), noWebpage: params.disableWebPreview, replyMarkup: BotKeyboard._convertToTl(params.replyMarkup), message: content, diff --git a/packages/client/src/methods/messages/forward-messages.ts b/packages/client/src/methods/messages/forward-messages.ts index 3031329d..7cd0fbb8 100644 --- a/packages/client/src/methods/messages/forward-messages.ts +++ b/packages/client/src/methods/messages/forward-messages.ts @@ -10,7 +10,6 @@ import { MaybeArray } from '@mtcute/core' import { tl } from '@mtcute/tl' import { createUsersChatsIndex, - normalizeToInputPeer, } from '../../utils/peer-utils' import { normalizeDate, randomUlong } from '../../utils/misc-utils' @@ -193,7 +192,7 @@ export async function forwardMessages( 'You can forward no more than 100 messages at once' ) - const toPeer = normalizeToInputPeer(await this.resolvePeer(toChatId)) + const toPeer = await this.resolvePeer(toChatId) let captionMessage: Message | null = null if (params.caption) { @@ -221,7 +220,7 @@ export async function forwardMessages( const res = await this.call({ _: 'messages.forwardMessages', toPeer, - fromPeer: normalizeToInputPeer(await this.resolvePeer(fromChatId)), + fromPeer: await this.resolvePeer(fromChatId), id: messages as number[], silent: params.silent, scheduleDate: normalizeDate(params.schedule), diff --git a/packages/client/src/methods/messages/get-history.ts b/packages/client/src/methods/messages/get-history.ts index 0c45c881..bfbb2096 100644 --- a/packages/client/src/methods/messages/get-history.ts +++ b/packages/client/src/methods/messages/get-history.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' -import { InputPeerLike, Message, MtCuteArgumentError, MtCuteTypeAssertionError } from '../../types' -import { createUsersChatsIndex, normalizeToInputPeer } from '../../utils/peer-utils' +import { InputPeerLike, Message, MtCuteTypeAssertionError } from '../../types' +import { createUsersChatsIndex, } from '../../utils/peer-utils' import { normalizeDate } from '../../utils/misc-utils' /** @@ -57,7 +57,7 @@ export async function getHistory( params.offsetId ?? (params.reverse && !params.offsetDate ? 1 : 0) const limit = params.limit || 100 - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const res = await this.call({ _: 'messages.getHistory', diff --git a/packages/client/src/methods/messages/get-messages.ts b/packages/client/src/methods/messages/get-messages.ts index 37d4abbe..fcf8f3ef 100644 --- a/packages/client/src/methods/messages/get-messages.ts +++ b/packages/client/src/methods/messages/get-messages.ts @@ -4,7 +4,6 @@ import { createUsersChatsIndex, isInputPeerChannel, normalizeToInputChannel, - normalizeToInputPeer, } from '../../utils/peer-utils' import { tl } from '@mtcute/tl' import { Message, InputPeerLike, MtCuteTypeAssertionError } from '../../types' @@ -53,7 +52,7 @@ export async function getMessages( messageIds: MaybeArray, fromReply = false ): Promise> { - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const isSingle = !Array.isArray(messageIds) if (isSingle) messageIds = [messageIds as number] diff --git a/packages/client/src/methods/messages/iter-history.ts b/packages/client/src/methods/messages/iter-history.ts index 94f18982..ea795899 100644 --- a/packages/client/src/methods/messages/iter-history.ts +++ b/packages/client/src/methods/messages/iter-history.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { InputPeerLike, Message } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Iterate through a chat history sequentially. @@ -68,7 +67,7 @@ export async function* iterHistory( const limit = Math.min(params.chunkSize || 100, total) // resolve peer once and pass an InputPeer afterwards - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) for (;;) { const messages = await this.getHistory(peer, { diff --git a/packages/client/src/methods/messages/pin-message.ts b/packages/client/src/methods/messages/pin-message.ts index aeffbdb2..3aced73e 100644 --- a/packages/client/src/methods/messages/pin-message.ts +++ b/packages/client/src/methods/messages/pin-message.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Pin a message in a group, supergroup, channel or PM. @@ -23,7 +22,7 @@ export async function pinMessage( ): Promise { const res = await this.call({ _: 'messages.updatePinnedMessage', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), id: messageId, silent: !notify, pmOneside: !bothSides diff --git a/packages/client/src/methods/messages/read-history.ts b/packages/client/src/methods/messages/read-history.ts index 8992bbf5..91e1dc17 100644 --- a/packages/client/src/methods/messages/read-history.ts +++ b/packages/client/src/methods/messages/read-history.ts @@ -1,6 +1,9 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { isInputPeerChannel, normalizeToInputChannel, normalizeToInputPeer } from '../../utils/peer-utils' +import { + isInputPeerChannel, + normalizeToInputChannel, +} from '../../utils/peer-utils' import { createDummyUpdate } from '../../utils/updates-utils' /** @@ -17,16 +20,18 @@ export async function readHistory( message = 0, clearMentions = false ): Promise { - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) if (clearMentions) { const res = await this.call({ _: 'messages.readMentions', - peer + peer, }) if (isInputPeerChannel(peer)) { - this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId)) + this._handleUpdate( + createDummyUpdate(res.pts, res.ptsCount, peer.channelId) + ) } else { this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount)) } @@ -36,15 +41,14 @@ export async function readHistory( await this.call({ _: 'channels.readHistory', channel: normalizeToInputChannel(peer), - maxId: message + maxId: message, }) } else { const res = await this.call({ _: 'messages.readHistory', peer, - maxId: message + maxId: message, }) this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount)) } - } diff --git a/packages/client/src/methods/messages/search-messages.ts b/packages/client/src/methods/messages/search-messages.ts index e0fad373..04dc140e 100644 --- a/packages/client/src/methods/messages/search-messages.ts +++ b/packages/client/src/methods/messages/search-messages.ts @@ -1,10 +1,7 @@ import { TelegramClient } from '../../client' import { InputPeerLike, Message, MtCuteTypeAssertionError } from '../../types' import { tl } from '@mtcute/tl' -import { - createUsersChatsIndex, - normalizeToInputPeer, -} from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' import { SearchFilters } from '../../types' /** @@ -72,11 +69,10 @@ export async function* searchMessages( const total = params.limit || Infinity const limit = Math.min(params.chunkSize || 100, total) - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const fromUser = - (params.fromUser - ? normalizeToInputPeer(await this.resolvePeer(params.fromUser)) - : null) || undefined + (params.fromUser ? await this.resolvePeer(params.fromUser) : null) || + undefined for (;;) { const res = await this.call({ diff --git a/packages/client/src/methods/messages/send-copy.ts b/packages/client/src/methods/messages/send-copy.ts index ff5890d3..4d5148ad 100644 --- a/packages/client/src/methods/messages/send-copy.ts +++ b/packages/client/src/methods/messages/send-copy.ts @@ -1,7 +1,6 @@ import { TelegramClient } from '../../client' import { InputPeerLike, Message, ReplyMarkup } from '../../types' import { tl } from '@mtcute/tl' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Copy a message (i.e. send the same message, @@ -79,7 +78,7 @@ export async function sendCopy( clearDraft?: boolean } ): Promise { - const fromPeer = normalizeToInputPeer(await this.resolvePeer(fromChatId)) + const fromPeer = await this.resolvePeer(fromChatId) const msg = await this.getMessages(fromPeer, message) return msg.sendCopy(toChatId, params) diff --git a/packages/client/src/methods/messages/send-media-group.ts b/packages/client/src/methods/messages/send-media-group.ts index 8fd6c1bf..be4d8b1d 100644 --- a/packages/client/src/methods/messages/send-media-group.ts +++ b/packages/client/src/methods/messages/send-media-group.ts @@ -6,7 +6,6 @@ import { Message, ReplyMarkup, } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' import { normalizeDate, randomUlong } from '../../utils/misc-utils' import { tl } from '@mtcute/tl' @@ -79,7 +78,7 @@ export async function sendMediaGroup( ): Promise { if (!params) params = {} - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup) const multiMedia: tl.RawInputSingleMedia[] = [] diff --git a/packages/client/src/methods/messages/send-media.ts b/packages/client/src/methods/messages/send-media.ts index ded25af5..26b43570 100644 --- a/packages/client/src/methods/messages/send-media.ts +++ b/packages/client/src/methods/messages/send-media.ts @@ -6,7 +6,6 @@ import { Message, ReplyMarkup, } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' import { normalizeDate, randomUlong } from '../../utils/misc-utils' /** @@ -94,7 +93,7 @@ export async function sendMedia( (media as any).entities ) - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup) const res = await this.call({ diff --git a/packages/client/src/methods/messages/send-text.ts b/packages/client/src/methods/messages/send-text.ts index cd52e621..18d38752 100644 --- a/packages/client/src/methods/messages/send-text.ts +++ b/packages/client/src/methods/messages/send-text.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { tl } from '@mtcute/tl' -import { inputPeerToPeer, normalizeToInputPeer } from '../../utils/peer-utils' +import { inputPeerToPeer } from '../../utils/peer-utils' import { normalizeDate, randomUlong } from '../../utils/misc-utils' import { InputPeerLike, Message, BotKeyboard, ReplyMarkup } from '../../types' @@ -76,7 +76,7 @@ export async function sendText( params.entities ) - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup) const res = await this.call({ diff --git a/packages/client/src/methods/messages/send-typing.ts b/packages/client/src/methods/messages/send-typing.ts index 15860e70..6a45085e 100644 --- a/packages/client/src/methods/messages/send-typing.ts +++ b/packages/client/src/methods/messages/send-typing.ts @@ -1,7 +1,6 @@ import { TelegramClient } from '../../client' import { tl } from '@mtcute/tl' import { InputPeerLike, TypingStatus } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Sends a current user/bot typing event @@ -74,7 +73,7 @@ export async function sendTyping( await this.call({ _: 'messages.setTyping', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), action: status }) } diff --git a/packages/client/src/methods/messages/send-vote.ts b/packages/client/src/methods/messages/send-vote.ts index f87d9e7f..b2e06162 100644 --- a/packages/client/src/methods/messages/send-vote.ts +++ b/packages/client/src/methods/messages/send-vote.ts @@ -6,10 +6,7 @@ import { Poll, } from '../../types' import { MaybeArray } from '@mtcute/core' -import { - createUsersChatsIndex, - normalizeToInputPeer, -} from '../../utils/peer-utils' +import { createUsersChatsIndex } from '../../utils/peer-utils' import { assertTypeIs } from '../../utils/type-assertion' /** @@ -33,7 +30,7 @@ export async function sendVote( if (options === null) options = [] if (!Array.isArray(options)) options = [options] - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) let poll: Poll | undefined = undefined if (options.some((it) => typeof it === 'number')) { diff --git a/packages/client/src/methods/messages/unpin-all-messages.ts b/packages/client/src/methods/messages/unpin-all-messages.ts index dee6771e..3ae7b98f 100644 --- a/packages/client/src/methods/messages/unpin-all-messages.ts +++ b/packages/client/src/methods/messages/unpin-all-messages.ts @@ -1,6 +1,6 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { isInputPeerChannel, normalizeToInputPeer } from '../../utils/peer-utils' +import { isInputPeerChannel } from '../../utils/peer-utils' import { createDummyUpdate } from '../../utils/updates-utils' /** @@ -13,7 +13,7 @@ export async function unpinAllMessages( this: TelegramClient, chatId: InputPeerLike ): Promise { - const peer = normalizeToInputPeer(await this.resolvePeer(chatId)) + const peer = await this.resolvePeer(chatId) const res = await this.call({ _: 'messages.unpinAllMessages', diff --git a/packages/client/src/methods/messages/unpin-message.ts b/packages/client/src/methods/messages/unpin-message.ts index fa1eb59b..aede0a4d 100644 --- a/packages/client/src/methods/messages/unpin-message.ts +++ b/packages/client/src/methods/messages/unpin-message.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Unpin a message in a group, supergroup, channel or PM. @@ -19,7 +18,7 @@ export async function unpinMessage( ): Promise { const res = await this.call({ _: 'messages.updatePinnedMessage', - peer: normalizeToInputPeer(await this.resolvePeer(chatId)), + peer: await this.resolvePeer(chatId), id: messageId, unpin: true }) diff --git a/packages/client/src/methods/users/block-user.ts b/packages/client/src/methods/users/block-user.ts index 44a58bc0..2cf3ce04 100644 --- a/packages/client/src/methods/users/block-user.ts +++ b/packages/client/src/methods/users/block-user.ts @@ -1,6 +1,5 @@ import { InputPeerLike } from '../../types' import { TelegramClient } from '../../client' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Block a user @@ -14,6 +13,6 @@ export async function blockUser( ): Promise { await this.call({ _: 'contacts.block', - id: normalizeToInputPeer(await this.resolvePeer(id)), + id: await this.resolvePeer(id), }) } diff --git a/packages/client/src/methods/users/resolve-peer-many.ts b/packages/client/src/methods/users/resolve-peer-many.ts index 0036e8be..cf2b201c 100644 --- a/packages/client/src/methods/users/resolve-peer-many.ts +++ b/packages/client/src/methods/users/resolve-peer-many.ts @@ -20,7 +20,7 @@ export async function resolvePeerMany< this: TelegramClient, peerIds: InputPeerLike[], normalizer: ( - obj: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel + obj: tl.TypeInputPeer ) => T | null ): Promise @@ -35,7 +35,7 @@ export async function resolvePeerMany< export async function resolvePeerMany( this: TelegramClient, peerIds: InputPeerLike[] -): Promise<(tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel)[]> +): Promise /** * @internal @@ -44,7 +44,7 @@ export async function resolvePeerMany( this: TelegramClient, peerIds: InputPeerLike[], normalizer?: ( - obj: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel + obj: tl.TypeInputPeer ) => tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | null ): Promise<(tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel)[]> { const ret: ( diff --git a/packages/client/src/methods/users/resolve-peer.ts b/packages/client/src/methods/users/resolve-peer.ts index 57ac66dd..922aa4f3 100644 --- a/packages/client/src/methods/users/resolve-peer.ts +++ b/packages/client/src/methods/users/resolve-peer.ts @@ -3,6 +3,7 @@ import { TelegramClient } from '../../client' import { InputPeerLike, MtCuteNotFoundError } from '../../types' import { getBasicPeerType, MAX_CHANNEL_ID } from '@mtcute/core' import bigInt from 'big-integer' +import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Get the `InputPeer` of a known peer id. @@ -14,9 +15,9 @@ import bigInt from 'big-integer' export async function resolvePeer( this: TelegramClient, peerId: InputPeerLike -): Promise { +): Promise { // for convenience we also accept tl objects directly - if (typeof peerId === 'object') return peerId + if (typeof peerId === 'object') return normalizeToInputPeer(peerId) if (typeof peerId === 'number') { const fromStorage = await this.storage.getPeerById(peerId) diff --git a/packages/client/src/methods/users/unblock-user.ts b/packages/client/src/methods/users/unblock-user.ts index c340503e..d5d52469 100644 --- a/packages/client/src/methods/users/unblock-user.ts +++ b/packages/client/src/methods/users/unblock-user.ts @@ -1,6 +1,5 @@ import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { normalizeToInputPeer } from '../../utils/peer-utils' /** * Unblock a user @@ -14,6 +13,6 @@ export async function unblockUser( ): Promise { await this.call({ _: 'contacts.unblock', - id: normalizeToInputPeer(await this.resolvePeer(id)), + id: await this.resolvePeer(id), }) }