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