From 58b1a4d7e3b405c5fb25e9c1b2fb8c4b2b292dd5 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 1 Mar 2020 14:40:24 +0800 Subject: [PATCH] Reduce code complexity --- .../net/mamoe/mirai/qqandroid/message/messages.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt index 605b600d7..dbddf1bc9 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt @@ -235,7 +235,10 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean): MutableList elements.add(ImMsgBody.Elem(text = ImMsgBody.Text(str = it.stringValue))) - is At -> elements.add(ImMsgBody.Elem(text = it.toJceData())).also { elements.add(ImMsgBody.Elem(text = ImMsgBody.Text(str = " "))) } + is At -> { + elements.add(ImMsgBody.Elem(text = it.toJceData())) + elements.add(ImMsgBody.Elem(text = ImMsgBody.Text(str = " "))) + } is CustomFaceFromFile -> elements.add(ImMsgBody.Elem(customFace = it.toJceData())) is CustomFaceFromServer -> elements.add(ImMsgBody.Elem(customFace = it.delegate)) is NotOnlineImageFromServer -> elements.add(ImMsgBody.Elem(notOnlineImage = it.delegate)) @@ -339,10 +342,10 @@ internal fun MsgComm.Msg.toMessageChain(): MessageChain { internal fun ImMsgBody.SourceMsg.toMessageChain(): MessageChain { val elements = this.elems!! - val message = MessageChainBuilder(elements.size + 1) - message.add(MessageSourceFromServer(delegate = this)) - elements.joinToMessageChain(message) - return message.asMessageChain() + return buildMessageChain(elements.size + 1) { + +MessageSourceFromServer(delegate = this@toMessageChain) + elements.joinToMessageChain(this) + } }