chore: remove remaining MaybeArray flex
This commit is contained in:
parent
3e5b2af7c0
commit
6629d91274
6 changed files with 30 additions and 126 deletions
|
@ -1898,24 +1898,17 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*/
|
||||
sharePhone?: boolean
|
||||
}): Promise<User>
|
||||
/**
|
||||
* 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<User | null>
|
||||
/**
|
||||
* 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<User[]>
|
||||
deleteContacts(userIds: MaybeArray<InputPeerLike>): Promise<User[]>
|
||||
/**
|
||||
* 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<Dialog>
|
||||
/**
|
||||
* Get dialogs with certain peers.
|
||||
* **Available**: 👤 users only
|
||||
*
|
||||
* @param peers Peers for which to fetch dialogs.
|
||||
*/
|
||||
getPeerDialogs(peers: InputPeerLike[]): Promise<Dialog[]>
|
||||
getPeerDialogs(peers: MaybeArray<InputPeerLike>): Promise<Dialog[]>
|
||||
/**
|
||||
* Iterate over dialogs.
|
||||
*
|
||||
|
@ -2380,18 +2369,14 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*/
|
||||
shouldDispatch?: true
|
||||
}): Promise<Message>
|
||||
/**
|
||||
* Get a single forum topic by its ID
|
||||
*
|
||||
* @param chatId Chat ID or username
|
||||
*/
|
||||
getForumTopicsById(chatId: InputPeerLike, ids: number): Promise<ForumTopic>
|
||||
/**
|
||||
* Get forum topics by their IDs
|
||||
*
|
||||
* **Available**: ✅ both users and bots
|
||||
*
|
||||
* @param chatId Chat ID or username
|
||||
*/
|
||||
getForumTopicsById(chatId: InputPeerLike, ids: number[]): Promise<ForumTopic[]>
|
||||
getForumTopicsById(chatId: InputPeerLike, ids: MaybeArray<number>): Promise<ForumTopic[]>
|
||||
/**
|
||||
* Get forum topics
|
||||
*
|
||||
|
@ -5080,21 +5065,17 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
limit?: number
|
||||
},
|
||||
): Promise<ArrayPaginated<Photo, number>>
|
||||
/**
|
||||
* 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<User>
|
||||
/**
|
||||
* 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<User[]>
|
||||
getUsers(ids: MaybeArray<InputPeerLike>): Promise<User[]>
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -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<User | null>
|
||||
|
||||
/**
|
||||
* 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<User[]>
|
||||
export async function deleteContacts(client: BaseTelegramClient, userIds: MaybeArray<InputPeerLike>): Promise<User[]> {
|
||||
if (!Array.isArray(userIds)) userIds = [userIds]
|
||||
|
||||
/** @internal */
|
||||
export async function deleteContacts(
|
||||
client: BaseTelegramClient,
|
||||
userIds: MaybeArray<InputPeerLike>,
|
||||
): Promise<MaybeArray<User> | 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))
|
||||
}
|
||||
|
|
|
@ -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<Dialog>
|
||||
/**
|
||||
* Get dialogs with certain peers.
|
||||
*
|
||||
* @param peers Peers for which to fetch dialogs.
|
||||
*/
|
||||
export async function getPeerDialogs(client: BaseTelegramClient, peers: InputPeerLike[]): Promise<Dialog[]>
|
||||
|
||||
/** @internal */
|
||||
export async function getPeerDialogs(
|
||||
client: BaseTelegramClient,
|
||||
peers: MaybeArray<InputPeerLike>,
|
||||
): Promise<MaybeArray<Dialog>> {
|
||||
const isSingle = !Array.isArray(peers)
|
||||
if (isSingle) peers = [peers as InputPeerLike]
|
||||
export async function getPeerDialogs(client: BaseTelegramClient, peers: MaybeArray<InputPeerLike>): Promise<Dialog[]> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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<ForumTopic>
|
||||
|
||||
/**
|
||||
* Get forum topics by their IDs
|
||||
*
|
||||
* @param chatId Chat ID or username
|
||||
*/
|
||||
export async function getForumTopicsById(
|
||||
client: BaseTelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
ids: number[],
|
||||
): Promise<ForumTopic[]>
|
||||
|
||||
/**
|
||||
* Get forum topics by their IDs
|
||||
*
|
||||
|
@ -35,17 +13,14 @@ export async function getForumTopicsById(
|
|||
client: BaseTelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
ids: MaybeArray<number>,
|
||||
): Promise<MaybeArray<ForumTopic>> {
|
||||
const single = !Array.isArray(ids)
|
||||
if (single) ids = [ids as number]
|
||||
): Promise<ForumTopic[]> {
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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<User>
|
||||
|
||||
/**
|
||||
* 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<User[]>
|
||||
|
||||
/** @internal */
|
||||
export async function getUsers(client: BaseTelegramClient, ids: MaybeArray<InputPeerLike>): Promise<MaybeArray<User>> {
|
||||
export async function getUsers(client: BaseTelegramClient, ids: MaybeArray<InputPeerLike>): Promise<User[]> {
|
||||
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))
|
||||
}
|
||||
|
|
|
@ -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<void>()
|
||||
|
|
Loading…
Reference in a new issue