Use getGroupByUinOrCodeOrFail in OnlineMessageSourceFromTempImpl for tests

This commit is contained in:
Him188 2021-08-27 20:15:47 +08:00
parent 15ad3fbda6
commit de07e0eeb8
2 changed files with 11 additions and 2 deletions

View File

@ -266,6 +266,12 @@ internal fun QQAndroidBot.getGroupByUin(uin: Long) = groups.firstOrNull { it.uin
internal fun QQAndroidBot.getGroupByUinOrCode(uinOrCode: Long) =
groups.firstOrNull { it.uin == uinOrCode } ?: groups.firstOrNull { it.id == uinOrCode }
/**
* uin first
*/
internal fun QQAndroidBot.getGroupByUinOrCodeOrFail(uinOrCode: Long) =
getGroupByUinOrCode(uinOrCode) ?: throw NoSuchElementException("group.code or uin=$uinOrCode")
/**
* code first

View File

@ -20,7 +20,7 @@ import net.mamoe.mirai.contact.Stranger
import net.mamoe.mirai.internal.asQQAndroidBot
import net.mamoe.mirai.internal.contact.checkIsGroupImpl
import net.mamoe.mirai.internal.contact.newAnonymous
import net.mamoe.mirai.internal.getGroupByUinOrFail
import net.mamoe.mirai.internal.getGroupByUinOrCodeOrFail
import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
import net.mamoe.mirai.internal.network.protocol.data.proto.SourceMsg
@ -140,7 +140,10 @@ internal class OnlineMessageSourceFromTempImpl(
override val sender: Member = with(msg.first().msgHead) {
// it must be uin, see #1410
// corresponding test: net.mamoe.mirai.internal.notice.processors.MessageTest.group temp message test 2
bot.asQQAndroidBot().getGroupByUinOrFail(c2cTmpMsgHead!!.groupUin).getOrFail(fromUin)
// search for group code also is for tests. code may be passed as uin in tests.
// clashing is unlikely possible in real time, so it would not be a problem.
bot.asQQAndroidBot().getGroupByUinOrCodeOrFail(c2cTmpMsgHead!!.groupUin).getOrFail(fromUin)
}
private val jceData: ImMsgBody.SourceMsg by lazy { msg.toJceDataPrivate(internalIds) }