mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-26 03:58:44 +00:00
RawChat boilerplate was removed and replaced by serializers
This commit is contained in:
parent
d6bb14e342
commit
1f62c8cf98
@ -23,6 +23,7 @@ was replaced into `abstracts` package and available permissions was updated
|
|||||||
Other important changes:
|
Other important changes:
|
||||||
|
|
||||||
* Totally reworked chats hierarchy. `Extended` abstractions was added for cases when called `GetChat` request
|
* 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`
|
* `RequestsExecutor` now is `Closeable`
|
||||||
* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things
|
* `TelegramAPIUrlsKeeper` was added to provide more comfortable work with file urls and other things
|
||||||
like this
|
like this
|
||||||
|
@ -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"
|
|
||||||
)
|
|
@ -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.CommonAbstracts.types.ChatRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.SimpleRequest
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatIdentifier
|
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 com.github.insanusmokrassar.TelegramBotAPI.types.chatIdField
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ import kotlinx.serialization.*
|
|||||||
data class GetChat(
|
data class GetChat(
|
||||||
@SerialName(chatIdField)
|
@SerialName(chatIdField)
|
||||||
override val chatId: ChatIdentifier
|
override val chatId: ChatIdentifier
|
||||||
): ChatRequest, SimpleRequest<RawChat> {
|
): ChatRequest, SimpleRequest<ExtendedChat> {
|
||||||
override fun method(): String = "getChat"
|
override fun method(): String = "getChat"
|
||||||
override fun resultSerializer(): KSerializer<RawChat> = RawChat.serializer()
|
override fun resultSerializer(): KSerializer<ExtendedChat> = ExtendedChatSerializer
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ const val lastNameField = "last_name"
|
|||||||
const val languageCodeField = "language_code"
|
const val languageCodeField = "language_code"
|
||||||
const val textEntitiesField = "text_entities"
|
const val textEntitiesField = "text_entities"
|
||||||
const val stickerSetNameField = "set_name"
|
const val stickerSetNameField = "set_name"
|
||||||
|
const val stickerSetNameFullField = "sticker_set_name"
|
||||||
const val maskPositionField = "mask_position"
|
const val maskPositionField = "mask_position"
|
||||||
const val phoneNumberField = "phone_number"
|
const val phoneNumberField = "phone_number"
|
||||||
const val userIdField = "user_id"
|
const val userIdField = "user_id"
|
||||||
@ -91,6 +92,8 @@ const val botUsernameField = "bot_username"
|
|||||||
const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat"
|
const val switchInlineQueryCurrentChatField = "switch_inline_query_current_chat"
|
||||||
const val switchInlineQueryField = "switch_inline_query"
|
const val switchInlineQueryField = "switch_inline_query"
|
||||||
const val isAnimatedField = "is_animated"
|
const val isAnimatedField = "is_animated"
|
||||||
|
const val inviteLinkField = "invite_link"
|
||||||
|
const val pinnedMessageField = "pinned_message"
|
||||||
|
|
||||||
|
|
||||||
const val requestWriteAccessField = "request_write_access"
|
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 canSendOtherMessagesField = "can_send_other_messages"
|
||||||
const val canSendPollsField = "can_send_polls"
|
const val canSendPollsField = "can_send_polls"
|
||||||
const val canAddWebPagePreviewsField = "can_add_web_page_previews"
|
const val canAddWebPagePreviewsField = "can_add_web_page_previews"
|
||||||
|
const val canSetStickerSetField = "can_set_sticker_set"
|
||||||
|
|
||||||
const val canBeEditedField = "can_be_edited"
|
const val canBeEditedField = "can_be_edited"
|
||||||
const val canChangeInfoField = "can_change_info"
|
const val canChangeInfoField = "can_change_info"
|
||||||
@ -205,6 +209,7 @@ const val questionField = "question"
|
|||||||
const val optionsField = "options"
|
const val optionsField = "options"
|
||||||
const val payField = "pay"
|
const val payField = "pay"
|
||||||
const val permissionsField = "permissions"
|
const val permissionsField = "permissions"
|
||||||
|
const val typeField = "type"
|
||||||
|
|
||||||
const val pointField = "point"
|
const val pointField = "point"
|
||||||
const val xShiftField = "x_shift"
|
const val xShiftField = "x_shift"
|
||||||
|
@ -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.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.PublicChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ChannelChatImpl(
|
data class ChannelChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
|
@SerialName(usernameField)
|
||||||
override val username: Username? = null
|
override val username: Username? = null
|
||||||
) : ChannelChat
|
) : ChannelChat
|
||||||
|
@ -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<Chat> {
|
||||||
|
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<ExtendedChat> {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.GroupChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class GroupChatImpl(
|
data class GroupChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(titleField)
|
||||||
override val title: String
|
override val title: String
|
||||||
) : GroupChat
|
) : GroupChat
|
||||||
|
@ -2,10 +2,17 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.*
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class PrivateChatImpl(
|
data class PrivateChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(usernameField)
|
||||||
override val username: Username? = null,
|
override val username: Username? = null,
|
||||||
|
@SerialName(firstNameField)
|
||||||
override val firstName: String = "",
|
override val firstName: String = "",
|
||||||
|
@SerialName(lastNameField)
|
||||||
override val lastName: String = ""
|
override val lastName: String = ""
|
||||||
) : PrivateChat
|
) : PrivateChat
|
||||||
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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.GroupChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.SupergroupChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class SupergroupChatImpl(
|
data class SupergroupChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
|
@SerialName(usernameField)
|
||||||
override val username: Username? = null
|
override val username: Username? = null
|
||||||
) : SupergroupChat
|
) : SupergroupChat
|
||||||
|
@ -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.ChatId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.PreviewChatSerializer
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable(PreviewChatSerializer::class)
|
||||||
interface Chat {
|
interface Chat {
|
||||||
val id: ChatId
|
val id: ChatId
|
||||||
}
|
}
|
@ -1,8 +1,11 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
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 com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.Chat
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable(ExtendedChatSerializer::class)
|
||||||
interface ExtendedChat : Chat {
|
interface ExtendedChat : Chat {
|
||||||
val chatPhoto: ChatPhoto
|
val chatPhoto: ChatPhoto
|
||||||
}
|
}
|
@ -3,13 +3,23 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedChannelChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ExtendedChannelChatImpl(
|
data class ExtendedChannelChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
override val username: Username?,
|
@SerialName(usernameField)
|
||||||
|
override val username: Username? = null,
|
||||||
|
@SerialName(photoField)
|
||||||
override val chatPhoto: ChatPhoto,
|
override val chatPhoto: ChatPhoto,
|
||||||
override val description: String,
|
@SerialName(descriptionField)
|
||||||
override val inviteLink: String?,
|
override val description: String = "",
|
||||||
override val pinnedMessage: RawMessage?
|
@SerialName(inviteLinkField)
|
||||||
|
override val inviteLink: String? = null,
|
||||||
|
@SerialName(pinnedMessageField)
|
||||||
|
override val pinnedMessage: RawMessage? = null
|
||||||
) : ExtendedChannelChat
|
) : ExtendedChannelChat
|
||||||
|
@ -1,17 +1,26 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ChatPhoto
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.ChatPermissions
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedGroupChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ExtendedGroupChatImpl(
|
data class ExtendedGroupChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
|
@SerialName(photoField)
|
||||||
override val chatPhoto: ChatPhoto,
|
override val chatPhoto: ChatPhoto,
|
||||||
override val description: String,
|
@SerialName(permissionsField)
|
||||||
override val inviteLink: String?,
|
|
||||||
override val permissions: ChatPermissions,
|
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
|
) : ExtendedGroupChat
|
||||||
|
@ -2,11 +2,19 @@ package com.github.insanusmokrassar.TelegramBotAPI.types.chat.extended
|
|||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedPrivateChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedPrivateChat
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ExtendedPrivateChatImpl(
|
data class ExtendedPrivateChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(photoField)
|
||||||
|
override val chatPhoto: ChatPhoto,
|
||||||
|
@SerialName(usernameField)
|
||||||
override val username: Username? = null,
|
override val username: Username? = null,
|
||||||
|
@SerialName(firstNameField)
|
||||||
override val firstName: String = "",
|
override val firstName: String = "",
|
||||||
override val lastName: String = "",
|
@SerialName(lastNameField)
|
||||||
override val chatPhoto: ChatPhoto
|
override val lastName: String = ""
|
||||||
) : ExtendedPrivateChat
|
) : ExtendedPrivateChat
|
||||||
|
@ -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.ChatPermissions
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat
|
import com.github.insanusmokrassar.TelegramBotAPI.types.chat.abstracts.extended.ExtendedSupergroupChat
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
import com.github.insanusmokrassar.TelegramBotAPI.types.message.RawMessage
|
||||||
|
import kotlinx.serialization.SerialName
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
data class ExtendedSupergroupChatImpl(
|
data class ExtendedSupergroupChatImpl(
|
||||||
|
@SerialName(idField)
|
||||||
override val id: ChatId,
|
override val id: ChatId,
|
||||||
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
|
@SerialName(usernameField)
|
||||||
override val username: Username? = null,
|
override val username: Username? = null,
|
||||||
|
@SerialName(photoField)
|
||||||
override val chatPhoto: ChatPhoto,
|
override val chatPhoto: ChatPhoto,
|
||||||
override val description: String,
|
@SerialName(permissionsField)
|
||||||
override val inviteLink: String?,
|
|
||||||
override val permissions: ChatPermissions,
|
override val permissions: ChatPermissions,
|
||||||
override val pinnedMessage: RawMessage?,
|
@SerialName(descriptionField)
|
||||||
override val stickerSetName: StickerSetName?,
|
override val description: String = "",
|
||||||
override val canSetStickerSet: Boolean
|
@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
|
) : ExtendedSupergroupChat
|
||||||
|
@ -31,11 +31,11 @@ data class RawMessage(
|
|||||||
@SerialName(dateField)
|
@SerialName(dateField)
|
||||||
val date: TelegramDate,
|
val date: TelegramDate,
|
||||||
@SerialName(chatField)
|
@SerialName(chatField)
|
||||||
private val chat: RawChat,
|
private val chat: Chat,
|
||||||
@SerialName(fromField)
|
@SerialName(fromField)
|
||||||
private val from: User? = null,
|
private val from: User? = null,
|
||||||
private val forward_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_from_message_id: MessageIdentifier? = null,
|
||||||
private val forward_signature: ForwardSignature? = null,
|
private val forward_signature: ForwardSignature? = null,
|
||||||
private val forward_sender_name: ForwardSenderName? = null,
|
private val forward_sender_name: ForwardSenderName? = null,
|
||||||
@ -150,7 +150,7 @@ data class RawMessage(
|
|||||||
forward_from_chat != null -> ForwardedFromChannelMessage(
|
forward_from_chat != null -> ForwardedFromChannelMessage(
|
||||||
forward_date,
|
forward_date,
|
||||||
forward_from_message_id ?: throw IllegalStateException("Channel forwarded message must contain message id, but was not"),
|
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_signature
|
||||||
)
|
)
|
||||||
forward_from != null -> UserForwardedMessage(
|
forward_from != null -> UserForwardedMessage(
|
||||||
@ -194,8 +194,6 @@ data class RawMessage(
|
|||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
val asMessage: Message by lazy {
|
val asMessage: Message by lazy {
|
||||||
val chat = chat.extractChat()
|
|
||||||
|
|
||||||
chatEvent ?.let {
|
chatEvent ?.let {
|
||||||
chatEvent ->
|
chatEvent ->
|
||||||
when (chat) {
|
when (chat) {
|
||||||
|
Loading…
Reference in New Issue
Block a user