mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-13 06:30:13 +08:00
Add sequence cache to filter duplicated events, fix #221
This commit is contained in:
parent
16d6c56202
commit
0dfea0698c
@ -131,6 +131,7 @@ internal open class QQAndroidClient(
|
||||
internal fun nextHighwayDataTransSequenceIdForApplyUp(): Int = highwayDataTransSequenceIdForApplyUp.getAndAdd(2)
|
||||
|
||||
internal val onlinePushCacheList: LockFreeLinkedList<Short> = LockFreeLinkedList()
|
||||
internal val pbPushTransMsgCacheList: LockFreeLinkedList<Int> = LockFreeLinkedList()
|
||||
|
||||
val appClientVersion: Int = 0
|
||||
|
||||
|
@ -123,6 +123,14 @@ internal class OnlinePush {
|
||||
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): Packet? {
|
||||
val content = this.readProtoBuf(OnlinePushTrans.PbMsgInfo.serializer())
|
||||
|
||||
val cache = bot.client.pbPushTransMsgCacheList.removeUntilFirst { it == content.msgSeq }
|
||||
if (cache == null) {
|
||||
bot.client.pbPushTransMsgCacheList.addLast(content.msgSeq)
|
||||
} else {
|
||||
bot.client.pbPushTransMsgCacheList.remove(cache)
|
||||
return null
|
||||
}
|
||||
|
||||
content.msgData.read<Unit> {
|
||||
when (content.msgType) {
|
||||
44 -> {
|
||||
@ -237,17 +245,6 @@ internal class OnlinePush {
|
||||
}.flatMap { it.vMsg.read { mapper(it) } }
|
||||
}
|
||||
|
||||
private inline fun LockFreeLinkedList<Short>.removeUntilFirst(block: (Short) -> Boolean): Short? {
|
||||
this.forEach {
|
||||
if (!block(it)) {
|
||||
this.remove(it)
|
||||
} else {
|
||||
return it
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun lambda732(block: ByteReadPacket.(group: GroupImpl, bot: QQAndroidBot) -> Sequence<Packet>):
|
||||
ByteReadPacket.(group: GroupImpl, bot: QQAndroidBot) -> Sequence<Packet> {
|
||||
return block
|
||||
@ -514,7 +511,7 @@ internal class OnlinePush {
|
||||
?.let { processor -> processor(notifyMsgBody, bot) }
|
||||
?: kotlin.run {
|
||||
bot.network.logger.debug {
|
||||
"unknown group 528 type ${notifyMsgBody.uSubMsgType}, data: " + notifyMsgBody.vProtobuf.toUHexString()
|
||||
"unknown group 528 type 0x${notifyMsgBody.uSubMsgType.toUHexString("")}, data: " + notifyMsgBody.vProtobuf.toUHexString()
|
||||
}
|
||||
return@deco emptySequence()
|
||||
}
|
||||
@ -572,4 +569,16 @@ internal class OnlinePush {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <E> LockFreeLinkedList<E>.removeUntilFirst(block: (E) -> Boolean): E? {
|
||||
this.forEach {
|
||||
if (!block(it)) {
|
||||
this.remove(it)
|
||||
} else {
|
||||
return it
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user