Prevent chapter lastReadPage coerceIn error (#1272)

coerceIn throws an error in case the max value is less than the min value ("Cannot coerce value to an empty range: maximum <max> is less than minimum <min>")

Regression from c8bd39b4bf
This commit is contained in:
schroda
2025-02-15 05:05:04 +01:00
committed by GitHub
parent c4d849d6a3
commit 36cb899b91
2 changed files with 2 additions and 2 deletions

View File

@@ -85,7 +85,7 @@ class ChapterMutation {
this[ChapterTable.isBookmarked] = it
}
patch.lastPageRead?.also {
this[ChapterTable.lastPageRead] = it.coerceIn(0, chapterIdToPageCount[chapterId])
this[ChapterTable.lastPageRead] = it.coerceAtMost(chapterIdToPageCount[chapterId] ?: 0).coerceAtLeast(0)
this[ChapterTable.lastReadAt] = now
}
}

View File

@@ -159,7 +159,7 @@ private class ChapterForDownload(
ChapterTable.update({ ChapterTable.id eq chapterId }) {
val pageCount = pageList.size
it[ChapterTable.pageCount] = pageCount
it[ChapterTable.lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceIn(0, pageCount - 1)
it[ChapterTable.lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceAtMost(pageCount - 1).coerceAtLeast(0)
}
}
}