Fix Flow<Message>.toMessageChain

This commit is contained in:
Him188 2021-06-20 01:36:32 +08:00
parent 8840ba9e6f
commit 415f133cbc
2 changed files with 10 additions and 2 deletions

View File

@ -464,7 +464,7 @@ public fun Stream<Message>.toMessageChain(): MessageChain = this.asSequence().to
*/
@JvmName("newChain")
public suspend fun Flow<Message>.toMessageChain(): MessageChain =
buildMessageChain { collect(::add) }
buildMessageChain { collect { add(it) } }
/**
* 扁平化 [this] 并创建一个 [MessageChain].

View File

@ -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())
}
}