mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
Update ChatIdentifierWithThreadId.kt
This commit is contained in:
parent
1b8ee5c4d7
commit
f2f15d7173
@ -1,29 +1,29 @@
|
||||
package dev.inmo.tgbotapi.utils.extensions
|
||||
|
||||
import dev.inmo.tgbotapi.types.ChatIdentifier
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.MessageThreadId
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlin.Pair
|
||||
import dev.inmo.tgbotapi.types.message.abstract.Message
|
||||
|
||||
sealed interface ChatIdWithThreadId {
|
||||
val chatId: ChatIdentifier
|
||||
val chatId: ChatId
|
||||
val threadId: MessageThreadId?
|
||||
|
||||
// Light weight due to absence of any conversations
|
||||
value class ByMessage(
|
||||
val sourceMessage: Message
|
||||
) : ChatIdWithThreadId {
|
||||
override val chatId: ChatIdentifier
|
||||
override val chatId: ChatId
|
||||
get() = sourceMessage.chat.id
|
||||
override val threadId: MessageThreadId?
|
||||
get() = sourceMessage.threadIdOrNull
|
||||
}
|
||||
@Serializable
|
||||
value class ByPair(
|
||||
val pair: Pair<ChatIdentifier, MessageThreadId?>
|
||||
val pair: Pair<ChatId, MessageThreadId?>
|
||||
) : ChatIdWithThreadId {
|
||||
override val chatId: ChatIdentifier
|
||||
override val chatId: ChatId
|
||||
get() = pair.first
|
||||
override val threadId: MessageThreadId?
|
||||
get() = pair.second
|
||||
@ -32,7 +32,7 @@ sealed interface ChatIdWithThreadId {
|
||||
companion {
|
||||
inline operator fun invoke(message: Message) = ByMessage(message)
|
||||
inline fun serializable(message: Message) = ByPair(message.chatId.id to message.threadIdOrNull)
|
||||
inline fun serializable(pair: Pair<ChatIdentifier, MessageThreadId?>) = ByPair(pair)
|
||||
inline fun serializable(pair: Pair<ChatId, MessageThreadId?>) = ByPair(pair)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user