mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-04 15:40:13 +08:00
Merge branch 'remark' into dev
# Conflicts: # mirai-core/src/commonMain/kotlin/contact/FriendImpl.kt
This commit is contained in:
commit
d3f6b3ce33
@ -48,6 +48,10 @@ public abstract class Friend : User(), CoroutineScope {
|
||||
* 昵称
|
||||
*/
|
||||
public abstract override val nick: String
|
||||
/**
|
||||
* 好友备注
|
||||
*/
|
||||
public abstract val remark: String
|
||||
|
||||
/**
|
||||
* 头像下载链接
|
||||
|
@ -16,4 +16,6 @@ public interface FriendInfo {
|
||||
public val uin: Long
|
||||
|
||||
public val nick: String
|
||||
|
||||
public val remark: String
|
||||
}
|
@ -33,8 +33,16 @@ import kotlin.jvm.*
|
||||
*/
|
||||
public data class FriendRemarkChangeEvent internal constructor(
|
||||
public override val friend: Friend,
|
||||
public val newName: String
|
||||
) : FriendEvent, Packet, AbstractEvent()
|
||||
public val oldRemark: String,
|
||||
public val newRemark: String
|
||||
) : FriendEvent, Packet, AbstractEvent() {
|
||||
@Deprecated(
|
||||
message = "Please use newRemark",
|
||||
replaceWith = ReplaceWith("newRemark"),
|
||||
level = DeprecationLevel.WARNING
|
||||
)
|
||||
val newName: String get() = newRemark
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功添加了一个新好友的事件
|
||||
|
@ -290,6 +290,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
_lowLevelNewFriend(object : FriendInfo {
|
||||
override val uin: Long get() = this@QQAndroidBotBase.id
|
||||
override val nick: String get() = this@QQAndroidBotBase.nick
|
||||
override val remark: String get() = nick
|
||||
})
|
||||
}
|
||||
|
||||
@ -798,6 +799,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
bot.friends.delegate.addLast(bot._lowLevelNewFriend(object : FriendInfo {
|
||||
override val uin: Long get() = fromId
|
||||
override val nick: String get() = fromNick
|
||||
override val remark: String get() = nick
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -853,6 +855,7 @@ internal abstract class QQAndroidBotBase constructor(
|
||||
override val muteTimestamp: Int get() = 0
|
||||
override val uin: Long get() = fromId
|
||||
override val nick: String get() = fromNick
|
||||
override val remark: String get() = fromNick
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -56,9 +56,22 @@ import kotlin.time.measureTime
|
||||
internal class FriendInfoImpl(
|
||||
@JvmField private val jceFriendInfo: net.mamoe.mirai.internal.network.protocol.data.jce.FriendInfo
|
||||
) : FriendInfo {
|
||||
@JvmField internal var cachedNick: String? = null
|
||||
@JvmField
|
||||
var cachedNick: String? = null
|
||||
override val nick: String get() = cachedNick ?: jceFriendInfo.nick.also { cachedNick = it }
|
||||
override val uin: Long get() = jceFriendInfo.friendUin
|
||||
@JvmField
|
||||
var cachedRemark: String? = null
|
||||
override val remark: String get() = cachedRemark ?: jceFriendInfo.remark.also { cachedRemark = it }
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
internal inline fun FriendInfo.checkIsInfoImpl(): FriendInfoImpl {
|
||||
contract {
|
||||
returns() implies (this@checkIsInfoImpl is FriendInfoImpl)
|
||||
}
|
||||
check(this is FriendInfoImpl) { "A Friend instance is not instance of FriendImpl. Don't interlace two protocol implementations together!" }
|
||||
return this
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalContracts::class)
|
||||
@ -84,6 +97,8 @@ internal class FriendImpl(
|
||||
override val bot: QQAndroidBot by bot.unsafeWeakRef()
|
||||
override val nick: String
|
||||
get() = friendInfo.nick
|
||||
override val remark: String
|
||||
get() = friendInfo.remark
|
||||
|
||||
@JvmSynthetic
|
||||
@Suppress("DuplicatedCode")
|
||||
|
@ -266,6 +266,7 @@ internal class GroupImpl(
|
||||
override val muteTimestamp = 0
|
||||
override val uin = 80000000L
|
||||
override val nick = name
|
||||
override val remark: String = "匿名"
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -270,4 +270,5 @@ internal class MemberInfoImpl(
|
||||
}
|
||||
override val specialTitle: String = jceInfo.sSpecialTitle ?: ""
|
||||
override val muteTimestamp: Int = jceInfo.dwShutupTimestap?.toInt() ?: 0
|
||||
override val remark: String = jceInfo.nick
|
||||
}
|
||||
|
@ -130,6 +130,7 @@ internal object MessageSvcPbGetMsg : OutgoingPacketFactory<MessageSvcPbGetMsg.Re
|
||||
override val uin: Long get() = msgHead.authUin
|
||||
override val nick: String = msgHead.authNick.takeIf { it.isNotEmpty() }
|
||||
?: msgHead.fromNick
|
||||
override val remark: String get() = nick
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,6 +138,8 @@ internal object OnlinePushPbPushTransMsg :
|
||||
get() = to
|
||||
override val nick: String
|
||||
get() = ""
|
||||
override val remark: String
|
||||
get() = ""
|
||||
}).also { owner ->
|
||||
owner.checkIsMemberImpl().permission = MemberPermission.OWNER
|
||||
group.members.delegate.addLast(owner)
|
||||
|
@ -80,6 +80,7 @@ internal object OnlinePushReqPush : IncomingPacketFactory<OnlinePushReqPush.ReqP
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override suspend fun ByteReadPacket.decode(bot: QQAndroidBot, sequenceId: Int): ReqPushDecoded {
|
||||
val reqPushMsg = readUniPacket(OnlinePushPack.SvcReqPushMsg.serializer(), "req")
|
||||
// bot.network.logger.debug { reqPushMsg._miraiContentToString() }
|
||||
|
||||
val packets: Sequence<Packet> = reqPushMsg.vMsgInfos.deco(bot.client) { msgInfo ->
|
||||
when (msgInfo.shMsgType.toInt()) {
|
||||
@ -283,7 +284,7 @@ private object Transformers732 : Map<Int, Lambda732> by mapOf(
|
||||
0x10 to lambda732 { group: GroupImpl, bot: QQAndroidBot ->
|
||||
val dataBytes = readBytes(26)
|
||||
|
||||
when (dataBytes[0].toInt()) {
|
||||
when (dataBytes[0].toInt() and 0xFF) {
|
||||
59 -> { // TODO 应该在 Transformers528 处理
|
||||
val size = readByte().toInt() // orthodox, don't `readUByte`
|
||||
if (size < 0) {
|
||||
@ -458,6 +459,7 @@ internal object Transformers528 : Map<Long, Lambda528> by mapOf(
|
||||
val new = bot._lowLevelNewFriend(object : FriendInfo {
|
||||
override val uin: Long get() = body.msgAddFrdNotify.fuin
|
||||
override val nick: String get() = body.msgAddFrdNotify.fuinNick
|
||||
override val remark: String get() = ""
|
||||
})
|
||||
bot.friends.delegate.addLast(new)
|
||||
return@lambda528 sequenceOf(FriendAddEvent(new))
|
||||
@ -563,8 +565,12 @@ internal object Transformers528 : Map<Long, Lambda528> by mapOf(
|
||||
fun ModFriendRemark.transform(bot: QQAndroidBot): Sequence<Packet> {
|
||||
return this.msgFrdRmk?.asSequence()?.mapNotNull {
|
||||
val friend = bot.getFriendOrNull(it.fuin) ?: return@mapNotNull null
|
||||
val old: String
|
||||
friend.checkIsFriendImpl().friendInfo.checkIsInfoImpl()
|
||||
.also { info -> old = info.remark }
|
||||
.cachedRemark = it.rmkName
|
||||
// TODO: 2020/4/10 ADD REMARK QUERY
|
||||
FriendRemarkChangeEvent(friend, it.rmkName)
|
||||
FriendRemarkChangeEvent(friend, old, it.rmkName)
|
||||
} ?: emptySequence()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user