mirror of
https://github.com/InsanusMokrassar/TelegramBotApiLibraries.git
synced 2025-09-16 13:49:29 +00:00
build fixes
This commit is contained in:
@@ -15,22 +15,22 @@ private sealed class RepoActions<T> {
|
||||
abstract val deferred: CompletableDeferred<T>
|
||||
}
|
||||
private class GetUpdateDateTimeRepoAction(
|
||||
val chatId: ChatId,
|
||||
val chatId: IdChatIdentifier,
|
||||
override val deferred: CompletableDeferred<DateTime?>
|
||||
) : RepoActions<DateTime?>()
|
||||
private class GetChatAdminsRepoAction(
|
||||
val chatId: ChatId,
|
||||
val chatId: IdChatIdentifier,
|
||||
override val deferred: CompletableDeferred<List<AdministratorChatMember>?>
|
||||
) : RepoActions<List<AdministratorChatMember>?>()
|
||||
private class SetChatAdminsRepoAction(
|
||||
val chatId: ChatId,
|
||||
val chatId: IdChatIdentifier,
|
||||
val newValue: List<AdministratorChatMember>,
|
||||
override val deferred: CompletableDeferred<Unit>
|
||||
) : RepoActions<Unit>()
|
||||
|
||||
class DefaultAdminsCacheAPIRepoImpl(
|
||||
private val adminsRepo: KeyValuesRepo<ChatId, AdministratorChatMember>,
|
||||
private val updatesRepo: KeyValueRepo<ChatId, MilliSeconds>,
|
||||
private val adminsRepo: KeyValuesRepo<IdChatIdentifier, AdministratorChatMember>,
|
||||
private val updatesRepo: KeyValueRepo<IdChatIdentifier, MilliSeconds>,
|
||||
private val scope: CoroutineScope
|
||||
) : DefaultAdminsCacheAPIRepo {
|
||||
private val actor = scope.actorAsync<RepoActions<*>>(Channel.UNLIMITED) {
|
||||
@@ -54,7 +54,7 @@ class DefaultAdminsCacheAPIRepoImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getChatAdmins(chatId: ChatId): List<AdministratorChatMember>? {
|
||||
override suspend fun getChatAdmins(chatId: IdChatIdentifier): List<AdministratorChatMember>? {
|
||||
val deferred = CompletableDeferred<List<AdministratorChatMember>?>()
|
||||
actor.trySend(
|
||||
GetChatAdminsRepoAction(chatId, deferred)
|
||||
@@ -64,7 +64,7 @@ class DefaultAdminsCacheAPIRepoImpl(
|
||||
return deferred.await()
|
||||
}
|
||||
|
||||
override suspend fun setChatAdmins(chatId: ChatId, chatMembers: List<AdministratorChatMember>) {
|
||||
override suspend fun setChatAdmins(chatId: IdChatIdentifier, chatMembers: List<AdministratorChatMember>) {
|
||||
val deferred = CompletableDeferred<Unit>()
|
||||
actor.trySend(
|
||||
SetChatAdminsRepoAction(chatId, chatMembers, deferred)
|
||||
@@ -73,7 +73,7 @@ class DefaultAdminsCacheAPIRepoImpl(
|
||||
}
|
||||
return deferred.await()
|
||||
}
|
||||
override suspend fun lastUpdate(chatId: ChatId): DateTime? {
|
||||
override suspend fun lastUpdate(chatId: IdChatIdentifier): DateTime? {
|
||||
val deferred = CompletableDeferred<DateTime?>()
|
||||
actor.trySend(
|
||||
GetUpdateDateTimeRepoAction(chatId, deferred)
|
||||
@@ -85,7 +85,7 @@ class DefaultAdminsCacheAPIRepoImpl(
|
||||
}
|
||||
|
||||
fun DefaultAdminsCacheAPIRepo(
|
||||
adminsRepo: KeyValuesRepo<ChatId, AdministratorChatMember>,
|
||||
updatesRepo: KeyValueRepo<ChatId, MilliSeconds>,
|
||||
adminsRepo: KeyValuesRepo<IdChatIdentifier, AdministratorChatMember>,
|
||||
updatesRepo: KeyValueRepo<IdChatIdentifier, MilliSeconds>,
|
||||
scope: CoroutineScope
|
||||
) = DefaultAdminsCacheAPIRepoImpl(adminsRepo, updatesRepo, scope)
|
||||
|
@@ -3,22 +3,22 @@ package dev.inmo.tgbotapi.libraries.cache.admins.micro_utils
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import dev.inmo.tgbotapi.libraries.cache.admins.*
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.types.IdChatIdentifier
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
|
||||
class DynamicAdminsCacheSettingsAPI(
|
||||
private val repo: KeyValueRepo<ChatId, AdminsCacheSettings>,
|
||||
private val repo: KeyValueRepo<IdChatIdentifier, AdminsCacheSettings>,
|
||||
private val scope: CoroutineScope
|
||||
) : AdminsCacheSettingsAPI, MutableAdminsCacheSettingsAPI {
|
||||
override val chatSettingsUpdatedFlow: SharedFlow<Pair<ChatId, AdminsCacheSettings>>
|
||||
override val chatSettingsUpdatedFlow: SharedFlow<Pair<IdChatIdentifier, AdminsCacheSettings>>
|
||||
get() = repo.onNewValue.shareIn(scope, SharingStarted.Eagerly)
|
||||
|
||||
override suspend fun setChatSettings(chatId: ChatId, settings: AdminsCacheSettings) {
|
||||
override suspend fun setChatSettings(chatId: IdChatIdentifier, settings: AdminsCacheSettings) {
|
||||
repo.set(chatId, settings)
|
||||
}
|
||||
|
||||
override suspend fun getChatSettings(chatId: ChatId): AdminsCacheSettings {
|
||||
override suspend fun getChatSettings(chatId: IdChatIdentifier): AdminsCacheSettings {
|
||||
val settings = repo.get(chatId)
|
||||
return if (settings == null) {
|
||||
val newSettings = AdminsCacheSettings()
|
||||
@@ -28,4 +28,4 @@ class DynamicAdminsCacheSettingsAPI(
|
||||
settings
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ fun TelegramBot.createAdminsCacheAPI(
|
||||
{ long("chatId") },
|
||||
{ text("member") },
|
||||
"AdminsTable"
|
||||
).withMapper<ChatId, AdministratorChatMember, Identifier, String>(
|
||||
).withMapper<IdChatIdentifier, AdministratorChatMember, Identifier, String>(
|
||||
keyFromToTo = { chatId },
|
||||
valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(AdministratorChatMember.serializer(), this) },
|
||||
keyToToFrom = { toChatId() },
|
||||
@@ -49,7 +49,7 @@ fun TelegramBot.createAdminsCacheAPI(
|
||||
{ long("chatId") },
|
||||
{ long("datetime") },
|
||||
"AdminsUpdatesTimesTable"
|
||||
).withMapper<ChatId, Long, Identifier, Long>(
|
||||
).withMapper<IdChatIdentifier, Long, Identifier, Long>(
|
||||
keyFromToTo = { chatId },
|
||||
valueFromToTo = { this },
|
||||
keyToToFrom = { toChatId() },
|
||||
@@ -63,7 +63,7 @@ fun TelegramBot.createAdminsCacheAPI(
|
||||
{ long("chatId") },
|
||||
{ text("settings") },
|
||||
"DynamicAdminsCacheSettingsAPI"
|
||||
).withMapper<ChatId, AdminsCacheSettings, Identifier, String>(
|
||||
).withMapper<IdChatIdentifier, AdminsCacheSettings, Identifier, String>(
|
||||
keyFromToTo = { chatId },
|
||||
valueFromToTo = { telegramAdminsSerializationFormat.encodeToString(AdminsCacheSettings.serializer() , this) },
|
||||
keyToToFrom = { toChatId() },
|
||||
|
Reference in New Issue
Block a user