Commit 43cb22e0 authored by Him188's avatar Him188

Remove MutableContactList

parent c4b42a31
......@@ -106,11 +106,9 @@ internal class BotImpl @PublishedApi internal constructor(
// endregion
// region contacts
@UseExperimental(MiraiInternalAPI::class)
override val groups: ContactList<Group> = ContactList(MutableContactList())
override val groups: ContactList<Group> = ContactList(LockFreeLinkedList())
@UseExperimental(MiraiInternalAPI::class)
override val qqs: ContactList<QQ> = ContactList(MutableContactList())
override val qqs: ContactList<QQ> = ContactList(LockFreeLinkedList())
/**
* 线程安全地获取缓存的 QQ 对象. 若没有对应的缓存, 则会创建一个.
......
......@@ -12,7 +12,7 @@ import net.mamoe.mirai.utils.joinToString
*/
@UseExperimental(MiraiInternalAPI::class)
@Suppress("unused")
class ContactList<C : Contact>(@PublishedApi internal val delegate: MutableContactList<C>) {
class ContactList<C : Contact>(@PublishedApi internal val delegate: LockFreeLinkedList<C>) {
/**
* ID 列表的字符串表示.
* 如:
......@@ -35,22 +35,14 @@ class ContactList<C : Contact>(@PublishedApi internal val delegate: MutableConta
override fun toString(): String = delegate.joinToString(separator = ", ", prefix = "ContactList(", postfix = ")")
}
/**
* 可修改联系人列表. 只会在内部使用.
*/
@MiraiInternalAPI
class MutableContactList<C : Contact> : LockFreeLinkedList<C>() {
override fun toString(): String = joinToString(separator = ", ", prefix = "MutableContactList(", postfix = ")")
operator fun get(id: UInt): C {
forEach { if (it.id == id) return it }
throw NoSuchElementException()
}
fun getOrNull(id: UInt): C? {
forEach { if (it.id == id) return it }
return null
}
fun getOrAdd(id: UInt, supplier: () -> C): C = super.filteringGetOrAdd({it.id == id}, supplier)
}
\ No newline at end of file
operator fun <C : Contact> LockFreeLinkedList<C>.get(id: UInt): C {
forEach { if (it.id == id) return it }
throw NoSuchElementException()
}
fun <C : Contact> LockFreeLinkedList<C>.getOrNull(id: UInt): C? {
forEach { if (it.id == id) return it }
return null
}
fun <C : Contact> LockFreeLinkedList<C>.getOrAdd(id: UInt, supplier: () -> C): C = filteringGetOrAdd({ it.id == id }, supplier)
......@@ -10,6 +10,7 @@ import net.mamoe.mirai.message.internal.toPacket
import net.mamoe.mirai.network.BotNetworkHandler
import net.mamoe.mirai.network.protocol.tim.TIMProtocol
import net.mamoe.mirai.network.protocol.tim.packet.*
import net.mamoe.mirai.utils.LockFreeLinkedList
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.io.*
import net.mamoe.mirai.withSession
......@@ -54,7 +55,7 @@ internal data class RawGroupInfo(
@Suppress("NOTHING_TO_INLINE") // this function it only executed in one place.
@UseExperimental(MiraiInternalAPI::class)
inline fun parseBy(group: Group): GroupInfo = group.bot.withSession {
val memberList = MutableContactList<Member>()
val memberList = LockFreeLinkedList<Member>()
members.forEach { entry: Map.Entry<UInt, MemberPermission> ->
entry.key.qq().let { group.Member(it, entry.value, it.coroutineContext) }
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment