1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2025-11-18 21:45:06 +00:00

Compare commits

...

7 Commits

5 changed files with 44 additions and 6 deletions

View File

@@ -1,5 +1,15 @@
# TelegramBotAPI changelog # TelegramBotAPI changelog
## 9.1.2
* `Core`:
* Fix of `MessageContent` serialization
## 9.1.1
* `Core`:
* Potential fix of incorrect parsing in `RawMessageEntity`
## 9.1.0 ## 9.1.0
**This update contains adding of [Telegram Bot API 6.8](https://core.telegram.org/bots/api-changelog#august-18-2023) support** **This update contains adding of [Telegram Bot API 6.8](https://core.telegram.org/bots/api-changelog#august-18-2023) support**

View File

@@ -6,4 +6,4 @@ kotlin.incremental=true
kotlin.incremental.js=true kotlin.incremental.js=true
library_group=dev.inmo library_group=dev.inmo
library_version=9.1.0 library_version=9.1.2

View File

@@ -18,6 +18,30 @@ internal data class RawMessageEntity(
internal val range by lazy { internal val range by lazy {
offset until (offset + length) offset until (offset + length)
} }
val priority by lazy {
when (type) {
// Types with potential subsources should have priority
"mention" -> 0
"hashtag" -> 0
"cashtag" -> 0
"email" -> 0
"phone_number" -> 0
"bold" -> 0
"italic" -> 0
"text_mention" -> 0
"strikethrough" -> 0
"underline" -> 0
"spoiler" -> 0
"custom_emoji" -> 0
"bot_command" -> 1
"url" -> 1
"code" -> 1
"pre" -> 1
"text_link" -> 1
else -> 1
}
}
} }
internal fun RawMessageEntity.asTextSource( internal fun RawMessageEntity.asTextSource(
@@ -85,7 +109,10 @@ private fun createTextSources(
originalFullString: String, originalFullString: String,
entities: RawMessageEntities entities: RawMessageEntities
): List<Pair<Int, TextSource>> { ): List<Pair<Int, TextSource>> {
val mutableEntities = entities.toMutableList().apply { sortBy { it.offset } } val mutableEntities = entities.toMutableList().apply {
sortBy { it.priority } // sorting to fix potential issues in source sorting of entities
sortBy { it.offset }
}
val resultList = mutableListOf<Pair<Int, TextSource>>() val resultList = mutableListOf<Pair<Int, TextSource>>()
while (mutableEntities.isNotEmpty()) { while (mutableEntities.isNotEmpty()) {

View File

@@ -13,8 +13,10 @@ import dev.inmo.tgbotapi.types.media.TelegramMedia
import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.abstracts.*
import dev.inmo.tgbotapi.types.threadId import dev.inmo.tgbotapi.types.threadId
import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.RiskFeature
import kotlinx.serialization.Serializable
import kotlinx.serialization.modules.* import kotlinx.serialization.modules.*
@Serializable
sealed interface MessageContent: ResendableContent { sealed interface MessageContent: ResendableContent {
companion object { companion object {
@RiskFeature("This serialization module can be changed in near releases") @RiskFeature("This serialization module can be changed in near releases")
@@ -49,6 +51,7 @@ sealed interface MessageContent: ResendableContent {
subclass(AnimationContent::class) subclass(AnimationContent::class)
subclass(StickerContent::class) subclass(StickerContent::class)
subclass(InvoiceContent::class) subclass(InvoiceContent::class)
subclass(StoryContent::class)
additionalBuilder() additionalBuilder()
} }

View File

@@ -58,7 +58,6 @@ sealed interface LocationContent : MessageContent {
/** /**
* [KSerializer] for [LocationContent] * [KSerializer] for [LocationContent]
*/ */
@Serializer(LocationContent::class)
object LocationContentSerializer : KSerializer<LocationContent> { object LocationContentSerializer : KSerializer<LocationContent> {
override val descriptor: SerialDescriptor = buildClassSerialDescriptor("LocationContent") { override val descriptor: SerialDescriptor = buildClassSerialDescriptor("LocationContent") {
element(LocationContent::location.name, LocationSerializer.descriptor) element(LocationContent::location.name, LocationSerializer.descriptor)
@@ -85,7 +84,6 @@ object LocationContentSerializer : KSerializer<LocationContent> {
encodeSerializableElement(descriptor, 0, LocationSerializer, value.location) encodeSerializableElement(descriptor, 0, LocationSerializer, value.location)
}.endStructure(descriptor) }.endStructure(descriptor)
} }
} }
/** /**
@@ -94,7 +92,7 @@ object LocationContentSerializer : KSerializer<LocationContent> {
* *
* @see dev.inmo.tgbotapi.extensions.behaviour_builder.utils.followLocation * @see dev.inmo.tgbotapi.extensions.behaviour_builder.utils.followLocation
*/ */
@Serializable(LocationContentSerializer::class) @Serializable
data class LiveLocationContent( data class LiveLocationContent(
override val location: LiveLocation override val location: LiveLocation
) : LocationContent { ) : LocationContent {
@@ -127,7 +125,7 @@ data class LiveLocationContent(
* Just a [LocationContent] with [StaticLocation] [location]. It could be [LiveLocationContent] in previous time in case * Just a [LocationContent] with [StaticLocation] [location]. It could be [LiveLocationContent] in previous time in case
* when somebody has sent [LiveLocation] in chat and then stop to broadcast location * when somebody has sent [LiveLocation] in chat and then stop to broadcast location
*/ */
@Serializable(LocationContentSerializer::class) @Serializable
data class StaticLocationContent( data class StaticLocationContent(
override val location: StaticLocation override val location: StaticLocation
) : LocationContent { ) : LocationContent {