From e686a23f402043bc56f4a5be6ad729b78df1d58c Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Thu, 16 Feb 2023 23:06:23 +0800 Subject: [PATCH] [core] Fix offline message source quote replying; fix #2501 --- .../kotlin/message/protocol/impl/QuoteReplyProtocol.kt | 9 ++++++--- .../message/protocol/impl/QuoteReplyProtocolTest.kt | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt index 62243678e..665ff9d18 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt @@ -10,7 +10,6 @@ package net.mamoe.mirai.internal.message.protocol.impl import net.mamoe.mirai.contact.AnonymousMember -import net.mamoe.mirai.contact.Group import net.mamoe.mirai.internal.message.protocol.MessageProtocol import net.mamoe.mirai.internal.message.protocol.ProcessorCollector import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoder @@ -20,7 +19,6 @@ import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext.Co import net.mamoe.mirai.internal.message.protocol.decode.MessageDecoderContext.Companion.MESSAGE_SOURCE_KIND import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoder import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext -import net.mamoe.mirai.internal.message.protocol.encode.MessageEncoderContext.Companion.contact import net.mamoe.mirai.internal.message.protocol.outgoing.OutgoingMessagePreprocessor import net.mamoe.mirai.internal.message.protocol.serialization.MessageSerializer import net.mamoe.mirai.internal.message.source.* @@ -154,9 +152,11 @@ internal class QuoteReplyProtocol : MessageProtocol(PRIORITY_METADATA) { private class Encoder : MessageEncoder { override suspend fun MessageEncoderContext.process(data: QuoteReply) { val source = data.source as? MessageSourceInternal ?: return + val sourceCommon = source as MessageSource + markAsConsumed() collect(ImMsgBody.Elem(srcMsg = source.toJceData())) - if (contact is Group) { + if (sourceCommon.kind == MessageSourceKind.GROUP) { if (source is OnlineMessageSource.Incoming.FromGroup) { val sender0 = source.sender if (sender0 !is AnonymousMember) { @@ -165,6 +165,9 @@ internal class QuoteReplyProtocol : MessageProtocol(PRIORITY_METADATA) { // transformOneMessage(PlainText(" ")) // removed by https://github.com/mamoe/mirai/issues/524 // 发送 QuoteReply 消息时无可避免的产生多余空格 #524 + } else if (sourceCommon.fromId != 80000000L) { + // https://github.com/mamoe/mirai/issues/2501 OfflineMessageSource quote replying + processAlso(At(sourceCommon.fromId)) } } } diff --git a/mirai-core/src/commonTest/kotlin/message/protocol/impl/QuoteReplyProtocolTest.kt b/mirai-core/src/commonTest/kotlin/message/protocol/impl/QuoteReplyProtocolTest.kt index 49f0ce7c5..fb4df111f 100644 --- a/mirai-core/src/commonTest/kotlin/message/protocol/impl/QuoteReplyProtocolTest.kt +++ b/mirai-core/src/commonTest/kotlin/message/protocol/impl/QuoteReplyProtocolTest.kt @@ -95,6 +95,12 @@ internal class QuoteReplyProtocolTest : AbstractMessageProtocolTest() { // mirai's OfflineMessageSource has no enough information to create 'srcMsg' ), ), + net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem( + text = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Text( + str = "@", + attr6Buf = "00 01 00 00 00 01 00 00 12 C4 B1 00 00".hexToBytes(), + ), + ), net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem( text = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Text( str = "s",