From d2d3665c5ebf2f27fcbfda720cb40af38dd90130 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Apr 2024 11:58:27 +0600 Subject: [PATCH 1/2] start 0.5.5 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc6c2e8..b7ff396 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # PlaguPoster +## 0.5.5 + ## 0.5.4 * Dependencies update diff --git a/gradle.properties b/gradle.properties index 70d4320..c56661e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,4 +10,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.5.4 +version=0.5.5 From e24237beb3b15780b0609420e4528bbcb37cd5a5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 24 Apr 2024 12:14:33 +0600 Subject: [PATCH 2/2] update dependencies --- CHANGELOG.md | 2 ++ .../src/commonMain/kotlin/ShortMessageInfo.kt | 7 ++-- gradle/libs.versions.toml | 18 +++++----- posts/panel/src/jvmMain/kotlin/Plugin.kt | 4 +-- .../src/jvmMain/kotlin/repos/PostsMessages.kt | 9 ++--- .../kotlin/models/PostContentInfo.kt | 9 ++--- .../commonMain/kotlin/repo/ReadPostsRepo.kt | 4 +-- .../jvmMain/kotlin/cached/CachedPostsRepo.kt | 4 +-- .../kotlin/exposed/ExposedContentInfoRepo.kt | 9 +++-- .../kotlin/exposed/ExposedPostsRepo.kt | 18 +++++----- .../repos/CachedPollsToMessagesInfoRepo.kt | 7 ++-- .../kotlin/repos/CachedPollsToPostsIdsRepo.kt | 7 ++-- .../kotlin/repos/PollsToMessagesInfoRepo.kt | 4 +-- .../kotlin/repos/PollsToPostsIdsRepo.kt | 4 +-- .../repos/ExposedPollsToMessagesInfoRepo.kt | 33 +++++++++---------- .../repos/ExposedPollsToPostsIdsRepo.kt | 16 ++++----- .../kotlin/repo/CachedRatingsRepo.kt | 4 +-- ratings/src/jvmMain/kotlin/Plugin.kt | 2 -- .../kotlin/exposed/ExposedRatingsRepo.kt | 6 ++-- triggers/command/src/jvmMain/kotlin/Plugin.kt | 6 ++-- 20 files changed, 82 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ff396..3be697d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.5.5 +* Dependencies update + ## 0.5.4 * Dependencies update diff --git a/common/src/commonMain/kotlin/ShortMessageInfo.kt b/common/src/commonMain/kotlin/ShortMessageInfo.kt index 586f893..b9b32e5 100644 --- a/common/src/commonMain/kotlin/ShortMessageInfo.kt +++ b/common/src/commonMain/kotlin/ShortMessageInfo.kt @@ -1,9 +1,6 @@ package dev.inmo.plaguposter.common -import dev.inmo.tgbotapi.types.ChatId -import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer -import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.message.abstracts.Message import kotlinx.serialization.Serializable @@ -11,7 +8,7 @@ import kotlinx.serialization.Serializable data class ShortMessageInfo( @Serializable(FullChatIdentifierSerializer::class) val chatId: IdChatIdentifier, - val messageId: MessageIdentifier + val messageId: MessageId ) fun Message.short() = ShortMessageInfo(chat.id, messageId) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 71cfca5..42528c0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,16 +1,16 @@ [versions] -kotlin = "1.9.22" -kotlin-serialization = "1.6.2" +kotlin = "1.9.23" +kotlin-serialization = "1.6.3" -plagubot = "8.2.0" -tgbotapi = "10.1.0" -microutils = "0.20.35" -kslog = "1.3.2" -krontab = "2.2.8" -plagubot-plugins = "0.18.2" +plagubot = "8.3.0" +tgbotapi = "12.0.1" +microutils = "0.20.45" +kslog = "1.3.3" +krontab = "2.2.9" +plagubot-plugins = "0.18.3" -dokka = "1.9.10" +dokka = "1.9.20" psql = "42.6.0" diff --git a/posts/panel/src/jvmMain/kotlin/Plugin.kt b/posts/panel/src/jvmMain/kotlin/Plugin.kt index d886118..9b42237 100644 --- a/posts/panel/src/jvmMain/kotlin/Plugin.kt +++ b/posts/panel/src/jvmMain/kotlin/Plugin.kt @@ -30,7 +30,7 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.ReplyParameters import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.buttons.InlineKeyboardMarkup @@ -129,7 +129,7 @@ object Plugin : Plugin { suspend fun refreshPostMessage( postId: PostId, chatId: IdChatIdentifier, - messageId: MessageIdentifier + messageId: MessageId ) { val post = postsRepo.getById(postId) ?: return val buttons = api.buttonsBuilders.chunked(config.buttonsPerRow).mapNotNull { row -> diff --git a/posts/panel/src/jvmMain/kotlin/repos/PostsMessages.kt b/posts/panel/src/jvmMain/kotlin/repos/PostsMessages.kt index 64015aa..baa52b5 100644 --- a/posts/panel/src/jvmMain/kotlin/repos/PostsMessages.kt +++ b/posts/panel/src/jvmMain/kotlin/repos/PostsMessages.kt @@ -4,21 +4,18 @@ import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo import dev.inmo.micro_utils.repos.mappers.withMapper import dev.inmo.plaguposter.posts.models.PostId -import dev.inmo.tgbotapi.types.ChatId -import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer -import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.* import kotlinx.serialization.builtins.PairSerializer import kotlinx.serialization.builtins.serializer import kotlinx.serialization.json.Json import org.jetbrains.exposed.sql.Database -private val ChatIdToMessageSerializer = PairSerializer(FullChatIdentifierSerializer, MessageIdentifier.serializer()) +private val ChatIdToMessageSerializer = PairSerializer(FullChatIdentifierSerializer, MessageId.serializer()) fun PostsMessages( database: Database, json: Json -): KeyValueRepo> = ExposedKeyValueRepo( +): KeyValueRepo> = ExposedKeyValueRepo( database, { text("postId") }, { text("chatToMessage") }, diff --git a/posts/src/commonMain/kotlin/models/PostContentInfo.kt b/posts/src/commonMain/kotlin/models/PostContentInfo.kt index 583290e..76f09ec 100644 --- a/posts/src/commonMain/kotlin/models/PostContentInfo.kt +++ b/posts/src/commonMain/kotlin/models/PostContentInfo.kt @@ -1,10 +1,7 @@ package dev.inmo.plaguposter.posts.models import dev.inmo.tgbotapi.extensions.utils.possiblyMediaGroupMessageOrNull -import dev.inmo.tgbotapi.types.ChatId -import dev.inmo.tgbotapi.types.FullChatIdentifierSerializer -import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.message.abstracts.ContentMessage import dev.inmo.tgbotapi.types.message.content.MediaGroupContent import kotlinx.serialization.Serializable @@ -13,8 +10,8 @@ import kotlinx.serialization.Serializable data class PostContentInfo( @Serializable(FullChatIdentifierSerializer::class) val chatId: IdChatIdentifier, - val messageId: MessageIdentifier, - val group: String?, + val messageId: MessageId, + val group: MediaGroupId?, val order: Int ) { companion object { diff --git a/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt b/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt index b161282..99307b5 100644 --- a/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt +++ b/posts/src/commonMain/kotlin/repo/ReadPostsRepo.kt @@ -5,10 +5,10 @@ import dev.inmo.micro_utils.repos.ReadCRUDRepo import dev.inmo.plaguposter.posts.models.* import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.MessageId interface ReadPostsRepo : ReadCRUDRepo { - suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageIdentifier): PostId? + suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageId): PostId? suspend fun getPostCreationTime(postId: PostId): DateTime? suspend fun getFirstMessageInfo(postId: PostId): PostContentInfo? } diff --git a/posts/src/jvmMain/kotlin/cached/CachedPostsRepo.kt b/posts/src/jvmMain/kotlin/cached/CachedPostsRepo.kt index bc23003..c80f262 100644 --- a/posts/src/jvmMain/kotlin/cached/CachedPostsRepo.kt +++ b/posts/src/jvmMain/kotlin/cached/CachedPostsRepo.kt @@ -16,7 +16,7 @@ import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.posts.models.RegisteredPost import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.MessageId import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow @@ -34,7 +34,7 @@ class CachedPostsRepo( ) { override val removedPostsFlow: Flow by parentRepo::removedPostsFlow - override suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageIdentifier): PostId? { + override suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageId): PostId? { doForAllWithNextPaging(firstPageWithOneElementPagination) { kvCache.values(it).also { it.results.forEach { diff --git a/posts/src/jvmMain/kotlin/exposed/ExposedContentInfoRepo.kt b/posts/src/jvmMain/kotlin/exposed/ExposedContentInfoRepo.kt index 52e9c70..9ac65d5 100644 --- a/posts/src/jvmMain/kotlin/exposed/ExposedContentInfoRepo.kt +++ b/posts/src/jvmMain/kotlin/exposed/ExposedContentInfoRepo.kt @@ -4,8 +4,7 @@ import com.benasher44.uuid.uuid4 import dev.inmo.micro_utils.repos.KeyValuesRepo import dev.inmo.micro_utils.repos.exposed.* import dev.inmo.plaguposter.posts.models.* -import dev.inmo.tgbotapi.types.ChatId -import dev.inmo.tgbotapi.types.IdChatIdentifier +import dev.inmo.tgbotapi.types.* import org.jetbrains.exposed.sql.* internal class ExposedContentInfoRepo( @@ -21,9 +20,9 @@ internal class ExposedContentInfoRepo( val ResultRow.asObject get() = PostContentInfo( - IdChatIdentifier(get(chatIdColumn), get(threadIdColumn)), - get(messageIdColumn), - get(groupColumn), + IdChatIdentifier(RawChatId(get(chatIdColumn)), get(threadIdColumn) ?.let(::MessageThreadId)), + MessageId(get(messageIdColumn)), + get(groupColumn) ?.let(::MediaGroupId), get(orderColumn) ) diff --git a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt index e0917d0..881e745 100644 --- a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt +++ b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt @@ -10,7 +10,7 @@ import dev.inmo.plaguposter.posts.models.* import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.MessageId import kotlinx.coroutines.flow.* import kotlinx.serialization.json.Json import org.jetbrains.exposed.sql.* @@ -93,10 +93,10 @@ class ExposedPostsRepo( post.content.forEach { contentInfo -> insert { it[postIdColumn] = post.id.string - it[chatIdColumn] = contentInfo.chatId.chatId - it[threadIdColumn] = contentInfo.chatId.threadId - it[messageIdColumn] = contentInfo.messageId - it[groupColumn] = contentInfo.group + it[chatIdColumn] = contentInfo.chatId.chatId.long + it[threadIdColumn] = contentInfo.chatId.threadId ?.long + it[messageIdColumn] = contentInfo.messageId.long + it[groupColumn] = contentInfo.group ?.string it[orderColumn] = contentInfo.order } } @@ -153,13 +153,13 @@ class ExposedPostsRepo( } } - override suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageIdentifier): PostId? { + override suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageId): PostId? { return transaction(database) { with(contentRepo) { select { - chatIdColumn.eq(chatId.chatId) - .and(chatId.threadId ?.let { threadIdColumn.eq(it) } ?: threadIdColumn.isNull()) - .and(messageIdColumn.eq(messageId)) + chatIdColumn.eq(chatId.chatId.long) + .and(chatId.threadId ?.let { threadIdColumn.eq(it.long) } ?: threadIdColumn.isNull()) + .and(messageIdColumn.eq(messageId.long)) }.limit(1).firstOrNull() ?.get(postIdColumn) } ?.let(::PostId) } diff --git a/ratings/source/src/commonMain/kotlin/repos/CachedPollsToMessagesInfoRepo.kt b/ratings/source/src/commonMain/kotlin/repos/CachedPollsToMessagesInfoRepo.kt index 21c225a..beb884f 100644 --- a/ratings/source/src/commonMain/kotlin/repos/CachedPollsToMessagesInfoRepo.kt +++ b/ratings/source/src/commonMain/kotlin/repos/CachedPollsToMessagesInfoRepo.kt @@ -1,14 +1,15 @@ package dev.inmo.plaguposter.ratings.source.repos import dev.inmo.micro_utils.repos.KeyValueRepo +import dev.inmo.micro_utils.repos.MapKeyValueRepo import dev.inmo.micro_utils.repos.cache.cache.FullKVCache import dev.inmo.micro_utils.repos.cache.full.fullyCached import dev.inmo.plaguposter.common.ShortMessageInfo -import dev.inmo.tgbotapi.types.PollIdentifier +import dev.inmo.tgbotapi.types.PollId import kotlinx.coroutines.CoroutineScope class CachedPollsToMessagesInfoRepo( private val repo: PollsToMessagesInfoRepo, private val scope: CoroutineScope, - private val kvCache: FullKVCache = FullKVCache() -) : PollsToMessagesInfoRepo, KeyValueRepo by repo.fullyCached(kvCache, scope) + private val kvCache: KeyValueRepo = MapKeyValueRepo() +) : PollsToMessagesInfoRepo, KeyValueRepo by repo.fullyCached(kvCache, scope) diff --git a/ratings/source/src/commonMain/kotlin/repos/CachedPollsToPostsIdsRepo.kt b/ratings/source/src/commonMain/kotlin/repos/CachedPollsToPostsIdsRepo.kt index 9166181..09871b8 100644 --- a/ratings/source/src/commonMain/kotlin/repos/CachedPollsToPostsIdsRepo.kt +++ b/ratings/source/src/commonMain/kotlin/repos/CachedPollsToPostsIdsRepo.kt @@ -1,14 +1,15 @@ package dev.inmo.plaguposter.ratings.source.repos import dev.inmo.micro_utils.repos.KeyValueRepo +import dev.inmo.micro_utils.repos.MapKeyValueRepo import dev.inmo.micro_utils.repos.cache.cache.FullKVCache import dev.inmo.micro_utils.repos.cache.full.fullyCached import dev.inmo.plaguposter.posts.models.PostId -import dev.inmo.tgbotapi.types.PollIdentifier +import dev.inmo.tgbotapi.types.PollId import kotlinx.coroutines.CoroutineScope class CachedPollsToPostsIdsRepo( private val repo: PollsToPostsIdsRepo, private val scope: CoroutineScope, - private val kvCache: FullKVCache = FullKVCache() -) : PollsToPostsIdsRepo, KeyValueRepo by repo.fullyCached(kvCache, scope) + private val kvCache: KeyValueRepo = MapKeyValueRepo() +) : PollsToPostsIdsRepo, KeyValueRepo by repo.fullyCached(kvCache, scope) diff --git a/ratings/source/src/commonMain/kotlin/repos/PollsToMessagesInfoRepo.kt b/ratings/source/src/commonMain/kotlin/repos/PollsToMessagesInfoRepo.kt index 6906d7f..0e5f36e 100644 --- a/ratings/source/src/commonMain/kotlin/repos/PollsToMessagesInfoRepo.kt +++ b/ratings/source/src/commonMain/kotlin/repos/PollsToMessagesInfoRepo.kt @@ -3,6 +3,6 @@ package dev.inmo.plaguposter.ratings.source.repos import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.plaguposter.common.ShortMessageInfo import dev.inmo.plaguposter.posts.models.PostId -import dev.inmo.tgbotapi.types.PollIdentifier +import dev.inmo.tgbotapi.types.PollId -interface PollsToMessagesInfoRepo : KeyValueRepo +interface PollsToMessagesInfoRepo : KeyValueRepo diff --git a/ratings/source/src/commonMain/kotlin/repos/PollsToPostsIdsRepo.kt b/ratings/source/src/commonMain/kotlin/repos/PollsToPostsIdsRepo.kt index 90a673b..44f6202 100644 --- a/ratings/source/src/commonMain/kotlin/repos/PollsToPostsIdsRepo.kt +++ b/ratings/source/src/commonMain/kotlin/repos/PollsToPostsIdsRepo.kt @@ -2,6 +2,6 @@ package dev.inmo.plaguposter.ratings.source.repos import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.plaguposter.posts.models.PostId -import dev.inmo.tgbotapi.types.PollIdentifier +import dev.inmo.tgbotapi.types.PollId -interface PollsToPostsIdsRepo : KeyValueRepo +interface PollsToPostsIdsRepo : KeyValueRepo diff --git a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt index d66a00f..7bd2667 100644 --- a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt +++ b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt @@ -3,9 +3,7 @@ package dev.inmo.plaguposter.ratings.source.repos import dev.inmo.micro_utils.repos.exposed.initTable import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo import dev.inmo.plaguposter.common.ShortMessageInfo -import dev.inmo.tgbotapi.types.ChatId -import dev.inmo.tgbotapi.types.IdChatIdentifier -import dev.inmo.tgbotapi.types.PollIdentifier +import dev.inmo.tgbotapi.types.* import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull @@ -13,7 +11,7 @@ import org.jetbrains.exposed.sql.statements.* class ExposedPollsToMessagesInfoRepo( database: Database -) : PollsToMessagesInfoRepo, AbstractExposedKeyValueRepo( +) : PollsToMessagesInfoRepo, AbstractExposedKeyValueRepo( database, "polls_to_their_messages_info" ) { @@ -21,31 +19,32 @@ class ExposedPollsToMessagesInfoRepo( private val chatIdColumn = long("chat_id") private val threadIdColumn = long("thread_id").nullable().default(null) private val messageIdColumn = long("message_id") - override val selectById: ISqlExpressionBuilder.(PollIdentifier) -> Op = { keyColumn.eq(it) } + override val selectById: ISqlExpressionBuilder.(PollId) -> Op = { keyColumn.eq(it.string) } override val selectByValue: ISqlExpressionBuilder.(ShortMessageInfo) -> Op = { - chatIdColumn.eq(it.chatId.chatId).and(it.chatId.threadId ?.let { threadIdColumn.eq(it) } ?: threadIdColumn.isNull()).and( - messageIdColumn.eq(it.messageId) + chatIdColumn.eq(it.chatId.chatId.long) + .and(it.chatId.threadId?.let { threadIdColumn.eq(it.long) } ?: threadIdColumn.isNull()).and( + messageIdColumn.eq(it.messageId.long) ) } - override val ResultRow.asKey: PollIdentifier - get() = get(keyColumn) + override val ResultRow.asKey: PollId + get() = PollId(get(keyColumn)) override val ResultRow.asObject: ShortMessageInfo get() = ShortMessageInfo( - IdChatIdentifier(get(chatIdColumn), get(threadIdColumn)), - get(messageIdColumn) + IdChatIdentifier(RawChatId(get(chatIdColumn)), get(threadIdColumn) ?.let(::MessageThreadId)), + MessageId(get(messageIdColumn)) ) init { initTable() } - override fun update(k: PollIdentifier, v: ShortMessageInfo, it: UpdateBuilder) { - it[chatIdColumn] = v.chatId.chatId - it[threadIdColumn] = v.chatId.threadId - it[messageIdColumn] = v.messageId + override fun update(k: PollId, v: ShortMessageInfo, it: UpdateBuilder) { + it[chatIdColumn] = v.chatId.chatId.long + it[threadIdColumn] = v.chatId.threadId ?.long + it[messageIdColumn] = v.messageId.long } - override fun insertKey(k: PollIdentifier, v: ShortMessageInfo, it: InsertStatement) { - it[keyColumn] = k + override fun insertKey(k: PollId, v: ShortMessageInfo, it: InsertStatement) { + it[keyColumn] = k.string } } diff --git a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt index d68ed9c..e8b5b0a 100644 --- a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt +++ b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToPostsIdsRepo.kt @@ -3,19 +3,19 @@ package dev.inmo.plaguposter.ratings.source.repos import dev.inmo.micro_utils.repos.exposed.initTable import dev.inmo.micro_utils.repos.exposed.keyvalue.AbstractExposedKeyValueRepo import dev.inmo.plaguposter.posts.models.PostId -import dev.inmo.tgbotapi.types.PollIdentifier +import dev.inmo.tgbotapi.types.PollId import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.statements.* class ExposedPollsToPostsIdsRepo( database: Database -) : PollsToPostsIdsRepo, AbstractExposedKeyValueRepo(database, "polls_to_posts") { +) : PollsToPostsIdsRepo, AbstractExposedKeyValueRepo(database, "polls_to_posts") { override val keyColumn = text("poll_id") val postIdColumn = text("postId") - override val selectById: ISqlExpressionBuilder.(PollIdentifier) -> Op = { keyColumn.eq(it) } + override val selectById: ISqlExpressionBuilder.(PollId) -> Op = { keyColumn.eq(it.string) } override val selectByValue: ISqlExpressionBuilder.(PostId) -> Op = { postIdColumn.eq(it.string) } - override val ResultRow.asKey: PollIdentifier - get() = get(keyColumn) + override val ResultRow.asKey: PollId + get() = PollId(get(keyColumn)) override val ResultRow.asObject: PostId get() = get(postIdColumn).let(::PostId) @@ -23,11 +23,11 @@ class ExposedPollsToPostsIdsRepo( initTable() } - override fun update(k: PollIdentifier, v: PostId, it: UpdateBuilder) { + override fun update(k: PollId, v: PostId, it: UpdateBuilder) { it[postIdColumn] = v.string } - override fun insertKey(k: PollIdentifier, v: PostId, it: InsertStatement) { - it[keyColumn] = k + override fun insertKey(k: PollId, v: PostId, it: InsertStatement) { + it[keyColumn] = k.string } } diff --git a/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt b/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt index ab3e1e8..8e3e0ec 100644 --- a/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt +++ b/ratings/src/commonMain/kotlin/repo/CachedRatingsRepo.kt @@ -2,7 +2,7 @@ package dev.inmo.plaguposter.ratings.repo import dev.inmo.micro_utils.pagination.utils.doForAllWithNextPaging import dev.inmo.micro_utils.repos.KeyValueRepo -import dev.inmo.micro_utils.repos.cache.cache.FullKVCache +import dev.inmo.micro_utils.repos.MapKeyValueRepo import dev.inmo.micro_utils.repos.cache.full.FullKeyValueCacheRepo import dev.inmo.plaguposter.posts.models.PostId import dev.inmo.plaguposter.ratings.models.Rating @@ -11,7 +11,7 @@ import kotlinx.coroutines.CoroutineScope class CachedRatingsRepo( private val base: RatingsRepo, private val scope: CoroutineScope, - private val kvCache: FullKVCache = FullKVCache() + private val kvCache: MapKeyValueRepo = MapKeyValueRepo() ) : RatingsRepo, KeyValueRepo by FullKeyValueCacheRepo(base, kvCache, scope) { override suspend fun getPosts( range: ClosedRange, diff --git a/ratings/src/jvmMain/kotlin/Plugin.kt b/ratings/src/jvmMain/kotlin/Plugin.kt index de859d7..5afdb38 100644 --- a/ratings/src/jvmMain/kotlin/Plugin.kt +++ b/ratings/src/jvmMain/kotlin/Plugin.kt @@ -5,7 +5,6 @@ import dev.inmo.micro_utils.koin.singleWithBinds import dev.inmo.micro_utils.repos.unset import dev.inmo.plagubot.Plugin import dev.inmo.plaguposter.common.useCache -import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo import dev.inmo.plaguposter.posts.repo.PostsRepo import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo import dev.inmo.plaguposter.ratings.repo.* @@ -14,7 +13,6 @@ import kotlinx.serialization.json.* import org.jetbrains.exposed.sql.Database import org.koin.core.Koin import org.koin.core.module.Module -import org.koin.dsl.binds object Plugin : Plugin { override fun Module.setupDI(database: Database, params: JsonObject) { diff --git a/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt b/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt index 480033b..8a6dd5d 100644 --- a/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt +++ b/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt @@ -49,7 +49,7 @@ class ExposedRatingsRepo ( count: Int?, exclude: List ): Map = transaction(database) { - select { + selectAll().where { ratingsColumn.greaterEq(range.start.double).and( ratingsColumn.lessEq(range.endInclusive.double) ).and( @@ -66,7 +66,7 @@ class ExposedRatingsRepo ( count: Int?, exclude: List ) = transaction(database) { - select { ratingsColumn.greaterEq(then.double).and(keyColumn.notInList(exclude.map { it.string })) }.optionallyLimit(count).optionallyReverse(reversed).map { + selectAll().where { ratingsColumn.greaterEq(then.double).and(keyColumn.notInList(exclude.map { it.string })) }.optionallyLimit(count).optionallyReverse(reversed).map { it.asKey to it.asObject } }.toMap() @@ -77,7 +77,7 @@ class ExposedRatingsRepo ( count: Int?, exclude: List ): Map = transaction(database) { - select { ratingsColumn.lessEq(then.double).and(keyColumn.notInList(exclude.map { it.string })) }.optionallyLimit(count).optionallyReverse(reversed).map { + selectAll().where { ratingsColumn.lessEq(then.double).and(keyColumn.notInList(exclude.map { it.string })) }.optionallyLimit(count).optionallyReverse(reversed).map { it.asKey to it.asObject } }.toMap() diff --git a/triggers/command/src/jvmMain/kotlin/Plugin.kt b/triggers/command/src/jvmMain/kotlin/Plugin.kt index 6a31c1f..08fe1df 100644 --- a/triggers/command/src/jvmMain/kotlin/Plugin.kt +++ b/triggers/command/src/jvmMain/kotlin/Plugin.kt @@ -24,7 +24,7 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sameMessage import dev.inmo.tgbotapi.extensions.utils.types.buttons.dataButton import dev.inmo.tgbotapi.extensions.utils.types.buttons.flatInlineKeyboard import dev.inmo.tgbotapi.types.ChatId -import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.MessageId import dev.inmo.tgbotapi.types.buttons.InlineKeyboardButtons.CallbackDataInlineKeyboardButton import dev.inmo.tgbotapi.types.message.textsources.regular import kotlinx.coroutines.flow.first @@ -38,8 +38,8 @@ object Plugin : Plugin { @Serializable private data class PublishState( override val context: ChatId, - val sourceMessageId: MessageIdentifier, - val messageInReply: MessageIdentifier + val sourceMessageId: MessageId, + val messageInReply: MessageId ) : State @Serializable internal data class Config(