Commit a5853ba2 authored by Him188's avatar Him188

Rename `delegate` to `mutable`

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