Skip to content

Commit

Permalink
[core] avoid potential null cast when refining `OnlineShortVideoMsgIn…
Browse files Browse the repository at this point in the history
…ternal`
  • Loading branch information
StageGuard committed Aug 25, 2023
1 parent 5651d64 commit 4acd667
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions mirai-core/src/commonMain/kotlin/message/data/shortVideo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package net.mamoe.mirai.internal.message.data
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import net.mamoe.mirai.Bot
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.contact.getMember
import net.mamoe.mirai.internal.asQQAndroidBot
import net.mamoe.mirai.internal.message.RefinableMessage
Expand Down Expand Up @@ -44,18 +43,17 @@ internal class OnlineShortVideoMsgInternal(
val groupId = refineContext[RefineContextKey.GroupIdOrZero] ?: return null

val contact = when (sourceKind) {
net.mamoe.mirai.message.data.MessageSourceKind.FRIEND -> bot.getFriend(fromId)
net.mamoe.mirai.message.data.MessageSourceKind.GROUP -> bot.getGroup(groupId)
else -> return null // TODO: ignore processing stranger's video message
} as Contact
MessageSourceKind.FRIEND -> bot.getFriend(fromId) ?: error("Cannot find friend $fromId.")
MessageSourceKind.GROUP -> bot.getGroup(groupId) ?: error("Cannot find group $fromId.")
else -> return null // ignore processing stranger's video message
}
val sender = when (sourceKind) {
net.mamoe.mirai.message.data.MessageSourceKind.FRIEND ->
bot.getFriend(fromId) ?: error("Cannot find friend $fromId.")
net.mamoe.mirai.message.data.MessageSourceKind.GROUP -> {
MessageSourceKind.FRIEND -> bot.getFriend(fromId) ?: error("Cannot find friend $fromId.")
MessageSourceKind.GROUP -> {
val group = bot.getGroup(groupId) ?: error("Cannot find group $groupId.")
group.getMember(fromId) ?: error("Cannot find member $fromId of group $groupId.")
}
else -> return null // TODO: ignore processing stranger's video message
else -> return null // ignore processing stranger's video message
}

val shortVideoDownloadReq = bot.network.sendAndExpect(
Expand Down

0 comments on commit 4acd667

Please sign in to comment.