mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 03:28:44 +00:00
commit
7f43dc0815
@ -1,5 +1,11 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 4.1.1
|
||||
|
||||
* `Core`:
|
||||
* Add opportunity to create `IdChatIdentifier` with optional `threadId`
|
||||
* New serializer `FullChatIdentifierSerializer` with serialization of `ChatIdWithThreadId`
|
||||
|
||||
## 4.1.0
|
||||
|
||||
* `Versions`:
|
||||
|
@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=4.1.0
|
||||
library_version=4.1.1
|
||||
|
@ -30,6 +30,9 @@ sealed interface IdChatIdentifier : ChatIdentifier {
|
||||
|
||||
companion object {
|
||||
operator fun invoke(chatId: Identifier) = ChatId(chatId)
|
||||
operator fun invoke(chatId: Identifier, threadId: MessageThreadId?) = threadId ?.let {
|
||||
ChatIdWithThreadId(chatId, threadId)
|
||||
} ?: ChatId(chatId)
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,6 +97,7 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
override val descriptor: SerialDescriptor = internalSerializer.descriptor
|
||||
override fun deserialize(decoder: Decoder): ChatIdentifier {
|
||||
val id = internalSerializer.deserialize(decoder)
|
||||
|
||||
return id.longOrNull ?.let {
|
||||
ChatId(it)
|
||||
} ?: id.content.let {
|
||||
@ -112,3 +116,41 @@ object ChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@RiskFeature
|
||||
object FullChatIdentifierSerializer : KSerializer<ChatIdentifier> {
|
||||
private val internalSerializer = JsonPrimitive.serializer()
|
||||
override val descriptor: SerialDescriptor = internalSerializer.descriptor
|
||||
override fun deserialize(decoder: Decoder): ChatIdentifier {
|
||||
val id = internalSerializer.deserialize(decoder)
|
||||
|
||||
return id.longOrNull ?.let {
|
||||
ChatId(it)
|
||||
} ?:let {
|
||||
val splitted = id.content.split("/")
|
||||
if (splitted.size == 2) {
|
||||
val (chatId, threadId) = splitted
|
||||
ChatIdWithThreadId(
|
||||
chatId.toLongOrNull() ?: return@let null,
|
||||
threadId.toLongOrNull() ?: return@let null
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: id.content.let {
|
||||
if (!it.startsWith("@")) {
|
||||
Username("@$it")
|
||||
} else {
|
||||
Username(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun serialize(encoder: Encoder, value: ChatIdentifier) {
|
||||
when (value) {
|
||||
is ChatId -> encoder.encodeLong(value.chatId)
|
||||
is ChatIdWithThreadId -> encoder.encodeString("${value.chatId}/${value.threadId}")
|
||||
is Username -> encoder.encodeString(value.username)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user