Feature/auto download ahead (#681)

* Add "download ahead" mutation

Checks if the specified number of unread chapters, that should be downloaded, are available.
In case not enough chapters are downloaded, the number of missing unread chapters will get downloaded

* Optionally pass the latest read chapter id of a manga

In case a chapter will get marked as read, which also triggered the download ahead call, it's possible, that by the time the download ahead logic gets triggered, the chapter hasn't been marked as read yet.
This could then cause this chapter to be included in the chapters to get downloaded.
By providing the chapter id, this chapter will be used as the latest read chapter instead, and thus, not be included inn the chapters to download.
This commit is contained in:
schroda
2023-10-05 04:02:10 +02:00
committed by GitHub
parent c8865ad185
commit ef0a6f54b8
3 changed files with 113 additions and 0 deletions

View File

@@ -329,6 +329,10 @@ object DownloadManager {
dequeue(downloadQueue.filter { it.mangaId == mangaId && it.chapterIndex == chapterIndex }.toSet())
}
fun dequeue(mangaIds: List<Int>, chaptersToIgnore: List<Int> = emptyList()) {
dequeue(downloadQueue.filter { it.mangaId in mangaIds && it.chapter.id !in chaptersToIgnore }.toSet())
}
private fun dequeue(chapterDownloads: Set<DownloadChapter>) {
logger.debug { "dequeue ${chapterDownloads.size} chapters [${chapterDownloads.joinToString(separator = ", ") { "$it" }}]" }