feat(client): getDiscussionMessage method
This commit is contained in:
parent
b03e2f4f0b
commit
cc8c974e23
3 changed files with 77 additions and 3 deletions
|
@ -98,7 +98,10 @@ import { editInlineMessage } from './methods/messages/edit-inline-message'
|
||||||
import { editMessage } from './methods/messages/edit-message'
|
import { editMessage } from './methods/messages/edit-message'
|
||||||
import { _findMessageInUpdate } from './methods/messages/find-in-update'
|
import { _findMessageInUpdate } from './methods/messages/find-in-update'
|
||||||
import { forwardMessages } from './methods/messages/forward-messages'
|
import { forwardMessages } from './methods/messages/forward-messages'
|
||||||
import { _getDiscussionMessage } from './methods/messages/get-discussion-message'
|
import {
|
||||||
|
_getDiscussionMessage,
|
||||||
|
getDiscussionMessage,
|
||||||
|
} from './methods/messages/get-discussion-message'
|
||||||
import { getHistory } from './methods/messages/get-history'
|
import { getHistory } from './methods/messages/get-history'
|
||||||
import { getMessageGroup } from './methods/messages/get-message-group'
|
import { getMessageGroup } from './methods/messages/get-message-group'
|
||||||
import { getMessagesUnsafe } from './methods/messages/get-messages-unsafe'
|
import { getMessagesUnsafe } from './methods/messages/get-messages-unsafe'
|
||||||
|
@ -680,7 +683,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
* Whether the results should be displayed as a gallery instead
|
* Whether the results should be displayed as a gallery instead
|
||||||
* of a vertical list. Only applicable to some media types.
|
* of a vertical list. Only applicable to some media types.
|
||||||
*
|
*
|
||||||
* Defaults to `false`
|
* Defaults to `true`
|
||||||
*/
|
*/
|
||||||
gallery?: boolean
|
gallery?: boolean
|
||||||
|
|
||||||
|
@ -2201,6 +2204,25 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
clearDraft?: boolean
|
clearDraft?: boolean
|
||||||
}
|
}
|
||||||
): Promise<MaybeArray<Message>>
|
): Promise<MaybeArray<Message>>
|
||||||
|
// public version of the same method because why not
|
||||||
|
/**
|
||||||
|
* Get discussion message for some channel post.
|
||||||
|
*
|
||||||
|
* Returns `null` if the post does not have a discussion
|
||||||
|
* message.
|
||||||
|
*
|
||||||
|
* This method might throw `FLOOD_WAIT_X` error in case
|
||||||
|
* the discussion message was not *yet* created. Error
|
||||||
|
* is usually handled by the client, but if you disabled that,
|
||||||
|
* you'll need to handle it manually.
|
||||||
|
*
|
||||||
|
* @param peer Channel where the post was found
|
||||||
|
* @param message ID of the channel post
|
||||||
|
*/
|
||||||
|
getDiscussionMessage(
|
||||||
|
peer: InputPeerLike,
|
||||||
|
message: number
|
||||||
|
): Promise<Message | null>
|
||||||
/**
|
/**
|
||||||
* Retrieve a chunk of the chat history.
|
* Retrieve a chunk of the chat history.
|
||||||
*
|
*
|
||||||
|
@ -3588,6 +3610,7 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
protected _findMessageInUpdate = _findMessageInUpdate
|
protected _findMessageInUpdate = _findMessageInUpdate
|
||||||
forwardMessages = forwardMessages
|
forwardMessages = forwardMessages
|
||||||
protected _getDiscussionMessage = _getDiscussionMessage
|
protected _getDiscussionMessage = _getDiscussionMessage
|
||||||
|
getDiscussionMessage = getDiscussionMessage
|
||||||
getHistory = getHistory
|
getHistory = getHistory
|
||||||
getMessageGroup = getMessageGroup
|
getMessageGroup = getMessageGroup
|
||||||
getMessagesUnsafe = getMessagesUnsafe
|
getMessagesUnsafe = getMessagesUnsafe
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike, Message } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export async function _getDiscussionMessage(
|
export async function _getDiscussionMessage(
|
||||||
|
@ -34,3 +35,43 @@ export async function _getDiscussionMessage(
|
||||||
msg.id,
|
msg.id,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public version of the same method because why not
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get discussion message for some channel post.
|
||||||
|
*
|
||||||
|
* Returns `null` if the post does not have a discussion
|
||||||
|
* message.
|
||||||
|
*
|
||||||
|
* This method might throw `FLOOD_WAIT_X` error in case
|
||||||
|
* the discussion message was not *yet* created. Error
|
||||||
|
* is usually handled by the client, but if you disabled that,
|
||||||
|
* you'll need to handle it manually.
|
||||||
|
*
|
||||||
|
* @param peer Channel where the post was found
|
||||||
|
* @param message ID of the channel post
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function getDiscussionMessage(
|
||||||
|
this: TelegramClient,
|
||||||
|
peer: InputPeerLike,
|
||||||
|
message: number
|
||||||
|
): Promise<Message | null> {
|
||||||
|
const inputPeer = await this.resolvePeer(peer)
|
||||||
|
|
||||||
|
const res = await this.call({
|
||||||
|
_: 'messages.getDiscussionMessage',
|
||||||
|
peer: inputPeer,
|
||||||
|
msgId: message,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!res.messages.length || res.messages[0]._ === 'messageEmpty')
|
||||||
|
// no discussion message (i guess?), return the same msg
|
||||||
|
return null
|
||||||
|
|
||||||
|
const msg = res.messages[0]
|
||||||
|
const { users, chats } = createUsersChatsIndex(res)
|
||||||
|
|
||||||
|
return new Message(this, msg, users, chats)
|
||||||
|
}
|
||||||
|
|
|
@ -870,6 +870,16 @@ export class Message {
|
||||||
return this.client.getMessageGroup(this.chat.inputPeer, this.raw.id)
|
return this.client.getMessageGroup(this.chat.inputPeer, this.raw.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get discussion message for some channel post.
|
||||||
|
*
|
||||||
|
* Returns `null` if the post does not have a discussion
|
||||||
|
* message.
|
||||||
|
*/
|
||||||
|
async getDiscussionMessage(): Promise<Message | null> {
|
||||||
|
return this.client.getDiscussionMessage(this.chat.inputPeer, this.raw.id)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read history in the chat up until this message
|
* Read history in the chat up until this message
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue