From 1f62c8cf9876e2d6ba55c42dd815d93a59c80e31 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 12 Aug 2019 15:41:07 +0600 Subject: [PATCH] RawChat boilerplate was removed and replaced by serializers --- CHANGELOG.md | 1 + .../bot/exceptions/HandleException.kt | 15 --- .../requests/chat/get/GetChat.kt | 7 +- .../TelegramBotAPI/types/Common.kt | 5 + .../types/chat/ChannelChatImpl.kt | 6 ++ .../types/chat/ChatSerializers.kt | 68 +++++++++++++ .../types/chat/GroupChatImpl.kt | 8 +- .../types/chat/PrivateChatImpl.kt | 7 ++ .../TelegramBotAPI/types/chat/RawChat.kt | 97 ------------------- .../types/chat/SupergroupChatImpl.kt | 6 ++ .../types/chat/abstracts/Chat.kt | 3 + .../chat/abstracts/extended/ExtendedChat.kt | 3 + .../chat/extended/ExtendedChannelChatImpl.kt | 18 +++- .../chat/extended/ExtendedGroupChatImpl.kt | 19 +++- .../chat/extended/ExtendedPrivateChatImpl.kt | 12 ++- .../extended/ExtendedSupergroupChatImpl.kt | 23 ++++- .../types/message/RawMessage.kt | 8 +- 17 files changed, 168 insertions(+), 138 deletions(-) delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt create mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt delete mode 100644 src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 586dbea97f..98a5d66c83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ was replaced into `abstracts` package and available permissions was updated Other important changes: * Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request +* `RawChat` boilerplate was removed and replaced by serializers * `RequestsExecutor` now is `Closeable` * `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things like this diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt deleted file mode 100644 index 9c147a59b5..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/bot/exceptions/HandleException.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions - -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat - -sealed class HandleException ( - message: String -) : IllegalArgumentException( - message -) - -class IllegalChatRawObjectException( - rawChat: RawChat -) : HandleException( - "One of the fields in raw chat object is incorrect" -) diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt index fdd9ce0bd6..275b772ff4 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/requests/chat/get/GetChat.kt @@ -3,7 +3,8 @@ package com.github.insanusmokrassar.TelegramBotAPI.requests.chat.get import com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts.types.ChatRequest import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.RawChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat import com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField import kotlinx.serialization.* @@ -11,7 +12,7 @@ import kotlinx.serialization.* data class GetChat( @SerialName(chatIdField) override val chatId: ChatIdentifier -): ChatRequest, SimpleRequest { +): ChatRequest, SimpleRequest { override fun method(): String = "getChat" - override fun resultSerializer(): KSerializer = RawChat.serializer() + override fun resultSerializer(): KSerializer = ExtendedChatSerializer } diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt index 2c2cf8c768..dd07501d98 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/Common.kt @@ -56,6 +56,7 @@ const val lastNameField = "last_name" const val languageCodeField = "language_code" const val textEntitiesField = "text_entities" const val stickerSetNameField = "set_name" +const val stickerSetNameFullField = "sticker_set_name" const val maskPositionField = "mask_position" const val phoneNumberField = "phone_number" const val userIdField = "user_id" @@ -91,6 +92,8 @@ const val botUsernameField = "bot_username" const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat" const val switchInlineQueryField = "switch_inline_query" const val isAnimatedField = "is_animated" +const val inviteLinkField = "invite_link" +const val pinnedMessageField = "pinned_message" const val requestWriteAccessField = "request_write_access" @@ -149,6 +152,7 @@ const val canSendMediaMessagesField = "can_send_media_messages" const val canSendOtherMessagesField = "can_send_other_messages" const val canSendPollsField = "can_send_polls" const val canAddWebPagePreviewsField = "can_add_web_page_previews" +const val canSetStickerSetField = "can_set_sticker_set" const val canBeEditedField = "can_be_edited" const val canChangeInfoField = "can_change_info" @@ -205,6 +209,7 @@ const val questionField = "question" const val optionsField = "options" const val payField = "pay" const val permissionsField = "permissions" +const val typeField = "type" const val pointField = "point" const val xShiftField = "x_shift" diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt index c10fc3ab98..53a434e3c7 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChannelChatImpl.kt @@ -4,9 +4,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ChannelChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(usernameField) override val username: Username? = null ) : ChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt new file mode 100644 index 0000000000..4de5303901 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/ChatSerializers.kt @@ -0,0 +1,68 @@ +package com.github.insanusmokrassar.TelegramBotAPI.types.chat + +import com.github.insanusmokrassar.TelegramBotAPI.types.* +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended.* +import kotlinx.serialization.* +import kotlinx.serialization.internal.StringDescriptor +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonObjectSerializer + +object PreviewChatSerializer : KSerializer { + override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer") + + override fun deserialize(decoder: Decoder): Chat { + val decodedJson = JsonObjectSerializer.deserialize(decoder) + + val type = decodedJson.getPrimitive(typeField).content + + return when (type) { + "private" -> Json.nonstrict.fromJson(PrivateChatImpl.serializer(), decodedJson) + "group" -> Json.nonstrict.fromJson(GroupChatImpl.serializer(), decodedJson) + "supergroup" -> Json.nonstrict.fromJson(SupergroupChatImpl.serializer(), decodedJson) + "channel" -> Json.nonstrict.fromJson(ChannelChatImpl.serializer(), decodedJson) + else -> throw IllegalArgumentException("Unknown type of chat") + } + } + + override fun serialize(encoder: Encoder, obj: Chat) { + when (obj) { + is ExtendedChat -> ExtendedChatSerializer.serialize(encoder, obj) + is PrivateChatImpl -> PrivateChatImpl.serializer().serialize(encoder, obj) + is GroupChatImpl -> GroupChatImpl.serializer().serialize(encoder, obj) + is SupergroupChatImpl -> SupergroupChatImpl.serializer().serialize(encoder, obj) + is ChannelChatImpl -> ChannelChatImpl.serializer().serialize(encoder, obj) + } + } +} + +object ExtendedChatSerializer : KSerializer { + override val descriptor: SerialDescriptor = StringDescriptor.withName("PreviewChatSerializer") + + override fun deserialize(decoder: Decoder): ExtendedChat { + val decodedJson = JsonObjectSerializer.deserialize(decoder) + + val type = decodedJson.getPrimitive(typeField).content + + return when (type) { + "private" -> Json.nonstrict.fromJson(ExtendedPrivateChatImpl.serializer(), decodedJson) + "group" -> Json.nonstrict.fromJson(ExtendedGroupChatImpl.serializer(), decodedJson) + "supergroup" -> Json.nonstrict.fromJson(ExtendedSupergroupChatImpl.serializer(), decodedJson) + "channel" -> Json.nonstrict.fromJson(ExtendedChannelChatImpl.serializer(), decodedJson) + else -> throw IllegalArgumentException("Unknown type of chat") + } + } + + override fun serialize(encoder: Encoder, obj: ExtendedChat) { + when (obj) { + is ExtendedPrivateChatImpl -> ExtendedPrivateChatImpl.serializer().serialize(encoder, obj) + is ExtendedGroupChatImpl -> ExtendedGroupChatImpl.serializer().serialize(encoder, obj) + is ExtendedSupergroupChatImpl -> ExtendedSupergroupChatImpl.serializer().serialize(encoder, obj) + is ExtendedChannelChatImpl -> ExtendedChannelChatImpl.serializer().serialize(encoder, obj) + } + } +} + + + diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt index 4959f2077a..0f97e79b70 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/GroupChatImpl.kt @@ -1,11 +1,15 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class GroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String ) : GroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt index c8a8f837f1..e335fa4aa0 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/PrivateChatImpl.kt @@ -2,10 +2,17 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class PrivateChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(usernameField) override val username: Username? = null, + @SerialName(firstNameField) override val firstName: String = "", + @SerialName(lastNameField) override val lastName: String = "" ) : PrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt deleted file mode 100644 index e04894c535..0000000000 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/RawChat.kt +++ /dev/null @@ -1,97 +0,0 @@ -package com.github.insanusmokrassar.TelegramBotAPI.types.chat - -import com.github.insanusmokrassar.TelegramBotAPI.bot.exceptions.IllegalChatRawObjectException -import com.github.insanusmokrassar.TelegramBotAPI.types.* -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChat -import com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended.* -import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class RawChat( - override val id: ChatId, - private val type: String, - private val title: String? = null, - private val username: Username? = null, - private val first_name: String? = null, - private val last_name: String? = null, - private val description: String? = null, - private val invite_link: String? = null, - private val pinned_message: RawMessage? = null, - private val sticker_set_name: String? = null, - private val can_set_sticker_set: Boolean? = null, - @SerialName("photo") - private val chatPhoto: ChatPhoto? = null, - private val permissions: ChatPermissions? = null -) : Chat { - private fun extractExtendedChat(): ExtendedChat { - return when (type) { - "private" -> ExtendedPrivateChatImpl(id, username, first_name ?: "", last_name ?: "", chatPhoto!!) - "group" -> ExtendedGroupChatImpl( - id, - title!!, - chatPhoto!!, - description ?: "", - invite_link, - permissions!!, - pinned_message - ) - "supergroup" -> ExtendedSupergroupChatImpl( - id, - title!!, - username, - chatPhoto!!, - description ?: "", - invite_link, - permissions!!, - pinned_message, - sticker_set_name, - can_set_sticker_set ?: false - ) - "channel" -> ExtendedChannelChatImpl( - id, - title!!, - username, - chatPhoto!!, - description ?: "", - invite_link, - pinned_message - ) - else -> throw IllegalArgumentException("Unknown type of chat") - } - } - - private fun extractPreviewChat(): Chat { - return when (type) { - "private" -> PrivateChatImpl(id, username, first_name ?: "", last_name ?: "") - "group" -> GroupChatImpl( - id, - title!! - ) - "supergroup" -> SupergroupChatImpl( - id, - title!!, - username - ) - "channel" -> ChannelChatImpl( - id, - title!!, - username - ) - else -> throw IllegalArgumentException("Unknown type of chat") - } - } - - fun extractChat(): Chat { - return try { - when (chatPhoto) { - null -> extractPreviewChat() - else -> extractExtendedChat() - } - } catch (e: NullPointerException) { - throw IllegalChatRawObjectException(this) - } - } -} diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt index d492647dd8..ce53d3bd4f 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/SupergroupChatImpl.kt @@ -5,9 +5,15 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class SupergroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(usernameField) override val username: Username? = null ) : SupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt index 2f208fa270..7eead97d8e 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/Chat.kt @@ -2,7 +2,10 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.PreviewChatSerializer +import kotlinx.serialization.Serializable +@Serializable(PreviewChatSerializer::class) interface Chat { val id: ChatId } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt index 5a11195175..24a13a19d1 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/abstracts/extended/ExtendedChat.kt @@ -1,8 +1,11 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ExtendedChatSerializer import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat +import kotlinx.serialization.Serializable +@Serializable(ExtendedChatSerializer::class) interface ExtendedChat : Chat { val chatPhoto: ChatPhoto } \ No newline at end of file diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt index 66fa32a89b..7f47b04816 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedChannelChatImpl.kt @@ -3,13 +3,23 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedChannelChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, - override val username: Username?, + @SerialName(usernameField) + override val username: Username? = null, + @SerialName(photoField) override val chatPhoto: ChatPhoto, - override val description: String, - override val inviteLink: String?, - override val pinnedMessage: RawMessage? + @SerialName(descriptionField) + override val description: String = "", + @SerialName(inviteLinkField) + override val inviteLink: String? = null, + @SerialName(pinnedMessageField) + override val pinnedMessage: RawMessage? = null ) : ExtendedChannelChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt index 58ee8695bb..f9990cd24d 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedGroupChatImpl.kt @@ -1,17 +1,26 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId -import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto +import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedGroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(photoField) override val chatPhoto: ChatPhoto, - override val description: String, - override val inviteLink: String?, + @SerialName(permissionsField) override val permissions: ChatPermissions, - override val pinnedMessage: RawMessage? + @SerialName(descriptionField) + override val description: String = "", + @SerialName(inviteLinkField) + override val inviteLink: String? = null, + @SerialName(pinnedMessageField) + override val pinnedMessage: RawMessage? = null ) : ExtendedGroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt index 3469146856..c960d71a08 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedPrivateChatImpl.kt @@ -2,11 +2,19 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedPrivateChat +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedPrivateChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(photoField) + override val chatPhoto: ChatPhoto, + @SerialName(usernameField) override val username: Username? = null, + @SerialName(firstNameField) override val firstName: String = "", - override val lastName: String = "", - override val chatPhoto: ChatPhoto + @SerialName(lastNameField) + override val lastName: String = "" ) : ExtendedPrivateChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt index bd40e28001..c781b3ff6c 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/chat/extended/ExtendedSupergroupChatImpl.kt @@ -4,16 +4,29 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.* import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +@Serializable data class ExtendedSupergroupChatImpl( + @SerialName(idField) override val id: ChatId, + @SerialName(titleField) override val title: String, + @SerialName(usernameField) override val username: Username? = null, + @SerialName(photoField) override val chatPhoto: ChatPhoto, - override val description: String, - override val inviteLink: String?, + @SerialName(permissionsField) override val permissions: ChatPermissions, - override val pinnedMessage: RawMessage?, - override val stickerSetName: StickerSetName?, - override val canSetStickerSet: Boolean + @SerialName(descriptionField) + override val description: String = "", + @SerialName(inviteLinkField) + override val inviteLink: String? = null, + @SerialName(pinnedMessageField) + override val pinnedMessage: RawMessage? = null, + @SerialName(stickerSetNameFullField) + override val stickerSetName: StickerSetName? = null, + @SerialName(canSetStickerSetField) + override val canSetStickerSet: Boolean = false ) : ExtendedSupergroupChat diff --git a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt index 3145aff30a..02008dfd76 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/message/RawMessage.kt @@ -31,11 +31,11 @@ data class RawMessage( @SerialName(dateField) val date: TelegramDate, @SerialName(chatField) - private val chat: RawChat, + private val chat: Chat, @SerialName(fromField) private val from: User? = null, private val forward_from: User? = null, - private val forward_from_chat: RawChat? = null, + private val forward_from_chat: Chat? = null, private val forward_from_message_id: MessageIdentifier? = null, private val forward_signature: ForwardSignature? = null, private val forward_sender_name: ForwardSenderName? = null, @@ -150,7 +150,7 @@ data class RawMessage( forward_from_chat != null -> ForwardedFromChannelMessage( forward_date, forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"), - forward_from_chat.extractChat(), + forward_from_chat, forward_signature ) forward_from != null -> UserForwardedMessage( @@ -194,8 +194,6 @@ data class RawMessage( @Transient val asMessage: Message by lazy { - val chat = chat.extractChat() - chatEvent ?.let { chatEvent -> when (chat) {