Add companion Keys to GroupImage, FriendImage, OnlineImage, OfflineImage

This commit is contained in:
Him188 2020-03-23 20:03:01 +08:00
parent 917aaf685b
commit 7443e2aedd
2 changed files with 14 additions and 2 deletions

View File

@ -85,6 +85,8 @@ abstract class AbstractImage internal constructor() : Image {
* 一般由 [Contact.uploadImage] 得到
*/
interface OnlineImage : Image {
companion object Key : Message.Key<OnlineImage>
/**
* 原图下载链接. 包含域名
*/
@ -115,7 +117,9 @@ suspend fun Image.queryUrl(): String {
* 一般由 [Contact.uploadImage] 得到
* @see queryOriginUrl
*/
interface OfflineImage : Image
interface OfflineImage : Image {
companion object Key : Message.Key<OfflineImage>
}
/**
* 原图下载链接. 包含域名
@ -142,6 +146,8 @@ suspend inline fun OfflineImage.queryOriginUrl(): String = queryUrl()
// CustomFace
@OptIn(MiraiInternalAPI::class)
sealed class GroupImage : AbstractImage() {
companion object Key : Message.Key<GroupImage>
abstract val filepath: String
abstract val fileId: Int
abstract val serverIp: Int
@ -213,6 +219,8 @@ abstract class OnlineGroupImage : GroupImage(), OnlineImage
*/ // NotOnlineImage
@OptIn(MiraiInternalAPI::class)
sealed class FriendImage : AbstractImage() {
companion object Key : Message.Key<FriendImage>
abstract val resourceId: String
abstract val md5: ByteArray
abstract val filepath: String

View File

@ -127,6 +127,10 @@ fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = when (key)
AtAll -> first<AtAll>()
PlainText -> first<PlainText>()
Image -> first<Image>()
OnlineImage -> first<OnlineImage>()
OfflineImage -> first<OfflineImage>()
GroupImage -> first<GroupImage>()
FriendImage -> first<FriendImage>()
Face -> first<Face>()
QuoteReply -> first<QuoteReply>()
MessageSource -> first<MessageSource>()
@ -360,7 +364,7 @@ fun Message.flatten(): Sequence<SingleMessage> {
}
fun CombinedMessage.flatten(): Sequence<SingleMessage> {
if (this.isFlat()){
if (this.isFlat()) {
@Suppress("UNCHECKED_CAST")
return (this as Iterable<SingleMessage>).asSequence()
} else return this.asSequence().flatten()