Skip to content

Commit

Permalink
[core] Fix offline message source quote replying; fix #2501
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlatemp committed Feb 16, 2023
1 parent d8ef9ad commit e686a23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.*
Expand Down Expand Up @@ -154,9 +152,11 @@ internal class QuoteReplyProtocol : MessageProtocol(PRIORITY_METADATA) {
private class Encoder : MessageEncoder<QuoteReply> {
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) {
Expand All @@ -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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e686a23

Please sign in to comment.