Rename getQQ to getFriend Add deprecation message

This commit is contained in:
Him188 2020-02-03 14:25:19 +08:00
parent 102da76a32
commit d3d7e530a9
6 changed files with 21 additions and 18 deletions

View File

@ -33,7 +33,7 @@ internal abstract class QQAndroidBotBase constructor(
val selfQQ: QQ by lazy { QQ(uin) }
override fun getQQ(id: Long): QQ {
override fun getFriend(id: Long): QQ {
return qqs.delegate.filteringGetOrAdd({ it.id == id }, { QQImpl(this as QQAndroidBot, coroutineContext, id) })
}

View File

@ -134,7 +134,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
totalFriendCount = data.totalFriendCount
data.friendList.forEach {
// atomic add
bot.qqs.delegate.addLast(bot.getQQ(it.friendUin).also {
bot.qqs.delegate.addLast(bot.getFriend(it.friendUin).also {
currentFriendCount++
})
}

View File

@ -123,14 +123,11 @@ internal class MessageSvc {
val messages = resp.uinPairMsgs.asSequence().filterNot { it.msg == null }.flatMap { it.msg!!.asSequence() }.mapNotNull {
when (it.msgHead.msgType) {
166 -> {
FriendMessage(
bot,
false, // TODO: 2020/1/29 PREVIOUS??
bot.getQQ(it.msgHead.fromUin),
it.msgBody.richText.toMessageChain()
)
}
166 -> FriendMessage(
bot,
bot.getFriend(it.msgHead.fromUin),
it.msgBody.richText.toMessageChain()
)
else -> null
}
}.toMutableList()
@ -176,7 +173,7 @@ internal class MessageSvc {
}
data class Failed(val errorCode: Int, val errorMessage: String) : Response() {
override fun toString(): String = "MessageSvc.PbSendMsg.Response.FAILED(errorCode=$errorCode, errorMessage=$errorMessage"
override fun toString(): String = "MessageSvc.PbSendMsg.Response.Failed(errorCode=$errorCode, errorMessage=$errorMessage"
}
}
@ -224,7 +221,7 @@ internal class MessageSvc {
///return@buildOutgoingUniPacket
writeProtoBuf(
MsgSvc.PbSendMsgReq.serializer(), MsgSvc.PbSendMsgReq(
routingHead = MsgSvc.RoutingHead(grp = MsgSvc.Grp(groupCode = groupCode)), // TODO: 2020/1/30 确认这里是 id 还是 internalId
routingHead = MsgSvc.RoutingHead(grp = MsgSvc.Grp(groupCode = groupCode)),
contentHead = MsgComm.ContentHead(pkgNum = 1, divSeq = seq),
msgBody = ImMsgBody.MsgBody(
richText = ImMsgBody.RichText(

View File

@ -58,9 +58,15 @@ abstract class Bot : CoroutineScope {
abstract val qqs: ContactList<QQ>
/**
* 获取一个好友对象. 若没有这个好友, 则会抛出异常[NoSuchElementException]
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
*/
abstract fun getQQ(id: Long): QQ
@Deprecated(message = "这个函数有歧义. 它获取的是好友, 却名为 getQQ", replaceWith = ReplaceWith("getFriend(id)"))
fun getQQ(id: Long): QQ = getFriend(id)
/**
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
*/
abstract fun getFriend(id: Long): QQ
/**
* 构造一个 [QQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
@ -133,8 +139,8 @@ abstract class Bot : CoroutineScope {
// region extensions
fun Int.qq(): QQ = getQQ(this.toLong())
fun Long.qq(): QQ = getQQ(this)
fun Int.qq(): QQ = getFriend(this.toLong())
fun Long.qq(): QQ = getFriend(this)
/**

View File

@ -11,7 +11,7 @@ import net.mamoe.mirai.data.Profile
/**
* QQ 对象.
* 注意: 一个 [QQ] 实例并不是独立的, 它属于一个 [Bot].
* 它不能被直接构造. 任何时候都应从 [Bot.getQQ] 或事件中获取.
* 它不能被直接构造. 任何时候都应从 [Bot.getFriend] 或事件中获取.
*
* 对于同一个 [Bot] 任何一个人的 [QQ] 实例都是单一的.
*

View File

@ -23,7 +23,7 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
@UseExperimental(MiraiInternalAPI::class)
override fun getQQs(): List<BlockingQQ> = bot.qqs.delegate.toList().map { it.blocking() }
override fun getQQ(id: Long): BlockingQQ = bot.getQQ(id).blocking()
override fun getQQ(id: Long): BlockingQQ = bot.getFriend(id).blocking()
@UseExperimental(MiraiInternalAPI::class)
override fun getGroups(): List<BlockingGroup> = bot.groups.delegate.toList().map { it.blocking() }