PlaguPoster/common/src/commonMain/kotlin/ChatConfig.kt

44 lines
1.5 KiB
Kotlin
Raw Normal View History

2022-09-09 13:40:46 +00:00
package dev.inmo.plaguposter.common
2022-08-21 15:54:18 +00:00
2022-12-14 05:50:02 +00:00
import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer
import dev.inmo.tgbotapi.types.IdChatIdentifier
2022-09-04 07:27:35 +00:00
import kotlinx.serialization.SerialName
2022-08-21 15:54:18 +00:00
import kotlinx.serialization.Serializable
@Serializable
data class ChatConfig(
2022-09-04 07:27:35 +00:00
@SerialName("targetChat")
2022-12-14 05:50:02 +00:00
@Serializable(FullChatIdentifierSerializer::class)
val targetChatId: IdChatIdentifier? = null,
2022-09-04 07:27:35 +00:00
@SerialName("sourceChat")
2022-12-14 05:50:02 +00:00
@Serializable(FullChatIdentifierSerializer::class)
val sourceChatId: IdChatIdentifier?,
2022-09-04 07:27:35 +00:00
@SerialName("cacheChat")
2022-12-14 05:50:02 +00:00
@Serializable(FullChatIdentifierSerializer::class)
val cacheChatId: IdChatIdentifier,
@SerialName("targetChats")
val targetChatIds: List<@Serializable(FullChatIdentifierSerializer::class) IdChatIdentifier> = emptyList(),
@SerialName("sourceChats")
val sourceChatIds: List<@Serializable(FullChatIdentifierSerializer::class) IdChatIdentifier> = emptyList(),
2022-12-14 05:50:02 +00:00
) {
val allTargetChatIds by lazy {
(listOfNotNull(targetChatId) + targetChatIds).toSet()
}
val allSourceChatIds by lazy {
(listOfNotNull(sourceChatId) + sourceChatIds).toSet()
}
init {
require(targetChatId != null || targetChatIds.isNotEmpty()) {
"One of fields, 'targetChat' or 'targetChats' should be presented"
}
}
2022-12-14 05:50:02 +00:00
fun check(chatId: IdChatIdentifier) = when (chatId) {
in allTargetChatIds,
in allSourceChatIds,
2022-12-14 05:50:02 +00:00
cacheChatId -> true
else -> false
}
}