mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 03:22:36 +08:00
Introduce common SyncingCacheList
This commit is contained in:
parent
1717501d85
commit
247a37da42
@ -14,13 +14,13 @@ package net.mamoe.mirai.qqandroid.network
|
||||
import kotlinx.atomicfu.AtomicBoolean
|
||||
import kotlinx.atomicfu.AtomicInt
|
||||
import kotlinx.atomicfu.atomic
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.io.core.*
|
||||
import net.mamoe.mirai.data.OnlineStatus
|
||||
import net.mamoe.mirai.network.LoginFailedException
|
||||
import net.mamoe.mirai.network.NoServerAvailableException
|
||||
import net.mamoe.mirai.qqandroid.BotAccount
|
||||
import net.mamoe.mirai.qqandroid.QQAndroidBot
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.SyncingCacheList
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.data.jce.FileStoragePushFSSvcListFuckKotlin
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.EMPTY_BYTE_ARRAY
|
||||
import net.mamoe.mirai.qqandroid.network.protocol.packet.PacketLogger
|
||||
@ -206,7 +206,7 @@ internal open class QQAndroidClient(
|
||||
*/
|
||||
val protocolVersion: Short = 8001
|
||||
|
||||
class C2cMessageSyncData {
|
||||
class MessageSvcSyncData {
|
||||
val firstNotify: AtomicBoolean = atomic(true)
|
||||
|
||||
@Volatile
|
||||
@ -215,17 +215,17 @@ internal open class QQAndroidClient(
|
||||
var msgCtrlBuf: ByteArray = EMPTY_BYTE_ARRAY
|
||||
|
||||
|
||||
internal data class SyncPacketIdentifier(
|
||||
internal data class PbGetMessageSyncId(
|
||||
val uid: Long,
|
||||
val sequence: Int,
|
||||
val time: Int
|
||||
)
|
||||
|
||||
val packetIdList = LinkedList<SyncPacketIdentifier>()
|
||||
val packetIdListLock = Mutex()
|
||||
val pbGetMessageCacheList = SyncingCacheList<PbGetMessageSyncId>()
|
||||
val systemMsgNewGroupCacheList = SyncingCacheList<PbGetMessageSyncId>()
|
||||
}
|
||||
|
||||
val c2cMessageSync = C2cMessageSyncData()
|
||||
val c2cMessageSync = MessageSvcSyncData()
|
||||
|
||||
/*
|
||||
* 以下登录使用
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright 2020 Mamoe Technologies and contributors.
|
||||
* *
|
||||
* * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
* *
|
||||
* * https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.qqandroid.network.protocol
|
||||
|
||||
import net.mamoe.mirai.qqandroid.utils.LinkedList
|
||||
import kotlin.jvm.Synchronized
|
||||
|
||||
internal class SyncingCacheList<E>(private val size: Int = 50) {
|
||||
private val packetIdList = LinkedList<E>()
|
||||
|
||||
@Synchronized // faster than suspending Mutex
|
||||
fun addCache(element: E): Boolean {
|
||||
if (packetIdList.contains(element)) return false // duplicate
|
||||
packetIdList.addLast(element)
|
||||
if (packetIdList.size >= size) packetIdList.removeFirst()
|
||||
return true
|
||||
}
|
||||
}
|
@ -191,20 +191,14 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
|
||||
MessageSvcPbDeleteMsg.delete(bot, it) // 删除消息
|
||||
}
|
||||
.mapNotNull { msg ->
|
||||
|
||||
bot.client.c2cMessageSync.run {
|
||||
val identifier = QQAndroidClient.C2cMessageSyncData.SyncPacketIdentifier(
|
||||
uid = msg.msgHead.msgUid,
|
||||
sequence = msg.msgHead.msgSeq,
|
||||
time = msg.msgHead.msgTime
|
||||
if (!bot.client.c2cMessageSync.pbGetMessageCacheList.addCache(
|
||||
QQAndroidClient.MessageSvcSyncData.PbGetMessageSyncId(
|
||||
uid = msg.msgHead.msgUid,
|
||||
sequence = msg.msgHead.msgSeq,
|
||||
time = msg.msgHead.msgTime
|
||||
)
|
||||
)
|
||||
|
||||
packetIdListLock.withLock {
|
||||
if (packetIdList.contains(identifier)) return@mapNotNull null // duplicate
|
||||
packetIdList.addLast(identifier)
|
||||
if (packetIdList.size >= 50) packetIdList.removeFirst()
|
||||
}
|
||||
}
|
||||
) return@mapNotNull null
|
||||
|
||||
when (msg.msgHead.msgType) {
|
||||
33 -> bot.groupListModifyLock.withLock {
|
||||
|
Loading…
Reference in New Issue
Block a user