From 49522fb5d38712168d116d2b76369e7183b18edb Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 29 Jan 2021 10:43:54 +0800 Subject: [PATCH] Make UserProfile impl data class --- .../src/commonMain/kotlin/data/UserProfile.kt | 7 ++-- .../packet/summarycard/SummaryCard.kt | 34 +++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/mirai-core-api/src/commonMain/kotlin/data/UserProfile.kt b/mirai-core-api/src/commonMain/kotlin/data/UserProfile.kt index 70cc2daff..f1d146ab1 100644 --- a/mirai-core-api/src/commonMain/kotlin/data/UserProfile.kt +++ b/mirai-core-api/src/commonMain/kotlin/data/UserProfile.kt @@ -9,12 +9,15 @@ package net.mamoe.mirai.data -import net.mamoe.mirai.utils.MiraiExperimentalApi +import net.mamoe.mirai.contact.User /** * 用户详细资料 + * + * @see User.queryProfile + * @suppress 使用这个接口是稳定的,但继承不稳定。将来可能会有新的属性添加。 + * @since 2.1 */ -@MiraiExperimentalApi public interface UserProfile { public val nickname: String public val email: String diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/summarycard/SummaryCard.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/summarycard/SummaryCard.kt index a2a3d59f3..ce383d174 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/summarycard/SummaryCard.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/summarycard/SummaryCard.kt @@ -21,33 +21,31 @@ import net.mamoe.mirai.internal.network.protocol.data.jce.RequestPacket import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacket import net.mamoe.mirai.internal.network.protocol.packet.OutgoingPacketFactory import net.mamoe.mirai.internal.network.protocol.packet.buildOutgoingUniPacket -import net.mamoe.mirai.internal.utils._miraiContentToString import net.mamoe.mirai.internal.utils.io.serialization.jceRequestSBuffer import net.mamoe.mirai.internal.utils.io.serialization.readJceStruct import net.mamoe.mirai.internal.utils.io.serialization.tars.Tars import net.mamoe.mirai.internal.utils.io.serialization.writeJceStruct -import net.mamoe.mirai.internal.utils.soutv import net.mamoe.mirai.utils.read import net.mamoe.mirai.internal.network.protocol.data.jce.ReqSummaryCard as JceReqSummaryCard import net.mamoe.mirai.internal.network.protocol.data.jce.RespSummaryCard as JceRespSummaryCard +internal data class UserProfileImpl( + override val nickname: String, + override val email: String, + override val age: Int, + override val qLevel: Int, + override val sex: UserProfile.Sex, + override val sign: String, +) : Packet, UserProfile { + override fun toString(): String { + return "UserProfile(nickname=$nickname, email=$email, age=$age, qLevel=$qLevel, sex=$sex, sign=$sign)" + } +} + internal object SummaryCard { - internal object ReqSummaryCard : OutgoingPacketFactory( + internal object ReqSummaryCard : OutgoingPacketFactory( "SummaryCard.ReqSummaryCard" ) { - internal class RespSummaryCard( - override val nickname: String, - override val email: String, - override val age: Int, - override val qLevel: Int, - override val sex: UserProfile.Sex, - override val sign: String, - ) : Packet, UserProfile { - override fun toString(): String { - return "SummaryCard.RespSummaryCard(nickname=$nickname, email=$email, age=$age, qLevel=$qLevel, sex=$sex, sign=$sign)" - } - } - operator fun invoke( client: QQAndroidClient, uin: Long, @@ -83,7 +81,7 @@ internal object SummaryCard { ) } - override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): RespSummaryCard { + override suspend fun ByteReadPacket.decode(bot: QQAndroidBot): UserProfileImpl { val fullMap = readJceStruct( RequestPacket.serializer() ).sBuffer.read { @@ -97,7 +95,7 @@ internal object SummaryCard { discardExact(1) Tars.UTF_8.load(JceRespSummaryCard.serializer(), this) } - return RespSummaryCard( + return UserProfileImpl( nickname = response.nick ?: "", email = response.email ?: "", age = response.age?.let { it.toInt() and 0xFF } ?: -1,