Drop InternalFlag in MessageReceipt

This commit is contained in:
Karlatemp 2021-11-16 22:12:02 +08:00
parent bd041e43d1
commit 736f52275f
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
2 changed files with 13 additions and 2 deletions

View File

@ -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 <C : Contact> OnlineMessageSource.Outgoing.createMessageReceipt(
): MessageReceipt<C> {
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)
}

View File

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