Commit 33b97c21 authored by Him188's avatar Him188

Mark Contacts as data class

parent aeeb3a26
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
package net.mamoe.mirai.contact package net.mamoe.mirai.contact
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred import kotlinx.coroutines.Deferred
import net.mamoe.mirai.Bot import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.data.Profile import net.mamoe.mirai.contact.data.Profile
...@@ -22,6 +23,8 @@ import net.mamoe.mirai.network.BotSession ...@@ -22,6 +23,8 @@ import net.mamoe.mirai.network.BotSession
interface QQ : Contact { interface QQ : Contact {
/** /**
* 用户资料. * 用户资料.
* 第一次获取时将会向服务器查询.
* 第一次以后则是直接得到一个用 [CompletableDeferred] 包装的值
*/ */
val profile: Deferred<Profile> val profile: Deferred<Profile>
......
...@@ -29,7 +29,7 @@ internal sealed class ContactImpl : Contact { ...@@ -29,7 +29,7 @@ internal sealed class ContactImpl : Contact {
} }
@Suppress("MemberVisibilityCanBePrivate", "CanBeParameter") @Suppress("MemberVisibilityCanBePrivate", "CanBeParameter")
internal class GroupImpl internal constructor(override val bot: Bot, val groupId: GroupId) : ContactImpl(), Group { internal data class GroupImpl internal constructor(override val bot: Bot, val groupId: GroupId) : ContactImpl(), Group {
override val id: UInt get() = groupId.value override val id: UInt get() = groupId.value
override val internalId = GroupId(id).toInternalId() override val internalId = GroupId(id).toInternalId()
...@@ -50,7 +50,7 @@ internal class GroupImpl internal constructor(override val bot: Bot, val groupId ...@@ -50,7 +50,7 @@ internal class GroupImpl internal constructor(override val bot: Bot, val groupId
override fun toString(): String = "Group(${this.id})" override fun toString(): String = "Group(${this.id})"
} }
internal class QQImpl internal constructor(override val bot: Bot, override val id: UInt) : ContactImpl(), QQ { internal data class QQImpl internal constructor(override val bot: Bot, override val id: UInt) : ContactImpl(), QQ {
private var _profile: Profile? = null private var _profile: Profile? = null
private val _initialProfile by bot.network.SuspendLazy { updateProfile() } private val _initialProfile by bot.network.SuspendLazy { updateProfile() }
...@@ -59,10 +59,6 @@ internal class QQImpl internal constructor(override val bot: Bot, override val i ...@@ -59,10 +59,6 @@ internal class QQImpl internal constructor(override val bot: Bot, override val i
override suspend fun sendMessage(message: MessageChain) = override suspend fun sendMessage(message: MessageChain) =
bot.sendPacket(SendFriendMessagePacket(bot.qqAccount, id, bot.sessionKey, message)) bot.sendPacket(SendFriendMessagePacket(bot.qqAccount, id, bot.sessionKey, message))
/**
* 更新个人资料.
* 将会同步更新 property [profile]
*/
override suspend fun updateProfile(): Profile = bot.withSession { override suspend fun updateProfile(): Profile = bot.withSession {
_profile = RequestProfileDetailsPacket(bot.qqAccount, id, sessionKey) _profile = RequestProfileDetailsPacket(bot.qqAccount, id, sessionKey)
.sendAndExpect<RequestProfileDetailsResponse, Profile> { it.profile } .sendAndExpect<RequestProfileDetailsResponse, Profile> { it.profile }
...@@ -76,7 +72,7 @@ internal class QQImpl internal constructor(override val bot: Bot, override val i ...@@ -76,7 +72,7 @@ internal class QQImpl internal constructor(override val bot: Bot, override val i
/** /**
* 群成员 * 群成员
*/ */
internal class MemberImpl(override val bot: Bot, private val delegate: QQ, override val group: Group) : Member, ContactImpl() { internal data class MemberImpl(override val bot: Bot, private val delegate: QQ, override val group: Group) : Member, ContactImpl() {
override val profile: Deferred<Profile> get() = delegate.profile override val profile: Deferred<Profile> get() = delegate.profile
override val id: UInt get() = delegate.id override val id: UInt get() = delegate.id
......
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