Fix FlashImage constructing

This commit is contained in:
Him188 2020-04-03 08:48:22 +08:00
parent ebe3ecd2cb
commit b4f77454a1
2 changed files with 16 additions and 6 deletions

View File

@ -116,8 +116,10 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean, withGeneralFlags: B
is OnlineGroupImageImpl -> elements.add(ImMsgBody.Elem(customFace = it.delegate)) is OnlineGroupImageImpl -> elements.add(ImMsgBody.Elem(customFace = it.delegate))
is OnlineFriendImageImpl -> elements.add(ImMsgBody.Elem(notOnlineImage = it.delegate)) is OnlineFriendImageImpl -> elements.add(ImMsgBody.Elem(notOnlineImage = it.delegate))
is OfflineFriendImage -> elements.add(ImMsgBody.Elem(notOnlineImage = it.toJceData())) is OfflineFriendImage -> elements.add(ImMsgBody.Elem(notOnlineImage = it.toJceData()))
is GroupFlashImageImpl -> elements.add(it.toJceData()).also { transformOneMessage(UNSUPPORTED_FLASH_MESSAGE_PLAIN) } is GroupFlashImage -> elements.add(it.toJceData())
is FriendFlashImageImpl -> elements.add(it.toJceData()).also { transformOneMessage(UNSUPPORTED_FLASH_MESSAGE_PLAIN) } .also { transformOneMessage(UNSUPPORTED_FLASH_MESSAGE_PLAIN) }
is FriendFlashImage -> elements.add(it.toJceData())
.also { transformOneMessage(UNSUPPORTED_FLASH_MESSAGE_PLAIN) }
is AtAll -> elements.add(atAllData) is AtAll -> elements.add(atAllData)
is Face -> elements.add(ImMsgBody.Elem(face = it.toJceData())) is Face -> elements.add(ImMsgBody.Elem(face = it.toJceData()))
is QuoteReplyToSend -> { is QuoteReplyToSend -> {
@ -303,10 +305,10 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(message: MessageChainBuilde
3 -> { 3 -> {
val proto = it.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype3.serializer()) val proto = it.commonElem.pbElem.loadAs(HummerCommelem.MsgElemInfoServtype3.serializer())
if (proto.flashTroopPic != null) { if (proto.flashTroopPic != null) {
message.add(GroupFlashImageImpl(OnlineGroupImageImpl(proto.flashTroopPic))) message.add(GroupFlashImage(OnlineGroupImageImpl(proto.flashTroopPic)))
} }
if (proto.flashC2cPic != null) { if (proto.flashC2cPic != null) {
message.add(FriendFlashImageImpl(OnlineFriendImageImpl(proto.flashC2cPic))) message.add(FriendFlashImage(OnlineFriendImageImpl(proto.flashC2cPic)))
} }
} }
} }

View File

@ -2,6 +2,7 @@
package net.mamoe.mirai.message.data package net.mamoe.mirai.message.data
import net.mamoe.mirai.utils.MiraiInternalAPI
import net.mamoe.mirai.utils.SinceMirai import net.mamoe.mirai.utils.SinceMirai
import kotlin.jvm.JvmSynthetic import kotlin.jvm.JvmSynthetic
@ -14,6 +15,7 @@ import kotlin.jvm.JvmSynthetic
sealed class FlashImage : MessageContent { sealed class FlashImage : MessageContent {
companion object Key : Message.Key<FlashImage> { companion object Key : Message.Key<FlashImage> {
operator fun invoke(image: Image): FlashImage { operator fun invoke(image: Image): FlashImage {
@OptIn(MiraiInternalAPI::class)
return when (image) { return when (image) {
is GroupImage -> GroupFlashImage(image) is GroupImage -> GroupFlashImage(image)
is FriendImage -> FriendFlashImage(image) is FriendImage -> FriendFlashImage(image)
@ -51,6 +53,12 @@ inline fun GroupImage.flash(): GroupFlashImage = FlashImage(this) as GroupFlashI
@JvmSynthetic @JvmSynthetic
inline fun FriendImage.flash(): FriendFlashImage = FlashImage(this) as FriendFlashImage inline fun FriendImage.flash(): FriendFlashImage = FlashImage(this) as FriendFlashImage
class GroupFlashImage internal constructor(override val image: GroupImage) : FlashImage() /**
* @see FlashImage.invoke
*/
class GroupFlashImage @MiraiInternalAPI constructor(override val image: GroupImage) : FlashImage()
class FriendFlashImage internal constructor(override val image: FriendImage) : FlashImage() /**
* @see FlashImage.invoke
*/
class FriendFlashImage @MiraiInternalAPI constructor(override val image: FriendImage) : FlashImage()