1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-30 14:08:44 +00:00

fixes in updateHandlerWithMediaGroupsAdaptation

This commit is contained in:
InsanusMokrassar 2022-12-30 09:13:53 +06:00
parent 887c51f83a
commit b50ad30176
2 changed files with 11 additions and 7 deletions

View File

@ -1,5 +1,7 @@
package dev.inmo.tgbotapi.extensions.utils.updates.retrieving package dev.inmo.tgbotapi.extensions.utils.updates.retrieving
import dev.inmo.micro_utils.coroutines.launchSafely
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage
import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate
@ -29,15 +31,18 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation(
) )
launch { launch {
launch { launchSafelyWithoutExceptions {
for (update in updatesChannel) { for (update in updatesChannel) {
when (val data = update.data) { val data = update.data
is PossiblyMediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) when {
data is PossiblyMediaGroupMessage<*> && data.mediaGroupId != null -> {
mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate)
}
else -> output(update) else -> output(update)
} }
} }
} }
launch { launchSafelyWithoutExceptions {
for ((_, mediaGroup) in mediaGroupAccumulatedChannel) { for ((_, mediaGroup) in mediaGroupAccumulatedChannel) {
mediaGroup.convertWithMediaGroupUpdates().forEach { mediaGroup.convertWithMediaGroupUpdates().forEach {
output(it) output(it)

View File

@ -41,10 +41,9 @@ fun Route.includeWebhookHandlingInRoute(
post { post {
try { try {
runCatchingSafely { runCatchingSafely {
val asJson = nonstrictJsonFormat.parseToJsonElement(call.receiveText()) val update = nonstrictJsonFormat.decodeFromString(
val update = nonstrictJsonFormat.decodeFromJsonElement(
UpdateDeserializationStrategy, UpdateDeserializationStrategy,
asJson call.receiveText()
) )
transformer(update) transformer(update)
}.onSuccess { }.onSuccess {