diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt index ea9ab3ae3..efd008f8f 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt @@ -59,7 +59,7 @@ inline fun Contact.withSession(block: BotSession.() -> R): R { /** * 只读联系人列表 */ -class ContactList @PublishedApi internal constructor(internal val delegate: MutableContactList) : Map { +class ContactList @PublishedApi internal constructor(internal val mutable: MutableContactList) : Map { /** * ID 列表的字符串表示. * 如: @@ -69,19 +69,19 @@ class ContactList @PublishedApi internal constructor(internal val d */ val idContentString: String get() = this.keys.joinToString(prefix = "[", postfix = "]") { it.toLong().toString() } - override fun toString(): String = delegate.toString() + override fun toString(): String = mutable.toString() // TODO: 2019/12/2 应该使用属性代理, 但属性代理会导致 UInt 内联错误. 等待 kotlin 修复后替换 - override val size: Int get() = delegate.size - override fun containsKey(key: UInt): Boolean = delegate.containsKey(key) - override fun containsValue(value: C): Boolean = delegate.containsValue(value) - override fun get(key: UInt): C? = delegate[key] - override fun isEmpty(): Boolean = delegate.isEmpty() - override val entries: MutableSet> get() = delegate.entries - override val keys: MutableSet get() = delegate.keys - override val values: MutableCollection get() = delegate.values + override val size: Int get() = mutable.size + override fun containsKey(key: UInt): Boolean = mutable.containsKey(key) + override fun containsValue(value: C): Boolean = mutable.containsValue(value) + override fun get(key: UInt): C? = mutable[key] + override fun isEmpty(): Boolean = mutable.isEmpty() + override val entries: MutableSet> get() = mutable.entries + override val keys: MutableSet get() = mutable.keys + override val values: MutableCollection get() = mutable.values } /** @@ -93,7 +93,7 @@ internal class MutableContactList : MutableMap { // TODO: 2019/12/2 应该使用属性代理, 但属性代理会导致 UInt 内联错误. 等待 kotlin 修复后替换 - private val delegate = mutableMapOf() + private val delegate = linkedMapOf() override val size: Int get() = delegate.size override fun containsKey(key: UInt): Boolean = delegate.containsKey(key) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt index a85024334..1b0a492bd 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/internal/ContactImpl.kt @@ -73,7 +73,7 @@ internal data class GroupImpl internal constructor(override val bot: Bot, val gr } override suspend fun updateGroupInfo(): GroupInfo = bot.withSession { - GroupPacket.QueryGroupInfo(qqAccount, internalId, sessionKey).sendAndExpect().parseBy(this@GroupImpl) + GroupPacket.QueryGroupInfo(qqAccount, internalId, sessionKey).sendAndExpect().parseBy(this@GroupImpl).also { info = it } } override suspend fun quit(): QuitGroupResponse = bot.withSession { @@ -84,17 +84,17 @@ internal data class GroupImpl internal constructor(override val bot: Bot, val gr override suspend fun CoroutineContext.startUpdater() { subscribeAlways { // FIXME: 2019/11/29 非线程安全!! - members.delegate[it.member.id] = it.member + members.mutable[it.member.id] = it.member } subscribeAlways { // FIXME: 2019/11/29 非线程安全!! - members.delegate.remove(it.member.id) + members.mutable.remove(it.member.id) } } override fun toString(): String = "Group(${this.id})" - override fun iterator(): Iterator = members.delegate.values.iterator() + override fun iterator(): Iterator = members.values.iterator() } internal data class QQImpl internal constructor(override val bot: Bot, override val id: UInt, override val coroutineContext: CoroutineContext) : ContactImpl(),