feat(client): unpinAllMessages method

This commit is contained in:
teidesu 2021-05-12 22:18:08 +03:00
parent 79a8962284
commit 4f40571455
3 changed files with 37 additions and 1 deletions

View file

@ -95,6 +95,7 @@ import { sendMedia } from './methods/messages/send-media'
import { sendText } from './methods/messages/send-text'
import { sendTyping } from './methods/messages/send-typing'
import { sendVote } from './methods/messages/send-vote'
import { unpinAllMessages } from './methods/messages/unpin-all-messages'
import { unpinMessage } from './methods/messages/unpin-message'
import { initTakeoutSession } from './methods/misc/init-takeout-session'
import {
@ -2313,6 +2314,12 @@ export interface TelegramClient extends BaseTelegramClient {
message: number,
options: null | MaybeArray<number | Buffer>
): Promise<Poll>
/**
* Unpin all pinned messages in a chat.
*
* @param chatId Chat or user ID
*/
unpinAllMessages(chatId: InputPeerLike): Promise<void>
/**
* Unpin a message in a group, supergroup, channel or PM.
*
@ -2937,6 +2944,7 @@ export class TelegramClient extends BaseTelegramClient {
sendText = sendText
sendTyping = sendTyping
sendVote = sendVote
unpinAllMessages = unpinAllMessages
unpinMessage = unpinMessage
initTakeoutSession = initTakeoutSession
registerParseMode = registerParseMode

View file

@ -31,7 +31,7 @@ export async function deleteMessages(
channel,
id: ids
})
upd = createDummyUpdate(res.pts, res.ptsCount, (channel as tl.RawInputChannel).channelId)
upd = createDummyUpdate(res.pts, res.ptsCount, peer.channelId)
} else {
const res = await this.call({
_: 'messages.deleteMessages',

View file

@ -0,0 +1,28 @@
import { TelegramClient } from '../../client'
import { InputPeerLike } from '../../types'
import { isInputPeerChannel, normalizeToInputPeer } from '../../utils/peer-utils'
import { createDummyUpdate } from '../../utils/updates-utils'
/**
* Unpin all pinned messages in a chat.
*
* @param chatId Chat or user ID
* @internal
*/
export async function unpinAllMessages(
this: TelegramClient,
chatId: InputPeerLike
): Promise<void> {
const peer = normalizeToInputPeer(await this.resolvePeer(chatId))
const res = await this.call({
_: 'messages.unpinAllMessages',
peer
})
if (isInputPeerChannel(peer)) {
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))
} else {
createDummyUpdate(res.pts, res.ptsCount)
}
}