mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-03 07:09:23 +00:00
fix of subcontextUpdatesFilter
This commit is contained in:
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
## 24.0.0
|
## 24.0.0
|
||||||
|
|
||||||
|
**THIS UPDATE CONTAINS BREAKING CHANGES IN `subcontextUpdatesFilter` WORK. TAKE CARE IN MIGRATION**
|
||||||
|
|
||||||
|
* `BehaviourBuilder`:
|
||||||
|
* Fix of overall `subcontextUpdatesFilter` behaviour. In fact, this update will fix its affection on scenaries
|
||||||
|
|
||||||
## 23.2.1
|
## 23.2.1
|
||||||
|
|
||||||
* `Core`:
|
* `Core`:
|
||||||
|
@@ -1,13 +1,20 @@
|
|||||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.coroutines.SpecialMutableStateFlow
|
||||||
|
import dev.inmo.micro_utils.coroutines.launchLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
|
import dev.inmo.micro_utils.coroutines.subscribeLoggingDropExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync
|
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.marker_factories.MarkerFactory
|
||||||
|
import dev.inmo.tgbotapi.extensions.utils.flatMap
|
||||||
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
import dev.inmo.tgbotapi.types.update.abstracts.Update
|
||||||
|
import kotlinx.coroutines.flow.emptyFlow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
|
||||||
internal suspend fun <BC : BehaviourContext, T> BC.on(
|
internal suspend fun <BC : BehaviourContext, T> BC.on(
|
||||||
markerFactory: MarkerFactory<in T, Any>?,
|
markerFactory: MarkerFactory<in T, Any>?,
|
||||||
@@ -40,11 +47,21 @@ internal suspend fun <BC : BehaviourContext, T> BC.on(
|
|||||||
}
|
}
|
||||||
val handler: suspend (Pair<Update, T>) -> Unit = subcontextUpdatesFilter ?.let {
|
val handler: suspend (Pair<Update, T>) -> Unit = subcontextUpdatesFilter ?.let {
|
||||||
{ (update, triggerData) ->
|
{ (update, triggerData) ->
|
||||||
createSubContextAndDoSynchronouslyWithUpdatesFilter {
|
val contextStateFlow = SpecialMutableStateFlow<BC?>(null)
|
||||||
if (subcontextUpdatesFilter(this, triggerData, update)) {
|
createSubContextAndDoSynchronouslyWithUpdatesFilter(
|
||||||
localSubcontextInitialAction(update, triggerData)
|
updatesUpstreamFlow = contextStateFlow.flatMapLatest { context ->
|
||||||
scenarioReceiver(triggerData)
|
if (context == null) {
|
||||||
|
emptyFlow()
|
||||||
|
} else {
|
||||||
|
allUpdatesFlow.filter {
|
||||||
|
context.subcontextUpdatesFilter(triggerData, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
) {
|
||||||
|
contextStateFlow.value = this
|
||||||
|
localSubcontextInitialAction(update, triggerData)
|
||||||
|
scenarioReceiver(triggerData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} ?: { (update, triggerData) ->
|
} ?: { (update, triggerData) ->
|
||||||
@@ -57,8 +74,8 @@ internal suspend fun <BC : BehaviourContext, T> BC.on(
|
|||||||
{ markerFactory(it.second) },
|
{ markerFactory(it.second) },
|
||||||
block = handler
|
block = handler
|
||||||
)
|
)
|
||||||
} ?: subscribeSafelyWithoutExceptions(scope) {
|
} ?: subscribeLoggingDropExceptions(scope) {
|
||||||
scope.launchSafelyWithoutExceptions {
|
scope.launchLoggingDropExceptions {
|
||||||
handler(it)
|
handler(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user