Skip to content

Commit

Permalink
[core] add stub elem to let FileMessageProtocol works properly
Browse files Browse the repository at this point in the history
  • Loading branch information
StageGuard committed Sep 1, 2023
1 parent 02c7086 commit 6a5925f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ internal class AudioProtocol : MessageProtocol() {
.getOrNull() ?: return

val ptt = originalMsg.msgBody.richText.ptt ?: return
if (collected.data.find { it is OnlineAudioImpl } != null) return // audio is ConstrainSingle

collect(OnlineAudioImpl(
filename = ptt.fileName.decodeToString(),
fileMd5 = ptt.fileMd5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ import net.mamoe.mirai.event.Event
import net.mamoe.mirai.event.events.*
import net.mamoe.mirai.internal.contact.*
import net.mamoe.mirai.internal.getGroupByUinOrCode
import net.mamoe.mirai.internal.message.ReceiveMessageTransformer
import net.mamoe.mirai.internal.message.RefineContextKey
import net.mamoe.mirai.internal.message.SimpleRefineContext
import net.mamoe.mirai.internal.message.data.FriendFileMessageImpl
import net.mamoe.mirai.internal.message.toMessageChainOnline
import net.mamoe.mirai.internal.network.Packet
import net.mamoe.mirai.internal.network.QQAndroidClient
import net.mamoe.mirai.internal.network.components.NoticePipelineContext
import net.mamoe.mirai.internal.network.components.NoticePipelineContext.Companion.KEY_FROM_SYNC
import net.mamoe.mirai.internal.network.components.NoticePipelineContext.Companion.fromSync
Expand All @@ -30,13 +27,9 @@ import net.mamoe.mirai.internal.network.components.SsoProcessor
import net.mamoe.mirai.internal.network.notice.group.GroupMessageProcessor
import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
import net.mamoe.mirai.internal.network.protocol.data.proto.SubMsgType0x4
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
import net.mamoe.mirai.internal.utils.io.serialization.loadAs
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.MessageSourceKind
import net.mamoe.mirai.message.data.buildMessageChain
import net.mamoe.mirai.message.data.toMessageChain
import net.mamoe.mirai.utils.assertUnreachable
import net.mamoe.mirai.utils.context

Expand Down Expand Up @@ -132,7 +125,26 @@ internal class PrivateMessageProcessor : SimpleNoticeProcessor<MsgComm.Msg>(type
-> {
val content = msgBody.msgContent
if (content.isEmpty()) return
handlePrivateMessage(data, bot.getFriend(senderUin)?.impl() ?: return)

// msgBody.richText.elems is empty when received friend file message
// In order to let the decoder at FileMessageProtocol in MessageProtocolFacade works,
// we put a fake(stub) elem which all message protocols ignore
val copiedData = MsgComm.Msg(
msgHead, contentHead, ImMsgBody.MsgBody(
ImMsgBody.RichText(
attr = data.msgBody.richText.attr,
elems = listOf(ImMsgBody.Elem()),
notOnlineFile = data.msgBody.richText.notOnlineFile,
ptt = data.msgBody.richText.ptt,
tmpPtt = data.msgBody.richText.tmpPtt,
trans211TmpMsg = data.msgBody.richText.trans211TmpMsg,
),
data.msgBody.msgContent,
data.msgBody.msgEncryptContent
), appshareInfo
)

handlePrivateMessage(copiedData, bot.getFriend(senderUin)?.impl() ?: return)
}

else -> markNotConsumed()
Expand Down

0 comments on commit 6a5925f

Please sign in to comment.