From 21f5808b12ff5f36a84cdd11a448a7527bd05363 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 31 Aug 2023 19:35:01 +0600 Subject: [PATCH] small refactoring --- .../types/message/RawMessageEntity.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) 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 71a2e300cb..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 @@ -19,25 +19,26 @@ internal data class RawMessageEntity( offset until (offset + length) } - val weight by lazy { + val priority by lazy { when (type) { - "mention" -> 2 - "hashtag" -> 2 - "cashtag" -> 2 + // 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 - "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 } } @@ -109,7 +110,7 @@ private fun createTextSources( entities: RawMessageEntities ): List> { val mutableEntities = entities.toMutableList().apply { - sortByDescending { it.weight } + sortBy { it.priority } // sorting to fix potential issues in source sorting of entities sortBy { it.offset } } val resultList = mutableListOf>()