refactor(api): extracted date parameters normalization to utils
This commit is contained in:
parent
389c45ad7b
commit
35dc5561a1
3 changed files with 12 additions and 16 deletions
|
@ -11,7 +11,7 @@ import {
|
|||
import { tl } from '@mtcute/tl'
|
||||
import { TelegramClient } from '../../client'
|
||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||
import { randomUlong } from '../../utils/misc-utils'
|
||||
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||
|
||||
/**
|
||||
* Send a single photo
|
||||
|
@ -139,13 +139,7 @@ export async function sendPhoto(
|
|||
: params.replyTo.id
|
||||
: undefined,
|
||||
randomId: randomUlong(),
|
||||
scheduleDate: params.schedule
|
||||
? ~~(
|
||||
(typeof params.schedule === 'number'
|
||||
? params.schedule
|
||||
: params.schedule.getTime()) / 1000
|
||||
)
|
||||
: undefined,
|
||||
scheduleDate: normalizeDate(params.schedule),
|
||||
replyMarkup,
|
||||
message,
|
||||
entities,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { inputPeerToPeer, normalizeToInputPeer } from '../../utils/peer-utils'
|
||||
import { randomUlong } from '../../utils/misc-utils'
|
||||
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||
import {
|
||||
InputPeerLike,
|
||||
Message,
|
||||
|
@ -89,13 +89,7 @@ export async function sendText(
|
|||
: params.replyTo.id
|
||||
: undefined,
|
||||
randomId: randomUlong(),
|
||||
scheduleDate: params.schedule
|
||||
? ~~(
|
||||
(typeof params.schedule === 'number'
|
||||
? params.schedule
|
||||
: params.schedule.getTime()) / 1000
|
||||
)
|
||||
: undefined,
|
||||
scheduleDate: normalizeDate(params.schedule),
|
||||
replyMarkup,
|
||||
message,
|
||||
entities,
|
||||
|
|
|
@ -35,3 +35,11 @@ export function extractChannelIdFromUpdate(
|
|||
? upd.message.peerId.channelId
|
||||
: undefined
|
||||
}
|
||||
|
||||
export function normalizeDate(
|
||||
date: Date | number | undefined
|
||||
): number | undefined {
|
||||
return date
|
||||
? ~~((typeof date === 'number' ? date : date.getTime()) / 1000)
|
||||
: undefined
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue