TelegramBotApiLibraries/resender/src/commonMain/kotlin/MessageMetaInfo.kt

37 lines
1.4 KiB
Kotlin
Raw Normal View History

2023-01-14 16:37:56 +00:00
package dev.inmo.tgbotapi.libraries.resender
import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer
2023-01-14 16:37:56 +00:00
import dev.inmo.tgbotapi.types.IdChatIdentifier
2024-04-23 15:20:03 +00:00
import dev.inmo.tgbotapi.types.MediaGroupId
2023-01-14 16:37:56 +00:00
import dev.inmo.tgbotapi.types.MessageId
2024-01-13 08:37:21 +00:00
import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage
2023-01-14 16:37:56 +00:00
import dev.inmo.tgbotapi.types.message.abstracts.Message
import dev.inmo.tgbotapi.types.message.abstracts.PossiblyMediaGroupMessage
2024-01-13 08:37:21 +00:00
import dev.inmo.tgbotapi.types.message.content.MediaGroupContent
2023-01-14 16:37:56 +00:00
import kotlinx.serialization.Serializable
@Serializable
data class MessageMetaInfo(
@Serializable(FullChatIdentifierSerializer::class)
2023-01-14 16:37:56 +00:00
val chatId: IdChatIdentifier,
val messageId: MessageId,
2024-04-23 15:20:03 +00:00
val group: MediaGroupId? = null
2024-01-13 08:37:21 +00:00
) {
val metaInfo: Message.MetaInfo
get() = Message.MetaInfo(chatId, messageId)
}
fun Message.asMessageMetaInfos(): List<MessageMetaInfo> {
return if (this is ContentMessage<*>) {
(content as? MediaGroupContent<*>) ?.group ?.map {
MessageMetaInfo(it.sourceMessage.chat.id, it.sourceMessage.messageId, it.sourceMessage.mediaGroupId)
}
} else {
null
} ?: listOf(MessageMetaInfo(chat.id, messageId, (this as? PossiblyMediaGroupMessage<*>) ?.mediaGroupId))
}
2023-01-14 16:37:56 +00:00
operator fun MessageMetaInfo.Companion.invoke(
message: Message
) = MessageMetaInfo(message.chat.id, message.messageId, (message as? PossiblyMediaGroupMessage<*>) ?.mediaGroupId)