1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00

additional fixes in live location

This commit is contained in:
InsanusMokrassar 2020-02-07 22:43:48 +06:00
parent d6bbb0cadc
commit 0e33b123e9

View File

@ -13,6 +13,7 @@ import com.soywiz.klock.DateTime
import com.soywiz.klock.TimeSpan import com.soywiz.klock.TimeSpan
import io.ktor.utils.io.core.Closeable import io.ktor.utils.io.core.Closeable
import kotlinx.coroutines.* import kotlinx.coroutines.*
import kotlin.math.ceil
private val livePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L private val livePeriodDelayMillis = (livePeriodLimit.last - 60L) * 1000L
class LiveLocation internal constructor( class LiveLocation internal constructor(
@ -68,17 +69,18 @@ suspend fun RequestsExecutor.startLiveLocation(
chatId: ChatIdentifier, chatId: ChatIdentifier,
latitude: Double, latitude: Double,
longitude: Double, longitude: Double,
firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, liveTimeMillis: Long = livePeriodDelayMillis,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocation { ): LiveLocation {
val liveTimeAsDouble = liveTimeMillis.toDouble()
val locationMessage = execute( val locationMessage = execute(
SendLocation( SendLocation(
chatId, chatId,
latitude, latitude,
longitude, longitude,
livePeriodLimit.last.toLong(), ceil(liveTimeAsDouble / 1000).toLong(),
disableNotification, disableNotification,
replyToMessageId, replyToMessageId,
replyMarkup replyMarkup
@ -88,7 +90,7 @@ suspend fun RequestsExecutor.startLiveLocation(
return LiveLocation( return LiveLocation(
this, this,
scope, scope,
firstTimeUntilCloseMillis.toDouble(), liveTimeAsDouble,
locationMessage locationMessage
) )
} }
@ -98,34 +100,34 @@ suspend fun RequestsExecutor.startLiveLocation(
chat: Chat, chat: Chat,
latitude: Double, latitude: Double,
longitude: Double, longitude: Double,
firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, liveTimeMillis: Long = livePeriodDelayMillis,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocation = startLiveLocation( ): LiveLocation = startLiveLocation(
scope, chat.id, latitude, longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup scope, chat.id, latitude, longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup
) )
suspend fun RequestsExecutor.startLiveLocation( suspend fun RequestsExecutor.startLiveLocation(
scope: CoroutineScope, scope: CoroutineScope,
chatId: ChatId, chatId: ChatId,
location: Location, location: Location,
firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, liveTimeMillis: Long = livePeriodDelayMillis,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocation = startLiveLocation( ): LiveLocation = startLiveLocation(
scope, chatId, location.latitude, location.longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup scope, chatId, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup
) )
suspend fun RequestsExecutor.startLiveLocation( suspend fun RequestsExecutor.startLiveLocation(
scope: CoroutineScope, scope: CoroutineScope,
chat: Chat, chat: Chat,
location: Location, location: Location,
firstTimeUntilCloseMillis: Long = livePeriodDelayMillis, liveTimeMillis: Long = livePeriodDelayMillis,
disableNotification: Boolean = false, disableNotification: Boolean = false,
replyToMessageId: MessageIdentifier? = null, replyToMessageId: MessageIdentifier? = null,
replyMarkup: KeyboardMarkup? = null replyMarkup: KeyboardMarkup? = null
): LiveLocation = startLiveLocation( ): LiveLocation = startLiveLocation(
scope, chat.id, location.latitude, location.longitude, firstTimeUntilCloseMillis, disableNotification, replyToMessageId, replyMarkup scope, chat.id, location.latitude, location.longitude, liveTimeMillis, disableNotification, replyToMessageId, replyMarkup
) )