Prevent negative lastPageRead values (#1267)

Co-authored-by: Mitchell Syer <Syer10@users.noreply.github.com>
This commit is contained in:
schroda
2025-02-15 01:06:54 +01:00
committed by GitHub
parent 733ba16af2
commit c8bd39b4bf
4 changed files with 28 additions and 5 deletions

View File

@@ -385,7 +385,7 @@ object ProtoBackupImport : ProtoBackupBase() {
this[ChapterTable.manga] = mangaId
this[ChapterTable.isRead] = chapter.read
this[ChapterTable.lastPageRead] = chapter.last_page_read
this[ChapterTable.lastPageRead] = chapter.last_page_read.coerceAtLeast(0)
this[ChapterTable.isBookmarked] = chapter.bookmark
this[ChapterTable.fetchedAt] = TimeUnit.MILLISECONDS.toSeconds(chapter.date_fetch)
@@ -414,13 +414,13 @@ object ProtoBackupImport : ProtoBackupBase() {
it[ChapterTable.manga] = mangaId
it[isRead] = chapter.read
it[lastPageRead] = chapter.last_page_read
it[lastPageRead] = chapter.last_page_read.coerceAtLeast(0)
it[isBookmarked] = chapter.bookmark
}
} else {
ChapterTable.update({ (ChapterTable.url eq dbChapter[ChapterTable.url]) and (ChapterTable.manga eq mangaId) }) {
it[isRead] = chapter.read || dbChapter[isRead]
it[lastPageRead] = max(chapter.last_page_read, dbChapter[lastPageRead])
it[lastPageRead] = max(chapter.last_page_read, dbChapter[lastPageRead]).coerceAtLeast(0)
it[isBookmarked] = chapter.bookmark || dbChapter[isBookmarked]
}
}

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].coerceAtMost(pageCount - 1)
it[ChapterTable.lastPageRead] = chapterEntry[ChapterTable.lastPageRead].coerceIn(0, pageCount - 1)
}
}
}