From e5bffa7c51166377842503c244dea20d167392dd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 30 Oct 2024 13:53:36 +0600 Subject: [PATCH] upgrade onRequestResultPresented in middlewares --- CHANGELOG.md | 1 + .../tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware.kt | 2 +- .../bot/ktor/middlewares/TelegramBotMiddlewareBuilder.kt | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea1d59d36..b4f52bd608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Add default middleware `ExceptionsThrottlerTelegramBotMiddleware` * Make `TelegramBotMiddlewaresPipelinesHandler` to be default `TelegramBotPipelinesHandler` * Make `DefaultKtorRequestsExecutor` now uses `runCatching` instead of `runCatchingSafely` + * `onRequestResultPresented` lambda now accepts non-nullable `result` ## 18.2.2 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware.kt index 719217843f..a4221a362f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddleware.kt @@ -28,7 +28,7 @@ open class TelegramBotMiddleware( internal val onBeforeSearchCallFactory: (suspend (request: Request<*>, callsFactories: List) -> Unit)? = null, internal val onBeforeCallFactoryMakeCall: (suspend (request: Request<*>, potentialFactory: KtorCallFactory) -> Unit)? = null, internal val onAfterCallFactoryMakeCall: (suspend (result: Any?, request: Request<*>, potentialFactory: KtorCallFactory) -> Any?)? = null, - internal val onRequestResultPresented: (suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List) -> Any?)? = null, + internal val onRequestResultPresented: (suspend (result: Any, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List) -> Any?)? = null, internal val onRequestResultAbsent: (suspend (request: Request<*>, callsFactories: List) -> Any?)? = null, internal val onRequestReturnResult: (suspend (result: Result<*>, request: Request<*>, callsFactories: List) -> Result?)? = null, val id: String = uuid4().toString() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewareBuilder.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewareBuilder.kt index 6400fc7c3b..83c64bb8ac 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewareBuilder.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/ktor/middlewares/TelegramBotMiddlewareBuilder.kt @@ -12,7 +12,7 @@ class TelegramBotMiddlewareBuilder { var onBeforeSearchCallFactory: (suspend (request: Request<*>, callsFactories: List) -> Unit)? = null var onBeforeCallFactoryMakeCall: (suspend (request: Request<*>, potentialFactory: KtorCallFactory) -> Unit)? = null var onAfterCallFactoryMakeCall: (suspend (result: Any?, request: Request<*>, potentialFactory: KtorCallFactory) -> Any?)? = null - var onRequestResultPresented: (suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List) -> Any?)? = null + var onRequestResultPresented: (suspend (result: Any, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List) -> Any?)? = null var onRequestResultAbsent: (suspend (request: Request<*>, callsFactories: List) -> Any?)? = null var onRequestReturnResult: (suspend (result: Result<*>, request: Request<*>, callsFactories: List) -> Result?)? = null var id: String = uuid4().toString() @@ -44,7 +44,7 @@ class TelegramBotMiddlewareBuilder { /** * Useful way to set [onRequestResultPresented] */ - fun doOnRequestResultPresented(block: suspend (result: Any?, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List) -> Any?) { + fun doOnRequestResultPresented(block: suspend (result: Any, request: Request<*>, resultCallFactory: KtorCallFactory, callsFactories: List) -> Any?) { onRequestResultPresented = block } /**