Commit 7443e2ae authored by Him188's avatar Him188

Add companion `Key`s to `GroupImage`, `FriendImage`, `OnlineImage`, `OfflineImage`

parent 917aaf68
......@@ -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
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment