Просмотр исходного кода

Rename `delegate` to `mutable`

Him188 6 лет назад
Родитель
Сommit
a5853ba28a

+ 11 - 11
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/contact/Contact.kt

@@ -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 列表的字符串表示.
      * 如:
@@ -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() }
 
-    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<MutableMap.MutableEntry<UInt, C>> get() = delegate.entries
-    override val keys: MutableSet<UInt> get() = delegate.keys
-    override val values: MutableCollection<C> 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<MutableMap.MutableEntry<UInt, C>> get() = mutable.entries
+    override val keys: MutableSet<UInt> get() = mutable.keys
+    override val values: MutableCollection<C> get() = mutable.values
 }
 
 /**
@@ -93,7 +93,7 @@ internal class MutableContactList<C : Contact> : MutableMap<UInt, C> {
 
 
     // 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 fun containsKey(key: UInt): Boolean = delegate.containsKey(key)

+ 4 - 4
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<RawGroupInfo>().parseBy(this@GroupImpl)
+        GroupPacket.QueryGroupInfo(qqAccount, internalId, sessionKey).sendAndExpect<RawGroupInfo>().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<MemberJoinEventPacket> {
             // FIXME: 2019/11/29 非线程安全!!
-            members.delegate[it.member.id] = it.member
+            members.mutable[it.member.id] = it.member
         }
         subscribeAlways<MemberQuitEvent> {
             // 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<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(),