diff --git a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt index 642ef41..8d7ef0c 100644 --- a/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt +++ b/posts/src/jvmMain/kotlin/exposed/ExposedPostsRepo.kt @@ -151,7 +151,11 @@ class ExposedPostsRepo( override suspend fun getIdByChatAndMessage(chatId: IdChatIdentifier, messageId: MessageIdentifier): PostId? { return transaction(database) { with(contentRepo) { - select { chatIdColumn.eq(chatId.chatId).and(threadIdColumn.eq(chatId.threadId)).and(messageIdColumn.eq(messageId)) }.limit(1).firstOrNull() ?.get(postIdColumn) + select { + chatIdColumn.eq(chatId.chatId) + .and(chatId.threadId ?.let { threadIdColumn.eq(it) } ?: threadIdColumn.isNull()) + .and(messageIdColumn.eq(messageId)) + }.limit(1).firstOrNull() ?.get(postIdColumn) } ?.let(::PostId) } } diff --git a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt index f36cd1d..d66a00f 100644 --- a/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt +++ b/ratings/source/src/jvmMain/kotlin/repos/ExposedPollsToMessagesInfoRepo.kt @@ -7,6 +7,8 @@ import dev.inmo.tgbotapi.types.ChatId import dev.inmo.tgbotapi.types.IdChatIdentifier import dev.inmo.tgbotapi.types.PollIdentifier import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq +import org.jetbrains.exposed.sql.SqlExpressionBuilder.isNull import org.jetbrains.exposed.sql.statements.* class ExposedPollsToMessagesInfoRepo( @@ -21,7 +23,7 @@ class ExposedPollsToMessagesInfoRepo( private val messageIdColumn = long("message_id") override val selectById: ISqlExpressionBuilder.(PollIdentifier) -> Op = { keyColumn.eq(it) } override val selectByValue: ISqlExpressionBuilder.(ShortMessageInfo) -> Op = { - chatIdColumn.eq(it.chatId.chatId).and(threadIdColumn.eq(it.chatId.threadId)).and( + chatIdColumn.eq(it.chatId.chatId).and(it.chatId.threadId ?.let { threadIdColumn.eq(it) } ?: threadIdColumn.isNull()).and( messageIdColumn.eq(it.messageId) ) }