Fix bookmarked chapters being deleted after manually marked as read

Fixes #9520
This commit is contained in:
arkon 2023-05-27 18:30:59 -04:00
parent 46efd4c134
commit 8735f3566f

View File

@ -214,9 +214,12 @@ class DownloadManager(
* @param source the source of the chapters. * @param source the source of the chapters.
*/ */
fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source) { fun deleteChapters(chapters: List<Chapter>, manga: Manga, source: Source) {
val filteredChapters = getChaptersToDelete(chapters, manga)
if (filteredChapters.isNotEmpty()) {
launchIO { launchIO {
val filteredChapters = getChaptersToDelete(chapters, manga)
if (filteredChapters.isEmpty()) {
return@launchIO
}
removeFromDownloadQueue(filteredChapters) removeFromDownloadQueue(filteredChapters)
val (mangaDir, chapterDirs) = provider.findChapterDirs(filteredChapters, manga, source) val (mangaDir, chapterDirs) = provider.findChapterDirs(filteredChapters, manga, source)
@ -229,7 +232,6 @@ class DownloadManager(
} }
} }
} }
}
/** /**
* Deletes the directory of a downloaded manga. * Deletes the directory of a downloaded manga.
@ -278,7 +280,7 @@ class DownloadManager(
* @param chapters the list of chapters to delete. * @param chapters the list of chapters to delete.
* @param manga the manga of the chapters. * @param manga the manga of the chapters.
*/ */
fun enqueueChaptersToDelete(chapters: List<Chapter>, manga: Manga) { suspend fun enqueueChaptersToDelete(chapters: List<Chapter>, manga: Manga) {
pendingDeleter.addChapters(getChaptersToDelete(chapters, manga), manga) pendingDeleter.addChapters(getChaptersToDelete(chapters, manga), manga)
} }
@ -351,22 +353,24 @@ class DownloadManager(
} }
} }
private fun getChaptersToDelete(chapters: List<Chapter>, manga: Manga): List<Chapter> { private suspend fun getChaptersToDelete(chapters: List<Chapter>, manga: Manga): List<Chapter> {
// Retrieve the categories that are set to exclude from being deleted on read // Retrieve the categories that are set to exclude from being deleted on read
val categoriesToExclude = downloadPreferences.removeExcludeCategories().get().map(String::toLong) val categoriesToExclude = downloadPreferences.removeExcludeCategories().get().map(String::toLong)
val categoriesForManga = runBlocking { getCategories.await(manga.id) } val categoriesForManga = getCategories.await(manga.id)
.map { it.id } .map { it.id }
.takeUnless { it.isEmpty() } .ifEmpty { listOf(0) }
?: listOf(0) val filteredCategoryManga = if (categoriesForManga.intersect(categoriesToExclude).isNotEmpty()) {
return if (categoriesForManga.intersect(categoriesToExclude).isNotEmpty()) {
chapters.filterNot { it.read } chapters.filterNot { it.read }
} else if (!downloadPreferences.removeBookmarkedChapters().get()) {
chapters.filterNot { it.bookmark }
} else { } else {
chapters chapters
} }
return if (!downloadPreferences.removeBookmarkedChapters().get()) {
filteredCategoryManga.filterNot { it.bookmark }
} else {
filteredCategoryManga
}
} }
fun statusFlow(): Flow<Download> = queueState fun statusFlow(): Flow<Download> = queueState