diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/MessageChain.kt b/mirai-core-api/src/commonMain/kotlin/message/data/MessageChain.kt index dbcca5439..bdcd93995 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/MessageChain.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/MessageChain.kt @@ -464,7 +464,7 @@ public fun Stream.toMessageChain(): MessageChain = this.asSequence().to */ @JvmName("newChain") public suspend fun Flow.toMessageChain(): MessageChain = - buildMessageChain { collect(::add) } + buildMessageChain { collect { add(it) } } /** * 扁平化 [this] 并创建一个 [MessageChain]. diff --git a/mirai-core-api/src/commonTest/kotlin/message.data/MessageUtilsTest.kt b/mirai-core-api/src/commonTest/kotlin/message.data/MessageUtilsTest.kt index 95687f514..45ab6159b 100644 --- a/mirai-core-api/src/commonTest/kotlin/message.data/MessageUtilsTest.kt +++ b/mirai-core-api/src/commonTest/kotlin/message.data/MessageUtilsTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. + * Copyright 2019-2021 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. @@ -8,7 +8,10 @@ */ package net.mamoe.mirai.message.data +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.runBlocking import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -21,4 +24,9 @@ internal class MessageUtilsTest { assertTrue { (PlainText("") + PlainText("")).isContentEmpty() } assertTrue { buildMessageChain { append(PlainText("")); append(PlainText("")) }.isContentEmpty() } } + + @Test + fun `flow toMessageChain`(): Unit = runBlocking { + assertEquals(messageChainOf(PlainText("1")), flowOf(PlainText("1")).toMessageChain()) + } } \ No newline at end of file