feat(client): accept online
as schedule date
This commit is contained in:
parent
9ed587209c
commit
1cdb75a0a9
4 changed files with 20 additions and 13 deletions
|
@ -4,7 +4,7 @@ import { MtMessageNotFoundError } from '../../types/errors.js'
|
|||
import { Message } from '../../types/messages/message.js'
|
||||
import { TextWithEntities } from '../../types/misc/entities.js'
|
||||
import { InputPeerLike } from '../../types/peers/index.js'
|
||||
import { normalizeMessageId, toInputUser } from '../../utils/index.js'
|
||||
import { normalizeDate, normalizeMessageId, toInputUser } from '../../utils/index.js'
|
||||
import { _normalizeInputText } from '../misc/normalize-text.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { _getDiscussionMessage } from './get-discussion-message.js'
|
||||
|
@ -70,10 +70,11 @@ export interface CommonSendParams {
|
|||
* If set, the message will be scheduled to this date.
|
||||
* When passing a number, a UNIX time in ms is expected.
|
||||
*
|
||||
* You can also pass `0x7FFFFFFE`, this will send the message
|
||||
* once the peer is online
|
||||
* You can also pass `online` - this will send the message
|
||||
* once the peer is online. Note that this requires that
|
||||
* peer's online status to be visible to you.
|
||||
*/
|
||||
schedule?: Date | number
|
||||
schedule?: Date | number | 'online'
|
||||
|
||||
/**
|
||||
* Whether to clear draft after sending this message.
|
||||
|
@ -155,8 +156,17 @@ export async function _processCommonSendParameters(
|
|||
}
|
||||
}
|
||||
|
||||
let scheduleDate: number | undefined = undefined
|
||||
|
||||
if (params.schedule === 'online') {
|
||||
scheduleDate = 0x7ffffffe
|
||||
} else if (params.schedule) {
|
||||
scheduleDate = normalizeDate(params.schedule)
|
||||
}
|
||||
|
||||
return {
|
||||
peer,
|
||||
replyTo: tlReplyTo,
|
||||
scheduleDate,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import { randomLong } from '@mtcute/core/utils.js'
|
|||
import { InputMediaLike } from '../../types/media/input-media.js'
|
||||
import { Message } from '../../types/messages/message.js'
|
||||
import { InputPeerLike, PeersIndex } from '../../types/peers/index.js'
|
||||
import { normalizeDate } from '../../utils/misc-utils.js'
|
||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils.js'
|
||||
import { _normalizeInputMedia } from '../files/normalize-input-media.js'
|
||||
import { _normalizeInputText } from '../misc/normalize-text.js'
|
||||
|
@ -50,7 +49,7 @@ export async function sendMediaGroup(
|
|||
): Promise<Message[]> {
|
||||
if (!params) params = {}
|
||||
|
||||
const { peer, replyTo } = await _processCommonSendParameters(client, chatId, params)
|
||||
const { peer, replyTo, scheduleDate } = await _processCommonSendParameters(client, chatId, params)
|
||||
|
||||
const multiMedia: tl.RawInputSingleMedia[] = []
|
||||
|
||||
|
@ -99,7 +98,7 @@ export async function sendMediaGroup(
|
|||
multiMedia,
|
||||
silent: params.silent,
|
||||
replyTo,
|
||||
scheduleDate: normalizeDate(params.schedule),
|
||||
scheduleDate,
|
||||
clearDraft: params.clearDraft,
|
||||
noforwards: params.forbidForwards,
|
||||
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,
|
||||
|
|
|
@ -6,7 +6,6 @@ import { InputMediaLike } from '../../types/media/input-media.js'
|
|||
import { Message } from '../../types/messages/message.js'
|
||||
import { InputText } from '../../types/misc/entities.js'
|
||||
import { InputPeerLike } from '../../types/peers/index.js'
|
||||
import { normalizeDate } from '../../utils/misc-utils.js'
|
||||
import { _normalizeInputMedia } from '../files/normalize-input-media.js'
|
||||
import { _normalizeInputText } from '../misc/normalize-text.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
|
@ -82,7 +81,7 @@ export async function sendMedia(
|
|||
)
|
||||
|
||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
||||
const { peer, replyTo } = await _processCommonSendParameters(client, chatId, params)
|
||||
const { peer, replyTo, scheduleDate } = await _processCommonSendParameters(client, chatId, params)
|
||||
|
||||
const res = await client.call({
|
||||
_: 'messages.sendMedia',
|
||||
|
@ -91,7 +90,7 @@ export async function sendMedia(
|
|||
silent: params.silent,
|
||||
replyTo,
|
||||
randomId: randomLong(),
|
||||
scheduleDate: normalizeDate(params.schedule),
|
||||
scheduleDate,
|
||||
replyMarkup,
|
||||
message,
|
||||
entities,
|
||||
|
|
|
@ -5,7 +5,6 @@ import { BotKeyboard, ReplyMarkup } from '../../types/bots/keyboards.js'
|
|||
import { Message } from '../../types/messages/message.js'
|
||||
import { InputText } from '../../types/misc/entities.js'
|
||||
import { InputPeerLike, PeersIndex } from '../../types/peers/index.js'
|
||||
import { normalizeDate } from '../../utils/misc-utils.js'
|
||||
import { inputPeerToPeer } from '../../utils/peer-utils.js'
|
||||
import { createDummyUpdate } from '../../utils/updates-utils.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
|
@ -53,7 +52,7 @@ export async function sendText(
|
|||
const [message, entities] = await _normalizeInputText(client, text)
|
||||
|
||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
||||
const { peer, replyTo } = await _processCommonSendParameters(client, chatId, params)
|
||||
const { peer, replyTo, scheduleDate } = await _processCommonSendParameters(client, chatId, params)
|
||||
|
||||
const res = await client.call({
|
||||
_: 'messages.sendMessage',
|
||||
|
@ -62,7 +61,7 @@ export async function sendText(
|
|||
silent: params.silent,
|
||||
replyTo,
|
||||
randomId: randomLong(),
|
||||
scheduleDate: normalizeDate(params.schedule),
|
||||
scheduleDate,
|
||||
replyMarkup,
|
||||
message,
|
||||
entities,
|
||||
|
|
Loading…
Reference in a new issue