Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
993faee5
Commit
993faee5
authored
Apr 02, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix length estimate for the case Quote + Image
parent
997261fa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
...commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
+13
-9
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/utils/type.kt
View file @
993faee5
...
...
@@ -12,10 +12,7 @@
package
net.mamoe.mirai.qqandroid.utils
import
net.mamoe.mirai.message.data.Image
import
net.mamoe.mirai.message.data.MessageChain
import
net.mamoe.mirai.message.data.PlainText
import
net.mamoe.mirai.message.data.QuoteReply
import
net.mamoe.mirai.message.data.*
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
...
...
@@ -40,13 +37,20 @@ internal fun String.chineseLength(upTo: Int): Int {
internal
fun
MessageChain
.
estimateLength
(
upTo
:
Int
=
Int
.
MAX_VALUE
):
Int
=
sumUpTo
(
upTo
)
{
it
,
up
->
when
(
it
)
{
is
QuoteReply
->
700
is
Image
->
300
is
PlainText
->
it
.
stringValue
.
chineseLength
(
up
)
else
->
it
.
toString
().
chineseLength
(
up
)
it
.
estimateLength
(
up
)
}
@OptIn
(
ExperimentalMessageSource
::
class
)
internal
fun
SingleMessage
.
estimateLength
(
upTo
:
Int
=
Int
.
MAX_VALUE
):
Int
{
return
when
(
this
)
{
is
QuoteReply
->
{
700
+
source
.
originalMessage
.
estimateLength
(
upTo
)
}
is
Image
->
300
is
PlainText
->
stringValue
.
chineseLength
(
upTo
)
else
->
this
.
toString
().
chineseLength
(
upTo
)
}
}
internal
inline
fun
<
T
>
Iterable
<
T
>.
sumUpTo
(
upTo
:
Int
,
selector
:
(
T
,
remaining
:
Int
)
->
Int
):
Int
{
var
sum
=
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment