mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
fixes in unique updates handling
This commit is contained in:
parent
e1adde0978
commit
3b2310ece1
@ -5,6 +5,7 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder
|
|||||||
import dev.inmo.micro_utils.coroutines.*
|
import dev.inmo.micro_utils.coroutines.*
|
||||||
import dev.inmo.tgbotapi.bot.TelegramBot
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.TriggersHolder
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.handlers_registrar.TriggersHolder
|
||||||
|
import dev.inmo.tgbotapi.types.UpdateIdentifier
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
import dev.inmo.tgbotapi.updateshandlers.*
|
import dev.inmo.tgbotapi.updateshandlers.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@ -71,9 +72,14 @@ class DefaultBehaviourContext(
|
|||||||
private val additionalUpdatesSharedFlow = MutableSharedFlow<Update>(0, broadcastChannelsSize, onBufferOverflow)
|
private val additionalUpdatesSharedFlow = MutableSharedFlow<Update>(0, broadcastChannelsSize, onBufferOverflow)
|
||||||
override val allUpdatesFlow: Flow<Update> = (additionalUpdatesSharedFlow.asSharedFlow()).let {
|
override val allUpdatesFlow: Flow<Update> = (additionalUpdatesSharedFlow.asSharedFlow()).let {
|
||||||
if (upstreamUpdatesFlow != null) {
|
if (upstreamUpdatesFlow != null) {
|
||||||
var lastHandledUpdate = -1L
|
val handledUpdates = mutableSetOf<UpdateIdentifier>()
|
||||||
(it + upstreamUpdatesFlow).filter {
|
(it + upstreamUpdatesFlow).filter {
|
||||||
(it.updateId > lastHandledUpdate).also { passed -> if (passed) { lastHandledUpdate = it.updateId } }
|
val passed = handledUpdates.add(it.updateId)
|
||||||
|
(passed).also { passed ->
|
||||||
|
handledUpdates.removeAll(
|
||||||
|
handledUpdates.take(handledUpdates.size - broadcastChannelsSize).ifEmpty { return@also }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
|
Loading…
Reference in New Issue
Block a user