
commonMain.dev.inmo.tgbotapi.libraries.cache.admins.AdminsCacheSettingsAPI.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tgbotapi.libraries.cache.admins.common-jvm Show documentation
Show all versions of tgbotapi.libraries.cache.admins.common-jvm Show documentation
tgbotapi.libraries.cache.admins.common
package dev.inmo.tgbotapi.libraries.cache.admins
import korlibs.time.minutes
import dev.inmo.tgbotapi.types.IdChatIdentifier
import dev.inmo.tgbotapi.types.Seconds
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.serialization.Serializable
@Serializable
data class AdminsCacheSettings(
val refreshSeconds: Seconds = 10.minutes.seconds.toInt(),
/**
* In case this setting set up to true, will request admins list just from time to time instead of refreshing on
* requests
*/
val disableRequestsRefreshMode: Boolean = false
) {
val refreshOnCacheCalls: Boolean
get() = !disableRequestsRefreshMode
@Deprecated("Renamed", ReplaceWith("refreshOnCacheCalls"))
val refreshOnRequests: Boolean
get() = refreshOnCacheCalls
}
interface AdminsCacheSettingsAPI {
suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings?
}
interface MutableAdminsCacheSettingsAPI : AdminsCacheSettingsAPI {
val chatSettingsUpdatedFlow: SharedFlow>
suspend fun setChatSettings(chatId: IdChatIdentifier, settings: AdminsCacheSettings)
}
fun AdminsCacheSettingsAPI.asMutable(): MutableAdminsCacheSettingsAPI? = this as? MutableAdminsCacheSettingsAPI
@Serializable
class StaticAdminsCacheSettingsAPI(
private val settings: Map
) : AdminsCacheSettingsAPI {
override suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings? = settings[chatId]
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy