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 { tl } from '@mtcute/tl'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||||
import { randomUlong } from '../../utils/misc-utils'
|
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a single photo
|
* Send a single photo
|
||||||
|
@ -139,13 +139,7 @@ export async function sendPhoto(
|
||||||
: params.replyTo.id
|
: params.replyTo.id
|
||||||
: undefined,
|
: undefined,
|
||||||
randomId: randomUlong(),
|
randomId: randomUlong(),
|
||||||
scheduleDate: params.schedule
|
scheduleDate: normalizeDate(params.schedule),
|
||||||
? ~~(
|
|
||||||
(typeof params.schedule === 'number'
|
|
||||||
? params.schedule
|
|
||||||
: params.schedule.getTime()) / 1000
|
|
||||||
)
|
|
||||||
: undefined,
|
|
||||||
replyMarkup,
|
replyMarkup,
|
||||||
message,
|
message,
|
||||||
entities,
|
entities,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { inputPeerToPeer, normalizeToInputPeer } from '../../utils/peer-utils'
|
import { inputPeerToPeer, normalizeToInputPeer } from '../../utils/peer-utils'
|
||||||
import { randomUlong } from '../../utils/misc-utils'
|
import { normalizeDate, randomUlong } from '../../utils/misc-utils'
|
||||||
import {
|
import {
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
Message,
|
Message,
|
||||||
|
@ -89,13 +89,7 @@ export async function sendText(
|
||||||
: params.replyTo.id
|
: params.replyTo.id
|
||||||
: undefined,
|
: undefined,
|
||||||
randomId: randomUlong(),
|
randomId: randomUlong(),
|
||||||
scheduleDate: params.schedule
|
scheduleDate: normalizeDate(params.schedule),
|
||||||
? ~~(
|
|
||||||
(typeof params.schedule === 'number'
|
|
||||||
? params.schedule
|
|
||||||
: params.schedule.getTime()) / 1000
|
|
||||||
)
|
|
||||||
: undefined,
|
|
||||||
replyMarkup,
|
replyMarkup,
|
||||||
message,
|
message,
|
||||||
entities,
|
entities,
|
||||||
|
|
|
@ -35,3 +35,11 @@ export function extractChannelIdFromUpdate(
|
||||||
? upd.message.peerId.channelId
|
? upd.message.peerId.channelId
|
||||||
: undefined
|
: 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