fix(client): archiveChats & unarchiveChats and respective bound methods for Chat

This commit is contained in:
teidesu 2021-04-10 20:30:28 +03:00
parent d592e55294
commit 8acad15d7c
4 changed files with 98 additions and 0 deletions

View file

@ -14,10 +14,12 @@ import { signIn } from './methods/auth/sign-in'
import { signUp } from './methods/auth/sign-up'
import { start } from './methods/auth/start'
import { addChatMembers } from './methods/chats/add-chat-members'
import { archiveChats } from './methods/chats/archive-chats'
import { getChatPreview } from './methods/chats/get-chat-preview'
import { getChat } from './methods/chats/get-chat'
import { getFullChat } from './methods/chats/get-full-chat'
import { joinChat } from './methods/chats/join-chat'
import { unarchiveChats } from './methods/chats/unarchive-chats'
import { downloadAsBuffer } from './methods/files/download-buffer'
import { downloadToFile } from './methods/files/download-file'
import { downloadAsIterable } from './methods/files/download-iterable'
@ -342,6 +344,14 @@ export class TelegramClient extends BaseTelegramClient {
): Promise<void> {
return addChatMembers.apply(this, arguments)
}
/**
* Archive one or more chats
*
* @param chats Chat ID(s), username(s), phone number(s), `"me"` or `"self"`
*/
archiveChats(chats: MaybeArray<InputPeerLike>): Promise<void> {
return archiveChats.apply(this, arguments)
}
/**
* Get preview information about a private chat.
*
@ -386,6 +396,14 @@ export class TelegramClient extends BaseTelegramClient {
joinChat(chatId: InputPeerLike): Promise<Chat> {
return joinChat.apply(this, arguments)
}
/**
* Unarchive one or more chats
*
* @param chats Chat ID(s), username(s), phone number(s), `"me"` or `"self"`
*/
unarchiveChats(chats: MaybeArray<InputPeerLike>): Promise<void> {
return unarchiveChats.apply(this, arguments)
}
/**
* Download a file and return its contents as a Buffer.
*

View file

@ -0,0 +1,33 @@
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
*
* @param chats Chat ID(s), username(s), phone number(s), `"me"` or `"self"`
* @internal
*/
export async function archiveChats(
this: TelegramClient,
chats: MaybeArray<InputPeerLike>
): Promise<void> {
if (!Array.isArray(chats)) chats = [chats]
const folderPeers: tl.TypeInputFolderPeer[] = []
for (const chat of chats) {
folderPeers.push({
_: 'inputFolderPeer',
peer: normalizeToInputPeer(await this.resolvePeer(chat)),
folderId: 1
})
}
await this.call({
_: 'folders.editPeerFolders',
folderPeers
})
}

View file

@ -0,0 +1,33 @@
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
*
* @param chats Chat ID(s), username(s), phone number(s), `"me"` or `"self"`
* @internal
*/
export async function unarchiveChats(
this: TelegramClient,
chats: MaybeArray<InputPeerLike>
): Promise<void> {
if (!Array.isArray(chats)) chats = [chats]
const folderPeers: tl.TypeInputFolderPeer[] = []
for (const chat of chats) {
folderPeers.push({
_: 'inputFolderPeer',
peer: normalizeToInputPeer(await this.resolvePeer(chat)),
folderId: 0
})
}
await this.call({
_: 'folders.editPeerFolders',
folderPeers
})
}

View file

@ -441,6 +441,20 @@ export class Chat {
async addMembers(users: MaybeArray<InputPeerLike>, forwardCount?: number): Promise<void> {
return this.client.addChatMembers(this.inputPeer, users, forwardCount)
}
/**
* Archive this chat
*/
async archive(): Promise<void> {
return this.client.archiveChats(this.inputPeer)
}
/**
* Unarchive this chat
*/
async unarchive(): Promise<void> {
return this.client.unarchiveChats(this.inputPeer)
}
}
makeInspectable(Chat)