1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-16 06:45:26 +00:00

Merge pull request #576 from xzima/fix_new_BehaviourContext_ignored

fix: new BehaviourContext ignored
This commit is contained in:
InsanusMokrassar 2022-05-02 08:50:20 +06:00 committed by GitHub
commit 901c1e8956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,7 +90,7 @@ class DefaultBehaviourContext(
onBufferOverflow: BufferOverflow,
upstreamUpdatesFlow: Flow<Update>?,
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
): BehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter)
): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter)
}
fun BehaviourContext(
@ -116,7 +116,8 @@ suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
scope: CoroutineScope = LinkedSupervisorScope(),
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
): T = copy(
): T {
val newContext = copy(
scope = scope,
updatesFilter = updatesFilter ?.let { _ ->
{
@ -126,9 +127,9 @@ suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
}
},
upstreamUpdatesFlow = updatesUpstreamFlow
).run {
withContext(coroutineContext) {
behaviourContextReceiver().also { if (stopOnCompletion) stop() }
) as BC
return withContext(currentCoroutineContext()) {
newContext.behaviourContextReceiver().also { if (stopOnCompletion) newContext.stop() }
}
}