Merge pull request #785 from InsanusMokrassar/9.1.1

9.1.1
This commit is contained in:
InsanusMokrassar 2023-08-31 20:39:30 +06:00 committed by GitHub
commit 12846a68b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -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**

View File

@ -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

View File

@ -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<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>>()
while (mutableEntities.isNotEmpty()) {