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
ac263579
Commit
ac263579
authored
Mar 23, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ambiguous CombinedMessage
parent
7443e2ae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt
...in/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt
+17
-7
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
...commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
+4
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/CombinedMessage.kt
View file @
ac263579
...
...
@@ -24,7 +24,7 @@ import kotlin.jvm.JvmName
*/
class
CombinedMessage
(
val
left
:
Message
,
val
element
:
Message
val
tail
:
Message
)
:
Iterable
<
Message
>,
Message
{
// 不要把它用作 local function, 会编译错误
...
...
@@ -32,16 +32,26 @@ class CombinedMessage(
when
(
message
)
{
is
CombinedMessage
->
{
// fast path, 避免创建新的 iterator, 也不会挂起协程
yieldCombinedOrElements
(
message
.
element
)
yieldCombinedOrElements
(
message
.
left
)
yieldCombinedOrElements
(
message
.
tail
)
}
is
MessageChain
->
{
is
Iterable
<
*
>
->
{
// 更好的性能, 因为协程不会挂起.
// 这可能会导致爆栈 (十万个元素), 但作为消息序列足够了.
message
.
forEach
{
yieldCombinedOrElements
(
it
)
}
message
.
forEach
{
yieldCombinedOrElements
(
it
as
?
Message
?:
error
(
"A Message implementing Iterable must implement Iterable<Message>, "
+
"whereas got ${it!!::class.simpleName}"
)
)
}
}
else
->
{
check
(
message
is
SingleMessage
)
{
"unsupported Message type. DO NOT CREATE YOUR OWN Message TYPE!"
}
check
(
message
is
SingleMessage
)
{
"unsupported Message type. "
+
"A Message must be a CombinedMessage, a Iterable<Message> or a SingleMessage"
}
yield
(
message
)
}
}
...
...
@@ -56,10 +66,10 @@ class CombinedMessage(
}
override
fun
toString
():
String
{
return
element
.
toString
()
+
left
.
toString
()
return
tail
.
toString
()
+
left
.
toString
()
}
fun
isFlat
():
Boolean
{
return
element
is
SingleMessage
&&
left
is
SingleMessage
return
tail
is
SingleMessage
&&
left
is
SingleMessage
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
View file @
ac263579
...
...
@@ -95,7 +95,7 @@ interface Message {
*/
@JvmSynthetic
// in java they should use `plus` instead
fun
followedBy
(
tail
:
Message
):
CombinedMessage
{
return
CombinedMessage
(
tail
,
this
)
return
CombinedMessage
(
left
=
this
,
tail
=
tail
)
}
/**
...
...
@@ -110,6 +110,9 @@ interface Message {
operator
fun
plus
(
another
:
Message
):
CombinedMessage
=
this
.
followedBy
(
another
)
// avoid resolution ambiguity
operator
fun
plus
(
another
:
SingleMessage
):
CombinedMessage
=
this
.
followedBy
(
another
)
operator
fun
plus
(
another
:
String
):
CombinedMessage
=
this
.
followedBy
(
another
.
toMessage
())
// `+ ""` will be resolved to `plus(String)` instead of `plus(CharSeq)`
...
...
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