From 736f52275fa822add9603f64845da46117a2ca73 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Tue, 16 Nov 2021 22:12:02 +0800 Subject: [PATCH] Drop InternalFlag in MessageReceipt --- .../commonMain/kotlin/message/MessageSourceInternal.kt | 6 ++++-- .../src/commonMain/kotlin/message/RefinableMessage.kt | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/message/MessageSourceInternal.kt b/mirai-core/src/commonMain/kotlin/message/MessageSourceInternal.kt index 3eb674c69..d02b7a354 100644 --- a/mirai-core/src/commonMain/kotlin/message/MessageSourceInternal.kt +++ b/mirai-core/src/commonMain/kotlin/message/MessageSourceInternal.kt @@ -12,11 +12,11 @@ package net.mamoe.mirai.internal.message import kotlinx.serialization.Transient import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.internal.contact.SendMessageHandler +import net.mamoe.mirai.internal.message.LightMessageRefiner.dropMiraiInternalFlags import net.mamoe.mirai.internal.message.LightMessageRefiner.refineLight import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody import net.mamoe.mirai.message.MessageReceipt import net.mamoe.mirai.message.data.* -import net.mamoe.mirai.utils.cast import java.util.concurrent.atomic.AtomicBoolean @@ -80,7 +80,9 @@ internal fun OnlineMessageSource.Outgoing.createMessageReceipt( ): MessageReceipt { if (doLightRefine) { check(this is OutgoingMessageSourceInternal) { "Internal error: source !is OutgoingMessageSourceInternal" } - this.originalMessage = this.originalMessage.refineLight(bot) + this.originalMessage = this.originalMessage + .dropMiraiInternalFlags() + .refineLight(bot) } return MessageReceipt(this, target) } diff --git a/mirai-core/src/commonMain/kotlin/message/RefinableMessage.kt b/mirai-core/src/commonMain/kotlin/message/RefinableMessage.kt index f27e32e3b..5f974f4b9 100644 --- a/mirai-core/src/commonMain/kotlin/message/RefinableMessage.kt +++ b/mirai-core/src/commonMain/kotlin/message/RefinableMessage.kt @@ -166,6 +166,15 @@ internal object LightMessageRefiner : MessageRefiner() { ): MessageChain { return refineImpl(bot) { it.tryRefine(bot, this, refineContext) } } + + /** + * 去除 [MessageChain] 携带的内部标识 + * + * 用于 [createMessageReceipt] <- `RemoteFile.uploadAndSend` (文件操作API v1) + */ + fun MessageChain.dropMiraiInternalFlags(): MessageChain { + return asSequence().filterNot { it is InternalFlagOnlyMessage }.toMessageChain() + } } /**