Skip to content

Commit

Permalink
Drop InternalFlag in MessageReceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlatemp authored and Him188 committed Nov 16, 2021
1 parent 8654908 commit 256ab60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions mirai-core/src/commonMain/kotlin/message/RefinableMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

/**
Expand Down

0 comments on commit 256ab60

Please sign in to comment.