Browse Source

Estimate length of originalMessage

Him188 6 năm trước cách đây
mục cha
commit
e23f91bac1

+ 5 - 4
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt

@@ -13,6 +13,7 @@
 package net.mamoe.mirai.qqandroid.utils
 
 import net.mamoe.mirai.message.data.*
+import net.mamoe.mirai.message.data.AtAll.display
 import kotlin.jvm.JvmMultifileClass
 import kotlin.jvm.JvmName
 
@@ -33,7 +34,7 @@ internal fun Int.toIpV4AddressString(): String {
 
 internal fun String.chineseLength(upTo: Int): Int {
     return this.sumUpTo(upTo) {
-        when(it) {
+        when (it) {
             in '\u0000'..'\u007F' -> 1
             in '\u0080'..'\u07FF' -> 2
             in '\u0800'..'\uFFFF' -> 3
@@ -42,14 +43,14 @@ internal fun String.chineseLength(upTo: Int): Int {
     }
 }
 
-internal fun MessageChain.estimateLength(upTo: Int = Int.MAX_VALUE): Int =
+internal fun MessageChain.estimateLength(upTo: Int): Int =
     sumUpTo(upTo) { it, up ->
         it.estimateLength(up)
     }
 
-internal fun SingleMessage.estimateLength(upTo: Int = Int.MAX_VALUE): Int {
+internal fun SingleMessage.estimateLength(upTo: Int): Int {
     return when (this) {
-        is QuoteReply -> 444 // Magic number
+        is QuoteReply -> 444 + this.source.originalMessage.estimateLength(upTo) // Magic number
         is Image -> 260 // Magic number
         is PlainText -> stringValue.chineseLength(upTo)
         is At -> display.chineseLength(upTo)