1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-03-30 01:40:29 +08:00

Kotlin coroutine

This commit is contained in:
Him188moe 2019-09-24 22:56:13 +08:00
parent 2d366d49a9
commit f459891cf8
2 changed files with 13 additions and 0 deletions
mirai-core/src/main/java/net/mamoe/mirai/message

View File

@ -104,6 +104,12 @@ abstract class Message {
* @return message connected
*/
open fun concat(tail: Message): MessageChain {
if (tail is MessageChain) {
return MessageChain(this).let {
tail.list.forEach { child -> it.concat(child) }
it
}
}
return MessageChain(this, Objects.requireNonNull(tail))
}

View File

@ -11,6 +11,9 @@ import java.util.stream.Stream
class MessageChain : Message {
override val type: Int = MessageId.CHAIN
/**
* Elements will not be instances of [MessageChain]
*/
val list: MutableList<Message> = Collections.synchronizedList(LinkedList<Message>())
constructor(head: Message, tail: Message) {
@ -58,6 +61,10 @@ class MessageChain : Message {
}
override fun concat(tail: Message): MessageChain {
if (tail is MessageChain) {
tail.list.forEach { child -> this.concat(child) }
return this
}
this.list.add(tail)
clearToStringCache()
return this