From 4acd66711aa76782d95cacbfa25ede9cd6d062db Mon Sep 17 00:00:00 2001
From: StageGuard <1355416608@qq.com>
Date: Fri, 25 Aug 2023 22:16:27 +0800
Subject: [PATCH] [core] avoid potential null cast when refining
 `OnlineShortVideoMsgInternal`

---
 .../commonMain/kotlin/message/data/shortVideo.kt | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/mirai-core/src/commonMain/kotlin/message/data/shortVideo.kt b/mirai-core/src/commonMain/kotlin/message/data/shortVideo.kt
index d54ae99c1..21fd167e0 100644
--- a/mirai-core/src/commonMain/kotlin/message/data/shortVideo.kt
+++ b/mirai-core/src/commonMain/kotlin/message/data/shortVideo.kt
@@ -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
@@ -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(