diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index 93ce6511..0ca9d89b 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -1898,24 +1898,17 @@ export interface TelegramClient extends BaseTelegramClient { */ sharePhone?: boolean }): Promise - /** - * Delete a single contact from your Telegram contacts list - * - * Returns deleted contact's profile or `null` in case - * that user was not in your contacts list - * - * @param userId User ID, username or phone number - */ - deleteContacts(userId: InputPeerLike): Promise /** * Delete one or more contacts from your Telegram contacts list * * Returns deleted contact's profiles. Does not return * profiles of users that were not in your contacts list * + * **Available**: 👤 users only + * * @param userIds User IDs, usernames or phone numbers */ - deleteContacts(userIds: InputPeerLike[]): Promise + deleteContacts(userIds: MaybeArray): Promise /** * Get list of contacts from your Telegram contacts list. * **Available**: 👤 users only @@ -2001,15 +1994,11 @@ export interface TelegramClient extends BaseTelegramClient { /** * Get dialogs with certain peers. * - * @param peers Peers for which to fetch dialogs. - */ - getPeerDialogs(peers: InputPeerLike): Promise - /** - * Get dialogs with certain peers. + * **Available**: 👤 users only * * @param peers Peers for which to fetch dialogs. */ - getPeerDialogs(peers: InputPeerLike[]): Promise + getPeerDialogs(peers: MaybeArray): Promise /** * Iterate over dialogs. * @@ -2380,18 +2369,14 @@ export interface TelegramClient extends BaseTelegramClient { */ shouldDispatch?: true }): Promise - /** - * Get a single forum topic by its ID - * - * @param chatId Chat ID or username - */ - getForumTopicsById(chatId: InputPeerLike, ids: number): Promise /** * Get forum topics by their IDs * + * **Available**: ✅ both users and bots + * * @param chatId Chat ID or username */ - getForumTopicsById(chatId: InputPeerLike, ids: number[]): Promise + getForumTopicsById(chatId: InputPeerLike, ids: MaybeArray): Promise /** * Get forum topics * @@ -5080,21 +5065,17 @@ export interface TelegramClient extends BaseTelegramClient { limit?: number }, ): Promise> - /** - * Get information about a single user. - * - * @param id User's identifier. Can be ID, username, phone number, `"me"` or `"self"` or TL object - */ - getUsers(id: InputPeerLike): Promise /** * Get information about multiple users. * You can retrieve up to 200 users at once. * * Note that order is not guaranteed. * + * **Available**: ✅ both users and bots + * * @param ids Users' identifiers. Can be ID, username, phone number, `"me"`, `"self"` or TL object */ - getUsers(ids: InputPeerLike[]): Promise + getUsers(ids: MaybeArray): Promise /** * Iterate over profile photos * @@ -5353,7 +5334,6 @@ export class TelegramClient extends BaseTelegramClient { unbanChatMember = unbanChatMember.bind(null, this) unrestrictChatMember = unbanChatMember.bind(null, this) addContact = addContact.bind(null, this) - // @ts-expect-error .bind() kinda breaks typings for overloads deleteContacts = deleteContacts.bind(null, this) getContacts = getContacts.bind(null, this) importContacts = importContacts.bind(null, this) @@ -5363,7 +5343,6 @@ export class TelegramClient extends BaseTelegramClient { findFolder = findFolder.bind(null, this) getFolders = getFolders.bind(null, this) _normalizeInputFolder = _normalizeInputFolder.bind(null, this) - // @ts-expect-error .bind() kinda breaks typings for overloads getPeerDialogs = getPeerDialogs.bind(null, this) iterDialogs = iterDialogs.bind(null, this) setFoldersOrder = setFoldersOrder.bind(null, this) @@ -5379,7 +5358,6 @@ export class TelegramClient extends BaseTelegramClient { createForumTopic = createForumTopic.bind(null, this) deleteForumTopicHistory = deleteForumTopicHistory.bind(null, this) editForumTopic = editForumTopic.bind(null, this) - // @ts-expect-error .bind() kinda breaks typings for overloads getForumTopicsById = getForumTopicsById.bind(null, this) getForumTopics = getForumTopics.bind(null, this) iterForumTopics = iterForumTopics.bind(null, this) @@ -5506,7 +5484,6 @@ export class TelegramClient extends BaseTelegramClient { getMyUsername = getMyUsername.bind(null, this) getProfilePhoto = getProfilePhoto.bind(null, this) getProfilePhotos = getProfilePhotos.bind(null, this) - // @ts-expect-error .bind() kinda breaks typings for overloads getUsers = getUsers.bind(null, this) iterProfilePhotos = iterProfilePhotos.bind(null, this) // @ts-expect-error .bind() kinda breaks typings for overloads diff --git a/packages/client/src/methods/contacts/delete-contacts.ts b/packages/client/src/methods/contacts/delete-contacts.ts index 838d5508..48138d3d 100644 --- a/packages/client/src/methods/contacts/delete-contacts.ts +++ b/packages/client/src/methods/contacts/delete-contacts.ts @@ -5,16 +5,6 @@ import { normalizeToInputUser } from '../../utils/peer-utils' import { assertIsUpdatesGroup } from '../../utils/updates-utils' import { resolvePeerMany } from '../users/resolve-peer-many' -/** - * Delete a single contact from your Telegram contacts list - * - * Returns deleted contact's profile or `null` in case - * that user was not in your contacts list - * - * @param userId User ID, username or phone number - */ -export async function deleteContacts(client: BaseTelegramClient, userId: InputPeerLike): Promise - /** * Delete one or more contacts from your Telegram contacts list * @@ -23,20 +13,13 @@ export async function deleteContacts(client: BaseTelegramClient, userId: InputPe * * @param userIds User IDs, usernames or phone numbers */ -export async function deleteContacts(client: BaseTelegramClient, userIds: InputPeerLike[]): Promise +export async function deleteContacts(client: BaseTelegramClient, userIds: MaybeArray): Promise { + if (!Array.isArray(userIds)) userIds = [userIds] -/** @internal */ -export async function deleteContacts( - client: BaseTelegramClient, - userIds: MaybeArray, -): Promise | null> { - const single = !Array.isArray(userIds) - if (single) userIds = [userIds as InputPeerLike] + const inputPeers = await resolvePeerMany(client, userIds, normalizeToInputUser) - const inputPeers = await resolvePeerMany(client, userIds as InputPeerLike[], normalizeToInputUser) - - if (single && !inputPeers.length) { - throw new MtInvalidPeerTypeError((userIds as InputPeerLike[])[0], 'user') + if (!inputPeers.length) { + throw new MtInvalidPeerTypeError('all provided ids', 'user') } const res = await client.call({ @@ -46,11 +29,7 @@ export async function deleteContacts( assertIsUpdatesGroup('contacts.deleteContacts', res) - if (single && !res.updates.length) return null - client.network.handleUpdate(res) - const users = res.users.map((user) => new User(user)) - - return single ? users[0] : users + return res.users.map((user) => new User(user)) } diff --git a/packages/client/src/methods/dialogs/get-peer-dialogs.ts b/packages/client/src/methods/dialogs/get-peer-dialogs.ts index 97eecd56..36634cb4 100644 --- a/packages/client/src/methods/dialogs/get-peer-dialogs.ts +++ b/packages/client/src/methods/dialogs/get-peer-dialogs.ts @@ -9,25 +9,12 @@ import { resolvePeerMany } from '../users/resolve-peer-many' * * @param peers Peers for which to fetch dialogs. */ -export async function getPeerDialogs(client: BaseTelegramClient, peers: InputPeerLike): Promise -/** - * Get dialogs with certain peers. - * - * @param peers Peers for which to fetch dialogs. - */ -export async function getPeerDialogs(client: BaseTelegramClient, peers: InputPeerLike[]): Promise - -/** @internal */ -export async function getPeerDialogs( - client: BaseTelegramClient, - peers: MaybeArray, -): Promise> { - const isSingle = !Array.isArray(peers) - if (isSingle) peers = [peers as InputPeerLike] +export async function getPeerDialogs(client: BaseTelegramClient, peers: MaybeArray): Promise { + if (!Array.isArray(peers)) peers = [peers] const res = await client.call({ _: 'messages.getPeerDialogs', - peers: await resolvePeerMany(client, peers as InputPeerLike[]).then((peers) => + peers: await resolvePeerMany(client, peers).then((peers) => peers.map((it) => ({ _: 'inputDialogPeer', peer: it, @@ -35,7 +22,5 @@ export async function getPeerDialogs( ), }) - const dialogs = Dialog.parseTlDialogs(res) - - return isSingle ? dialogs[0] : dialogs + return Dialog.parseTlDialogs(res) } 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 e0528288..29eec967 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 @@ -4,28 +4,6 @@ import { ForumTopic, InputPeerLike } from '../../types' import { normalizeToInputChannel } from '../../utils' import { resolvePeer } from '../users/resolve-peer' -/** - * Get a single forum topic by its ID - * - * @param chatId Chat ID or username - */ -export async function getForumTopicsById( - client: BaseTelegramClient, - chatId: InputPeerLike, - ids: number, -): Promise - -/** - * Get forum topics by their IDs - * - * @param chatId Chat ID or username - */ -export async function getForumTopicsById( - client: BaseTelegramClient, - chatId: InputPeerLike, - ids: number[], -): Promise - /** * Get forum topics by their IDs * @@ -35,17 +13,14 @@ export async function getForumTopicsById( client: BaseTelegramClient, chatId: InputPeerLike, ids: MaybeArray, -): Promise> { - const single = !Array.isArray(ids) - if (single) ids = [ids as number] +): Promise { + if (!Array.isArray(ids)) ids = [ids] const res = await client.call({ _: 'channels.getForumTopicsByID', channel: normalizeToInputChannel(await resolvePeer(client, chatId)), - topics: ids as number[], + topics: ids, }) - const topics = ForumTopic.parseTlForumTopics(res) - - return single ? topics[0] : topics + return ForumTopic.parseTlForumTopics(res) } diff --git a/packages/client/src/methods/users/get-users.ts b/packages/client/src/methods/users/get-users.ts index faaeb63d..283543fe 100644 --- a/packages/client/src/methods/users/get-users.ts +++ b/packages/client/src/methods/users/get-users.ts @@ -4,13 +4,6 @@ import { InputPeerLike, User } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' import { resolvePeerMany } from './resolve-peer-many' -/** - * Get information about a single user. - * - * @param id User's identifier. Can be ID, username, phone number, `"me"` or `"self"` or TL object - */ -export async function getUsers(client: BaseTelegramClient, id: InputPeerLike): Promise - /** * Get information about multiple users. * You can retrieve up to 200 users at once. @@ -19,21 +12,16 @@ export async function getUsers(client: BaseTelegramClient, id: InputPeerLike): P * * @param ids Users' identifiers. Can be ID, username, phone number, `"me"`, `"self"` or TL object */ -export async function getUsers(client: BaseTelegramClient, ids: InputPeerLike[]): Promise - -/** @internal */ -export async function getUsers(client: BaseTelegramClient, ids: MaybeArray): Promise> { +export async function getUsers(client: BaseTelegramClient, ids: MaybeArray): Promise { const isArray = Array.isArray(ids) if (!isArray) ids = [ids as InputPeerLike] const inputPeers = await resolvePeerMany(client, ids as InputPeerLike[], normalizeToInputUser) - let res = await client.call({ + const res = await client.call({ _: 'users.getUsers', id: inputPeers, }) - res = res.filter((it) => it._ !== 'userEmpty') - - return isArray ? res.map((it) => new User(it)) : new User(res[0]) + return res.filter((it) => it._ !== 'userEmpty').map((it) => new User(it)) } diff --git a/packages/client/src/types/conversation.ts b/packages/client/src/types/conversation.ts index 6aeb6210..08c0577c 100644 --- a/packages/client/src/types/conversation.ts +++ b/packages/client/src/types/conversation.ts @@ -153,7 +153,7 @@ export class Conversation { this._inputPeer = await resolvePeer(this.client, this.chat) this._chatId = getMarkedPeerId(this._inputPeer) - const dialog = await getPeerDialogs(this.client, this._inputPeer) + const [dialog] = await getPeerDialogs(this.client, this._inputPeer) const lastMessage = dialog.lastMessage if (lastMessage) { @@ -515,7 +515,7 @@ export class Conversation { } // check if the message is already read - const dialog = await getPeerDialogs(this.client, this._inputPeer) + const [dialog] = await getPeerDialogs(this.client, this._inputPeer) if (dialog.lastRead >= msgId) return const promise = createControllablePromise()