1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

fixes in updateHandlerWithMediaGroupsAdaptation

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

View File

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

View File

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