Probably fix previously read exh chapters affect updated gallery chapters

This commit is contained in:
Jobobby04 2020-09-05 18:18:39 -04:00
parent 1fdbae5bf8
commit ea620a8c74
2 changed files with 7 additions and 6 deletions

View File

@ -86,12 +86,12 @@ interface ChapterQueries : DbProvider {
)
.prepare()
fun getChaptersReadWithUrls(urls: List<String>) = db.get()
fun getChaptersReadByUrls(urls: List<String>) = db.get()
.listOfObjects(Chapter::class.java)
.withQuery(
Query.builder()
.table(ChapterTable.TABLE)
.where("${ChapterTable.COL_URL} IN (?) AND ${ChapterTable.COL_READ} = 1")
.where("${ChapterTable.COL_URL} IN (?) AND (${ChapterTable.COL_READ} = 1 OR ${ChapterTable.COL_LAST_PAGE_READ} != 0)")
.whereArgs(urls.joinToString { "\"$it\"" })
.build()
)

View File

@ -145,12 +145,13 @@ fun syncChaptersWithSource(
}
}
}
if (readded.isEmpty() && !DebugToggles.INCLUDE_ONLY_ROOT_WHEN_LOADING_EXH_VERSIONS.enabled) {
val readChapters = db.getChaptersReadWithUrls(finalAdded.map { it.url }).executeAsBlocking()
if (dbChapters.isEmpty() && !DebugToggles.INCLUDE_ONLY_ROOT_WHEN_LOADING_EXH_VERSIONS.enabled) {
val readChapters = db.getChaptersReadByUrls(finalAdded.map { it.url }).executeAsBlocking()
val readChapterUrls = readChapters.map { it.url }
if (readChapters.isNotEmpty()) {
finalAdded.onEach { chapter ->
toAdd.filter { it.url in readChapterUrls }.onEach { chapter ->
readChapters.firstOrNull { it.url == chapter.url }?.let {
chapter.read = true
chapter.read = it.read
chapter.last_page_read = it.last_page_read
}
}