From a85e7d7387fee71c884c9f36e7648181a4a9ccaa Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 9 Nov 2021 00:32:04 +0600 Subject: [PATCH] fixes --- .../tgbotapi/bot/Ktor/base/AbstractRequestCallFactory.kt | 7 ++++--- .../requests/chat/invite_links/ChatJoinRequestAnswer.kt | 8 +++++--- .../kotlin/dev/inmo/tgbotapi/types/ChatJoinRequest.kt | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/AbstractRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/AbstractRequestCallFactory.kt index b6d31e8875..e62250f706 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/AbstractRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/AbstractRequestCallFactory.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.bot.Ktor.base import dev.inmo.micro_utils.coroutines.safely +import dev.inmo.micro_utils.coroutines.safelyWithResult import dev.inmo.tgbotapi.bot.Ktor.KtorCallFactory import dev.inmo.tgbotapi.bot.exceptions.newRequestException import dev.inmo.tgbotapi.requests.GetUpdates @@ -57,7 +58,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory { val content = response.receive() val responseObject = jsonFormatter.decodeFromString(Response.serializer(), content) - return safely { + return safelyWithResult { (responseObject.result?.let { jsonFormatter.decodeFromJsonElement(request.resultDeserializer, it) } ?: response.let { @@ -67,7 +68,7 @@ abstract class AbstractRequestCallFactory : KtorCallFactory { "Can't get result object from $content" ) }) - } + }.getOrThrow() } } @@ -76,4 +77,4 @@ abstract class AbstractRequestCallFactory : KtorCallFactory { urlsKeeper: TelegramAPIUrlsKeeper, request: Request ): Any? -} \ No newline at end of file +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/ChatJoinRequestAnswer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/ChatJoinRequestAnswer.kt index 78c34d8c5c..ab4c705187 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/ChatJoinRequestAnswer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/chat/invite_links/ChatJoinRequestAnswer.kt @@ -2,9 +2,7 @@ package dev.inmo.tgbotapi.requests.chat.invite_links import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.Serializable -import kotlinx.serialization.SerializationStrategy +import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer sealed interface ChatJoinRequestAnswer : SimpleRequest { @@ -17,7 +15,9 @@ sealed interface ChatJoinRequestAnswer : SimpleRequest { @Serializable data class ApproveChatJoinRequest( + @SerialName(chatIdField) override val chatId: ChatIdentifier, + @SerialName(userIdField) override val userId: UserId ) : ChatJoinRequestAnswer { override val requestSerializer: SerializationStrategy<*> @@ -28,7 +28,9 @@ data class ApproveChatJoinRequest( @Serializable data class DeclineChatJoinRequest( + @SerialName(chatIdField) override val chatId: ChatIdentifier, + @SerialName(userIdField) override val userId: UserId ) : ChatJoinRequestAnswer { override val requestSerializer: SerializationStrategy<*> diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatJoinRequest.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatJoinRequest.kt index f8c138a1d8..05ca019dcc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatJoinRequest.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/ChatJoinRequest.kt @@ -9,12 +9,12 @@ import kotlinx.serialization.Serializable data class ChatJoinRequest( @SerialName(chatField) val chat: PublicChat, - @SerialName(userField) + @SerialName(fromField) override val from: User, @SerialName(dateField) val date: TelegramDate, - @SerialName(bioField) - val bio: String, @SerialName(inviteLinkField) - val inviteLink: ChatInviteLink + val inviteLink: ChatInviteLink, + @SerialName(bioField) + val bio: String? = null ) : FromUser