mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
add support of 'sender' chat type
This commit is contained in:
parent
ac63d52b14
commit
6896bc0772
@ -17,23 +17,41 @@ private val formatter
|
|||||||
sealed class ChatType {
|
sealed class ChatType {
|
||||||
abstract val stringified: String
|
abstract val stringified: String
|
||||||
@Serializable(ChatTypeSerializer::class)
|
@Serializable(ChatTypeSerializer::class)
|
||||||
object PrivateChatType : ChatType() { override val stringified = "private" }
|
object Sender : ChatType() { override val stringified = "sender" }
|
||||||
@Serializable(ChatTypeSerializer::class)
|
@Serializable(ChatTypeSerializer::class)
|
||||||
object GroupChatType : ChatType() { override val stringified = "group" }
|
object Private : ChatType() { override val stringified = "private" }
|
||||||
@Serializable(ChatTypeSerializer::class)
|
@Serializable(ChatTypeSerializer::class)
|
||||||
object SupergroupChatType : ChatType() { override val stringified = "supergroup" }
|
object Group : ChatType() { override val stringified = "group" }
|
||||||
@Serializable(ChatTypeSerializer::class)
|
@Serializable(ChatTypeSerializer::class)
|
||||||
object ChannelChatType : ChatType() { override val stringified = "channel" }
|
object Supergroup : ChatType() { override val stringified = "supergroup" }
|
||||||
@Serializable(ChatTypeSerializer::class)
|
@Serializable(ChatTypeSerializer::class)
|
||||||
class UnknownChatType(override val stringified: String) : ChatType()
|
object Channel : ChatType() { override val stringified = "channel" }
|
||||||
|
@Serializable(ChatTypeSerializer::class)
|
||||||
|
class Unknown(override val stringified: String) : ChatType()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@Deprecated("Renamed", ReplaceWith("Private", "dev.inmo.tgbotapi.types.chat.ChatType.Private"))
|
||||||
|
val PrivateChatType = Private
|
||||||
|
@Deprecated("Renamed", ReplaceWith("Group", "dev.inmo.tgbotapi.types.chat.ChatType.Group"))
|
||||||
|
val GroupChatType = Group
|
||||||
|
@Deprecated("Renamed", ReplaceWith("Supergroup", "dev.inmo.tgbotapi.types.chat.ChatType.Supergroup"))
|
||||||
|
val SupergroupChatType = Supergroup
|
||||||
|
@Deprecated("Renamed", ReplaceWith("Channel", "dev.inmo.tgbotapi.types.chat.ChatType.Channel"))
|
||||||
|
val ChannelChatType = Channel
|
||||||
|
@Deprecated("Renamed", ReplaceWith("Unknown", "dev.inmo.tgbotapi.types.chat.ChatType.Unknown"))
|
||||||
|
val UnknownChatType = Unknown
|
||||||
|
@Deprecated("Renamed", ReplaceWith("Unknown(stringified)", "dev.inmo.tgbotapi.types.chat.ChatType.Unknown"))
|
||||||
|
fun UnknownChatType(stringified: String) = Unknown(stringified)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val String.asChatType
|
val String.asChatType
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
ChatType.PrivateChatType.stringified -> ChatType.PrivateChatType
|
ChatType.Sender.stringified -> ChatType.Sender
|
||||||
ChatType.GroupChatType.stringified -> ChatType.GroupChatType
|
ChatType.Private.stringified -> ChatType.Private
|
||||||
ChatType.SupergroupChatType.stringified -> ChatType.SupergroupChatType
|
ChatType.Group.stringified -> ChatType.Group
|
||||||
ChatType.ChannelChatType.stringified -> ChatType.ChannelChatType
|
ChatType.Supergroup.stringified -> ChatType.Supergroup
|
||||||
else -> ChatType.UnknownChatType(this)
|
ChatType.Channel.stringified -> ChatType.Channel
|
||||||
|
else -> ChatType.Unknown(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@RiskFeature
|
@RiskFeature
|
||||||
@ -63,15 +81,16 @@ object ChatSerializer : KSerializer<Chat> {
|
|||||||
val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true
|
val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true
|
||||||
|
|
||||||
when (type) {
|
when (type) {
|
||||||
ChatType.PrivateChatType -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson)
|
ChatType.Sender -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson)
|
||||||
ChatType.GroupChatType -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson)
|
ChatType.Private -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson)
|
||||||
ChatType.SupergroupChatType -> if (isForum) {
|
ChatType.Group -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson)
|
||||||
|
ChatType.Supergroup -> if (isForum) {
|
||||||
formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson)
|
formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson)
|
||||||
} else {
|
} else {
|
||||||
formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson)
|
formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson)
|
||||||
}
|
}
|
||||||
ChatType.ChannelChatType -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson)
|
ChatType.Channel -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson)
|
||||||
is ChatType.UnknownChatType -> UnknownChatType(
|
is ChatType.Unknown -> UnknownChatType(
|
||||||
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
|
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
|
||||||
decodedJson.toString(),
|
decodedJson.toString(),
|
||||||
decodedJson
|
decodedJson
|
||||||
@ -101,15 +120,16 @@ object PreviewChatSerializer : KSerializer<PreviewChat> {
|
|||||||
val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true
|
val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true
|
||||||
|
|
||||||
return when (type) {
|
return when (type) {
|
||||||
ChatType.PrivateChatType -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson)
|
ChatType.Sender -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson)
|
||||||
ChatType.GroupChatType -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson)
|
ChatType.Private -> formatter.decodeFromJsonElement(PrivateChatImpl.serializer(), decodedJson)
|
||||||
ChatType.SupergroupChatType -> if (isForum) {
|
ChatType.Group -> formatter.decodeFromJsonElement(GroupChatImpl.serializer(), decodedJson)
|
||||||
|
ChatType.Supergroup -> if (isForum) {
|
||||||
formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson)
|
formatter.decodeFromJsonElement(ForumChatImpl.serializer(), decodedJson)
|
||||||
} else {
|
} else {
|
||||||
formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson)
|
formatter.decodeFromJsonElement(SupergroupChatImpl.serializer(), decodedJson)
|
||||||
}
|
}
|
||||||
ChatType.ChannelChatType -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson)
|
ChatType.Channel -> formatter.decodeFromJsonElement(ChannelChatImpl.serializer(), decodedJson)
|
||||||
is ChatType.UnknownChatType -> UnknownChatType(
|
is ChatType.Unknown -> UnknownChatType(
|
||||||
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
|
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
|
||||||
decodedJson.toString(),
|
decodedJson.toString(),
|
||||||
decodedJson
|
decodedJson
|
||||||
@ -143,16 +163,16 @@ sealed class ExtendedChatSerializer : KSerializer<ExtendedChat> {
|
|||||||
val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true
|
val isForum = decodedJson[isForumField] ?.jsonPrimitive ?.booleanOrNull == true
|
||||||
|
|
||||||
return when (type) {
|
return when (type) {
|
||||||
// else -> throw IllegalArgumentException("Unknown type of chat")
|
ChatType.Sender -> formatter.decodeFromJsonElement(ExtendedPrivateChatImpl.serializer(), decodedJson)
|
||||||
ChatType.PrivateChatType -> formatter.decodeFromJsonElement(ExtendedPrivateChatImpl.serializer(), decodedJson)
|
ChatType.Private -> formatter.decodeFromJsonElement(ExtendedPrivateChatImpl.serializer(), decodedJson)
|
||||||
ChatType.GroupChatType -> formatter.decodeFromJsonElement(ExtendedGroupChatImpl.serializer(), decodedJson)
|
ChatType.Group -> formatter.decodeFromJsonElement(ExtendedGroupChatImpl.serializer(), decodedJson)
|
||||||
ChatType.SupergroupChatType -> if (isForum) {
|
ChatType.Supergroup -> if (isForum) {
|
||||||
formatter.decodeFromJsonElement(ExtendedForumChatImpl.serializer(), decodedJson)
|
formatter.decodeFromJsonElement(ExtendedForumChatImpl.serializer(), decodedJson)
|
||||||
} else {
|
} else {
|
||||||
formatter.decodeFromJsonElement(ExtendedSupergroupChatImpl.serializer(), decodedJson)
|
formatter.decodeFromJsonElement(ExtendedSupergroupChatImpl.serializer(), decodedJson)
|
||||||
}
|
}
|
||||||
ChatType.ChannelChatType -> formatter.decodeFromJsonElement(ExtendedChannelChatImpl.serializer(), decodedJson)
|
ChatType.Channel -> formatter.decodeFromJsonElement(ExtendedChannelChatImpl.serializer(), decodedJson)
|
||||||
is ChatType.UnknownChatType -> UnknownExtendedChat(
|
is ChatType.Unknown -> UnknownExtendedChat(
|
||||||
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
|
formatter.decodeFromJsonElement(Long.serializer(), decodedJson[chatIdField] ?: JsonPrimitive(-1)).toChatId(),
|
||||||
decodedJson.toString(),
|
decodedJson.toString(),
|
||||||
decodedJson
|
decodedJson
|
||||||
|
Loading…
Reference in New Issue
Block a user