diff --git a/CHANGELOG.md b/CHANGELOG.md index 288b73f7b9..d74864db7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # TelegramBotAPI changelog +## 9.1.1 + +* `Core`: + * Potential fix of incorrect parsing in `RawMessageEntity` + ## 9.1.0 **This update contains adding of [Telegram Bot API 6.8](https://core.telegram.org/bots/api-changelog#august-18-2023) support** diff --git a/gradle.properties b/gradle.properties index 48a5330d31..61ebf873ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ kotlin.incremental=true kotlin.incremental.js=true library_group=dev.inmo -library_version=9.1.0 +library_version=9.1.1 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt index 8d4e49fe0a..b056f26c2f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessageEntity.kt @@ -18,6 +18,30 @@ internal data class RawMessageEntity( internal val range by lazy { 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( @@ -85,7 +109,10 @@ private fun createTextSources( originalFullString: String, entities: RawMessageEntities ): List> { - 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>() while (mutableEntities.isNotEmpty()) {