diff --git a/CHANGELOG.md b/CHANGELOG.md index aef340cdc0..ff8199814e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ * `Common`: * `Version`: * `Serialization`: `1.2.2` -> `1.3.0` - * `MicroUtils`: `0.5.28` -> `0.7.0` + * `MicroUtils`: `0.5.28` -> `0.7.1` * `Klock`: `2.4.3` -> `2.4.5` * `Core`: * `PayInlineKeyboardButton#pay` now is deprecated diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt index 08a60ddce1..b93449737e 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt @@ -16,6 +16,7 @@ import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.toList +import kotlin.reflect.KClass typealias CommonMessageToContentMapper = suspend CommonMessage.() -> T? @@ -54,19 +55,17 @@ private suspend fun BehaviourContext.waitCommonMessage( internal inline fun contentConverter( noinline mapper: CommonMessageToContentMapper? = null -): suspend CommonMessage.() -> T? = { - if (content is T) { - @Suppress("UNCHECKED_CAST") - val message = (this as CommonMessage) - if (mapper == null) { - message.content - } else { +): suspend CommonMessage.() -> T? = mapper ?.let { + { + if (content is T) { + @Suppress("UNCHECKED_CAST") + val message = (this as CommonMessage) safelyWithoutExceptions { mapper(message) } + } else { + null } - } else { - null } -} +} ?: { content as? T } private suspend inline fun BehaviourContext.waitContent( count: Int = 1,