feat(client): updated to layer 143
also fixed some minor bugs
This commit is contained in:
parent
a864eacfd4
commit
2c3529870a
23 changed files with 117 additions and 45 deletions
|
@ -14,7 +14,7 @@
|
|||
"dependencies": {
|
||||
"@types/long": "^4.0.1",
|
||||
"@types/node": "^15.12.1",
|
||||
"@mtcute/tl": "workspace:142.1.0",
|
||||
"@mtcute/tl": "workspace:143.0.0",
|
||||
"@mtcute/core": "workspace:^1.0.0",
|
||||
"@mtcute/file-id": "workspace:^1.0.0",
|
||||
"eager-async-pool": "^1.0.0",
|
||||
|
|
|
@ -142,6 +142,7 @@ import { getDialogs } from './methods/dialogs/get-dialogs'
|
|||
import { getFolders } from './methods/dialogs/get-folders'
|
||||
import { getPeerDialogs } from './methods/dialogs/get-peer-dialogs'
|
||||
import { _parseDialogs } from './methods/dialogs/parse-dialogs'
|
||||
import { setFoldersOrder } from './methods/dialogs/set-folders'
|
||||
import { downloadAsBuffer } from './methods/files/download-buffer'
|
||||
import { downloadToFile } from './methods/files/download-file'
|
||||
import { downloadAsIterable } from './methods/files/download-iterable'
|
||||
|
@ -1743,7 +1744,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
/**
|
||||
* Get list of folders.
|
||||
*/
|
||||
getFolders(): Promise<tl.RawDialogFilter[]>
|
||||
getFolders(): Promise<tl.TypeDialogFilter[]>
|
||||
/**
|
||||
* Get dialogs with certain peers.
|
||||
*
|
||||
|
@ -1756,6 +1757,13 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
* @param peers Peers for which to fetch dialogs.
|
||||
*/
|
||||
getPeerDialogs(peers: InputPeerLike[]): Promise<Dialog[]>
|
||||
/**
|
||||
* Reorder folders
|
||||
*
|
||||
* Order is folder's ID (0 = default folder)
|
||||
*
|
||||
*/
|
||||
setFoldersOrder(order: number[]): Promise<void>
|
||||
/**
|
||||
* Download a file and return its contents as a Buffer.
|
||||
*
|
||||
|
@ -3949,6 +3957,7 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
getFolders = getFolders
|
||||
getPeerDialogs = getPeerDialogs
|
||||
protected _parseDialogs = _parseDialogs
|
||||
setFoldersOrder = setFoldersOrder
|
||||
downloadAsBuffer = downloadAsBuffer
|
||||
downloadToFile = downloadToFile
|
||||
downloadAsIterable = downloadAsIterable
|
||||
|
|
|
@ -23,9 +23,9 @@ export async function createFolder(
|
|||
|
||||
// determine next id by finding max id
|
||||
// thanks durov for awesome api
|
||||
let max = 0
|
||||
let max = 1
|
||||
old.forEach((it) => {
|
||||
if (it.id > max) max = it.id
|
||||
if (it._ === 'dialogFilter' && it.id > max) max = it.id
|
||||
})
|
||||
id = max + 1
|
||||
}
|
||||
|
|
|
@ -19,13 +19,16 @@ export async function editFolder(
|
|||
folder: tl.RawDialogFilter | number | string,
|
||||
modification: Partial<Omit<tl.RawDialogFilter, 'id' | '_'>>
|
||||
): Promise<tl.RawDialogFilter> {
|
||||
if (folder === 0) {
|
||||
throw new MtArgumentError('Cannot modify default folder')
|
||||
}
|
||||
if (typeof folder === 'number' || typeof folder === 'string') {
|
||||
const old = await this.getFolders()
|
||||
const found = old.find((it) => it.id === folder || it.title === folder)
|
||||
const found = old.find((it) => it._ === 'dialogFilter' && (it.id === folder || it.title === folder))
|
||||
if (!found)
|
||||
throw new MtArgumentError(`Could not find a folder ${folder}`)
|
||||
|
||||
folder = found
|
||||
folder = found as tl.RawDialogFilter
|
||||
}
|
||||
|
||||
const filter: tl.RawDialogFilter = {
|
||||
|
|
|
@ -27,11 +27,12 @@ export async function findFolder(
|
|||
|
||||
return (
|
||||
folders.find((it) => {
|
||||
if (it._ === 'dialogFilterDefault') return false
|
||||
if (params.id && it.id !== params.id) return false
|
||||
if (params.title && it.title !== params.title) return false
|
||||
if (params.emoji && it.emoticon !== params.emoji) return false
|
||||
|
||||
return true
|
||||
}) ?? null
|
||||
}) as tl.RawDialogFilter ?? null
|
||||
)
|
||||
}
|
||||
|
|
|
@ -120,21 +120,25 @@ export async function* getDialogs(
|
|||
if (!params) params = {}
|
||||
|
||||
// fetch folder if needed
|
||||
let filters: tl.RawDialogFilter | undefined
|
||||
let filters: tl.TypeDialogFilter | undefined
|
||||
if (
|
||||
typeof params.folder === 'string' ||
|
||||
typeof params.folder === 'number'
|
||||
) {
|
||||
const folders = await this.getFolders()
|
||||
const found = folders.find(
|
||||
(it) => it.id === params!.folder || it.title === params!.folder
|
||||
)
|
||||
const found = folders.find((it) => {
|
||||
if (it._ === 'dialogFilterDefault' ) {
|
||||
return params!.folder === 0
|
||||
}
|
||||
|
||||
return it.id === params!.folder || it.title === params!.folder
|
||||
})
|
||||
if (!found)
|
||||
throw new MtArgumentError(
|
||||
`Could not find folder ${params.folder}`
|
||||
)
|
||||
|
||||
filters = found
|
||||
filters = found as tl.RawDialogFilter
|
||||
} else {
|
||||
filters = params.folder
|
||||
}
|
||||
|
@ -147,19 +151,13 @@ export async function* getDialogs(
|
|||
}
|
||||
} else {
|
||||
filters = {
|
||||
_: 'dialogFilter',
|
||||
id: 0,
|
||||
title: '',
|
||||
pinnedPeers: [],
|
||||
includePeers: [],
|
||||
excludePeers: [],
|
||||
...params.filter,
|
||||
_: 'dialogFilterDefault'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fetchPinnedDialogsFromFolder = async (): Promise<tl.messages.RawPeerDialogs | null> => {
|
||||
if (!filters || !filters.pinnedPeers.length) return null
|
||||
if (!filters || filters._ === 'dialogFilterDefault' || !filters.pinnedPeers.length) return null
|
||||
const res = await this.call({
|
||||
_: 'messages.getPeerDialogs',
|
||||
peers: filters.pinnedPeers.map((peer) => ({
|
||||
|
@ -180,7 +178,7 @@ export async function* getDialogs(
|
|||
let archived = params.archived ?? 'exclude'
|
||||
|
||||
if (filters) {
|
||||
archived = filters.excludeArchived ? 'exclude' : 'keep'
|
||||
archived = filters._ !== 'dialogFilterDefault' && filters.excludeArchived ? 'exclude' : 'keep'
|
||||
}
|
||||
|
||||
if (pinned === 'only') {
|
||||
|
@ -205,7 +203,7 @@ export async function* getDialogs(
|
|||
let offsetDate = normalizeDate(params.offsetDate) ?? 0
|
||||
let offsetPeer = params.offsetPeer ?? { _: 'inputPeerEmpty' }
|
||||
|
||||
if (filters && filters.pinnedPeers.length && pinned === 'include') {
|
||||
if (filters && filters._ !== 'dialogFilterDefault' && filters.pinnedPeers.length && pinned === 'include') {
|
||||
const res = await fetchPinnedDialogsFromFolder()
|
||||
if (res) {
|
||||
const dialogs = this._parseDialogs(res)
|
||||
|
|
|
@ -7,7 +7,7 @@ import { tl } from '@mtcute/tl'
|
|||
*/
|
||||
export async function getFolders(
|
||||
this: TelegramClient
|
||||
): Promise<tl.RawDialogFilter[]> {
|
||||
): Promise<tl.TypeDialogFilter[]> {
|
||||
return this.call({
|
||||
_: 'messages.getDialogFilters',
|
||||
})
|
||||
|
|
19
packages/client/src/methods/dialogs/set-folders.ts
Normal file
19
packages/client/src/methods/dialogs/set-folders.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
|
||||
/**
|
||||
* Reorder folders
|
||||
*
|
||||
* Order is folder's ID (0 = default folder)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export async function setFoldersOrder(
|
||||
this: TelegramClient,
|
||||
order: number[]
|
||||
): Promise<void> {
|
||||
await this.call({
|
||||
_: 'messages.updateDialogFiltersOrder',
|
||||
order
|
||||
})
|
||||
}
|
|
@ -2,9 +2,9 @@ import { TelegramClient } from '../../client'
|
|||
import {
|
||||
ChatInviteLink,
|
||||
InputPeerLike,
|
||||
MtInvalidPeerTypeError,
|
||||
PeersIndex,
|
||||
} from '../../types'
|
||||
MtInvalidPeerTypeError, MtTypeAssertionError,
|
||||
PeersIndex
|
||||
} from "../../types";
|
||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||
import { tl } from '@mtcute/tl'
|
||||
|
||||
|
@ -75,6 +75,9 @@ export async function* getInviteLinks(
|
|||
const peers = PeersIndex.from(res)
|
||||
|
||||
const last = res.invites[res.invites.length - 1]
|
||||
if (last._ === 'chatInvitePublicJoinRequests') {
|
||||
throw new MtTypeAssertionError('getInviteLinks', 'chatInviteExported', last._)
|
||||
}
|
||||
offsetDate = last.date
|
||||
offsetLink = last.link
|
||||
|
||||
|
|
|
@ -23,7 +23,14 @@ export async function getPrimaryInviteLink(
|
|||
revoked: false,
|
||||
})
|
||||
|
||||
if (!res.invites[0]?.permanent)
|
||||
if (res.invites[0]?._ !== 'chatInviteExported')
|
||||
throw new MtTypeAssertionError(
|
||||
'messages.getExportedChatInvites (@ .invites[0])',
|
||||
'chatInviteExported',
|
||||
res.invites[0]?._
|
||||
)
|
||||
|
||||
if (!res.invites[0].permanent)
|
||||
throw new MtTypeAssertionError(
|
||||
'messages.getExportedChatInvites (@ .invites[0].permanent)',
|
||||
'true',
|
||||
|
|
|
@ -102,8 +102,13 @@ export class Conversation {
|
|||
this._chatId = getMarkedPeerId(this._inputPeer)
|
||||
|
||||
const dialog = await this.client.getPeerDialogs(this._inputPeer)
|
||||
this._lastMessage = this._lastReceivedMessage = dialog.lastMessage.id
|
||||
|
||||
try {
|
||||
this._lastMessage = this._lastReceivedMessage = dialog.lastMessage.id
|
||||
} catch (e) {
|
||||
if (e instanceof tl.errors.MessageNotFoundError) {
|
||||
this._lastMessage = this._lastReceivedMessage = 0
|
||||
} else throw e
|
||||
}
|
||||
this.client.on('new_message', this._onNewMessage)
|
||||
this.client.on('edit_message', this._onEditMessage)
|
||||
this.client.on('history_read', this._onHistoryRead)
|
||||
|
|
|
@ -49,9 +49,13 @@ export class Dialog {
|
|||
* @param excludePinned Whether to exclude pinned folders
|
||||
*/
|
||||
static filterFolder(
|
||||
folder: tl.RawDialogFilter,
|
||||
folder: tl.TypeDialogFilter,
|
||||
excludePinned = true
|
||||
): (val: Dialog) => boolean {
|
||||
if (folder._ === 'dialogFilterDefault') {
|
||||
return () => true
|
||||
}
|
||||
|
||||
const pinned: Record<number, true> = {}
|
||||
const include: Record<number, true> = {}
|
||||
const exclude: Record<number, true> = {}
|
||||
|
@ -171,8 +175,6 @@ export class Dialog {
|
|||
private _lastMessage?: Message
|
||||
/**
|
||||
* The latest message sent in this chat
|
||||
*
|
||||
* Throws `MessageNotFoundError` if it was not found
|
||||
*/
|
||||
get lastMessage(): Message {
|
||||
if (!this._lastMessage) {
|
||||
|
|
|
@ -3,6 +3,7 @@ import { TelegramClient } from '../../client'
|
|||
import { tl } from '@mtcute/tl'
|
||||
import { User } from './user'
|
||||
import { PeersIndex } from './index'
|
||||
import { MtTypeAssertionError } from "../errors";
|
||||
|
||||
export namespace ChatInviteLink {
|
||||
export interface JoinedMember {
|
||||
|
@ -36,11 +37,18 @@ export namespace ChatInviteLink {
|
|||
* An invite link
|
||||
*/
|
||||
export class ChatInviteLink {
|
||||
raw: tl.RawChatInviteExported
|
||||
|
||||
constructor(
|
||||
readonly client: TelegramClient,
|
||||
readonly raw: tl.RawChatInviteExported,
|
||||
raw: tl.TypeExportedChatInvite,
|
||||
readonly _peers?: PeersIndex
|
||||
) {}
|
||||
) {
|
||||
if (raw._ === 'chatInvitePublicJoinRequests') {
|
||||
throw new MtTypeAssertionError('ChatInviteLink', 'chatInviteExported', raw._)
|
||||
}
|
||||
this.raw = raw
|
||||
}
|
||||
|
||||
/**
|
||||
* The invite link as a `t.me/joinchat/` string.
|
||||
|
|
|
@ -319,9 +319,15 @@ export class Chat {
|
|||
* Returned only in {@link TelegramClient.getFullChat}
|
||||
*/
|
||||
get inviteLink(): string | null {
|
||||
return this.fullPeer && this.fullPeer._ !== 'userFull'
|
||||
? this.fullPeer.exportedInvite?.link ?? null
|
||||
: null
|
||||
if (this.fullPeer && this.fullPeer._ !== 'userFull') {
|
||||
switch (this.fullPeer.exportedInvite?._) {
|
||||
case 'chatInvitePublicJoinRequests':
|
||||
return null
|
||||
case 'chatInviteExported':
|
||||
return this.fullPeer.exportedInvite.link
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"dependencies": {
|
||||
"@types/node": "^15.12.1",
|
||||
"@types/events": "^3.0.0",
|
||||
"@mtcute/tl": "workspace:142.1.0",
|
||||
"@mtcute/tl": "workspace:143.0.0",
|
||||
"@mtcute/tl-runtime": "workspace:^1.0.0",
|
||||
"big-integer": "1.6.48",
|
||||
"long": "^4.0.0",
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mtcute/tl": "workspace:142.1.0",
|
||||
"@mtcute/tl": "workspace:143.0.0",
|
||||
"@mtcute/core": "workspace:^1.0.0",
|
||||
"@mtcute/client": "workspace:^1.0.0",
|
||||
"events": "^3.2.0"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mtcute/tl": "workspace:142.1.0",
|
||||
"@mtcute/tl": "workspace:143.0.0",
|
||||
"@mtcute/tl-runtime": "workspace:^1.0.0",
|
||||
"@mtcute/core": "workspace:^1.0.0",
|
||||
"long": "^4.0.0"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"docs": "npx typedoc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mtcute/tl": "workspace:142.1.0",
|
||||
"@mtcute/tl": "workspace:143.0.0",
|
||||
"htmlparser2": "^6.0.1",
|
||||
"long": "^4.0.0"
|
||||
},
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"docs": "npx typedoc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mtcute/tl": "workspace:142.1.0",
|
||||
"@mtcute/tl": "workspace:143.0.0",
|
||||
"long": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
> TL schema and related utils used for MTCute.
|
||||
|
||||
Generated from TL layer **142** (last updated on 05.06.2022).
|
||||
Generated from TL layer **143** (last updated on 18.06.2022).
|
||||
|
||||
## About
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -7,6 +7,7 @@
|
|||
],
|
||||
"class": {
|
||||
"attachMenuBot": ["bot_id"],
|
||||
"autoDownloadSettings": ["video_size_max", "file_size_max"],
|
||||
"botInfo": ["user_id"],
|
||||
"channel": ["id"],
|
||||
"channelAdminLogEvent": ["user_id"],
|
||||
|
@ -33,9 +34,12 @@
|
|||
"chatParticipantsForbidden": ["chat_id"],
|
||||
"contact": ["user_id"],
|
||||
"contactStatus": ["user_id"],
|
||||
"document": ["size"],
|
||||
"encryptedChat": ["admin_id", "participant_id"],
|
||||
"encryptedChatRequested": ["admin_id", "participant_id"],
|
||||
"encryptedChatWaiting": ["admin_id", "participant_id"],
|
||||
"encryptedFile": ["size"],
|
||||
"fileHash": ["offset"],
|
||||
"highScore": ["user_id"],
|
||||
"importedContact": ["user_id"],
|
||||
"inputChannel": ["channel_id"],
|
||||
|
@ -80,6 +84,7 @@
|
|||
"privacyValueDisallowUsers": ["users"],
|
||||
"recentMeUrlChat": ["chat_id"],
|
||||
"recentMeUrlUser": ["user_id"],
|
||||
"secureFile": ["size"],
|
||||
"statsGroupTopAdmin": ["user_id"],
|
||||
"statsGroupTopInviter": ["user_id"],
|
||||
"statsGroupTopPoster": ["user_id"],
|
||||
|
@ -134,6 +139,7 @@
|
|||
"method": {
|
||||
"account.acceptAuthorization": ["bot_id"],
|
||||
"account.getAuthorizationForm": ["bot_id"],
|
||||
"account.initTakeoutSession": ["file_max_size"],
|
||||
"account.registerDevice": ["other_uids"],
|
||||
"account.unregisterDevice": ["other_uids"],
|
||||
"messages.addChatUser": ["chat_id"],
|
||||
|
@ -145,8 +151,13 @@
|
|||
"messages.getAllChats": ["except_ids"],
|
||||
"messages.getChats": ["id"],
|
||||
"messages.getCommonChats": ["max_id"],
|
||||
"messages.getDocumentByHash": ["size"],
|
||||
"messages.getFullChat": ["chat_id"],
|
||||
"messages.migrateChat": ["chat_id"],
|
||||
"upload.getCdnFile": ["offset"],
|
||||
"upload.getCdnFileHashes": ["offset"],
|
||||
"upload.getFile": ["offset"],
|
||||
"upload.getFileHashes": ["offset"],
|
||||
"_": "Dummy line teehee~"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@mtcute/tl",
|
||||
"version": "142.1.0",
|
||||
"version": "143.0.0",
|
||||
"description": "TL schema used for MTCute",
|
||||
"main": "index.js",
|
||||
"author": "Alisa Sireneva <me@tei.su>",
|
||||
|
|
Loading…
Reference in a new issue