mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
potential fix of incorrect parsing in 'RawMessageEntity'
This commit is contained in:
parent
4cd7fdb436
commit
64244a60fe
@ -2,6 +2,9 @@
|
||||
|
||||
## 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**
|
||||
|
@ -18,6 +18,29 @@ internal data class RawMessageEntity(
|
||||
internal val range by lazy {
|
||||
offset until (offset + length)
|
||||
}
|
||||
|
||||
val weight by lazy {
|
||||
when (type) {
|
||||
"mention" -> 2
|
||||
"hashtag" -> 2
|
||||
"cashtag" -> 2
|
||||
"bot_command" -> 1
|
||||
"url" -> 1
|
||||
"email" -> 2
|
||||
"phone_number" -> 2
|
||||
"bold" -> 2
|
||||
"italic" -> 2
|
||||
"code" -> 1
|
||||
"pre" -> 1
|
||||
"text_link" -> 1
|
||||
"text_mention" -> 2
|
||||
"underline" -> 2
|
||||
"strikethrough" -> 2
|
||||
"spoiler" -> 2
|
||||
"custom_emoji" -> 2
|
||||
else -> 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun RawMessageEntity.asTextSource(
|
||||
@ -85,7 +108,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 {
|
||||
sortByDescending { it.weight }
|
||||
sortBy { it.offset }
|
||||
}
|
||||
val resultList = mutableListOf<Pair<Int, TextSource>>()
|
||||
|
||||
while (mutableEntities.isNotEmpty()) {
|
||||
|
Loading…
Reference in New Issue
Block a user