From 5ba10aed31e7ce17ade45d8eed7ff296b36e0fd4 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 26 Dec 2020 16:56:19 +0800 Subject: [PATCH] Fix PbGetMsg, fix #766 --- .../chat/receive/MessageSvc.PbGetMsg.kt | 82 +++++++++---------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt index 7c52757cd..f20577bdf 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbGetMsg.kt @@ -43,8 +43,6 @@ import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket import net.mamoe.mirai.internal.network.protocol.packet.chat.GroupInfoImpl import net.mamoe.mirai.internal.network.protocol.packet.chat.NewContact -import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetMsg.createGroupForBot -import net.mamoe.mirai.internal.network.protocol.packet.chat.receive.MessageSvcPbGetMsg.getNewMemberInfo import net.mamoe.mirai.internal.network.protocol.packet.chat.toLongUnsigned import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList import net.mamoe.mirai.internal.utils.* @@ -122,30 +120,6 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory - if (!bot.client.syncingController.pbGetMessageCacheList.addCache( - QQAndroidClient.MessageSvcSyncData.PbGetMessageSyncId( - uid = msg.msgHead.msgUid, - sequence = msg.msgHead.msgSeq, - time = msg.msgHead.msgTime - ) + .filter { msg -> + bot.client.syncingController.pbGetMessageCacheList.addCache( + QQAndroidClient.MessageSvcSyncData.PbGetMessageSyncId( + uid = msg.msgHead.msgUid, + sequence = msg.msgHead.msgSeq, + time = msg.msgHead.msgTime ) - ) return@mapNotNull null - - // if (msg.msgHead.msgType != 732) msg._miraiContentToString().soutv("MSG") - - msg.transform(bot) + ) } + .flatMapConcat { msg -> + val result = msg.transform(bot) + if (result == null) emptyFlow() else flowOf(result) + } + val list: List = messages.toList() if (resp.syncFlag == MsgSvc.SyncFlag.STOP) { return GetMsgSuccess(list, resp.syncCookie) @@ -246,7 +220,31 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory bot.groupListModifyLock.withLock { @@ -378,17 +376,17 @@ private suspend fun MsgComm.Msg.transform(bot: QQAndroidBot): Packet? { return null } friend.lastMessageSequence.loop { - if (friend.lastMessageSequence.compareAndSet( + return if (friend.lastMessageSequence.compareAndSet( it, msgHead.msgSeq ) && contentHead?.autoReply != 1 ) { - return FriendMessageEvent( + FriendMessageEvent( friend, toMessageChain(bot, groupIdOrZero = 0, onlineSource = true), msgHead.msgTime ) - } else return null + } else null } } 208 -> {