Delete downloads of duplicates read along with a chapter (#3030)

Closes #3030
Fixes #2454

Co-authored-by: Leodyver Semilla <leodyversemilla07@gmail.com>
This commit is contained in:
AntsyLich
2026-10-10 02:01:41 +06:00
parent 0c1be369b0
commit 36ec043a5c
@@ -77,6 +77,7 @@ import tachiyomi.core.common.util.lang.withUIContext
import tachiyomi.core.common.util.system.logcat import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
import tachiyomi.domain.chapter.interactor.UpdateChapter import tachiyomi.domain.chapter.interactor.UpdateChapter
import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.chapter.model.ChapterUpdate import tachiyomi.domain.chapter.model.ChapterUpdate
import tachiyomi.domain.chapter.service.getChapterSort import tachiyomi.domain.chapter.service.getChapterSort
import tachiyomi.domain.download.service.DownloadPreferences import tachiyomi.domain.download.service.DownloadPreferences
@@ -564,9 +565,23 @@ class ReaderViewModel(
// If chapter is completely read, no need to download it // If chapter is completely read, no need to download it
chapterToDownload = null chapterToDownload = null
if (chapterToDelete != null) { if (chapterToDelete == null || !chapterToDelete.chapter.read) return
enqueueDeleteReadChapters(chapterToDelete)
val markDuplicateAsRead = libraryPreferences.markDuplicateReadChapterAsRead.get()
.contains(LibraryPreferences.MARK_DUPLICATE_CHAPTER_READ_EXISTING)
val duplicateChapters = if (markDuplicateAsRead) {
unfilteredChapterList
.filter {
it.id != chapterToDelete.chapter.id &&
it.isRecognizedNumber &&
it.chapterNumber.toFloat() == chapterToDelete.chapter.chapter_number
}
// The list is loaded once, before these were marked read along with chapterToDelete
.map { it.copy(read = true) }
} else {
emptyList()
} }
enqueueDeleteChapters(listOf(chapterToDelete.chapter.toDomainChapter()!!) + duplicateChapters)
} }
/** /**
@@ -959,15 +974,14 @@ class ReaderViewModel(
} }
/** /**
* Enqueues this [chapter] to be deleted when [deletePendingChapters] is called. The download * Enqueues these [chapters] to be deleted when [deletePendingChapters] is called. The download
* manager handles persisting it across process deaths. * manager handles persisting them across process deaths.
*/ */
private fun enqueueDeleteReadChapters(chapter: ReaderChapter) { private fun enqueueDeleteChapters(chapters: List<Chapter>) {
if (!chapter.chapter.read) return
val manga = manga ?: return val manga = manga ?: return
viewModelScope.launchNonCancellable { viewModelScope.launchNonCancellable {
downloadManager.enqueueChaptersToDelete(listOf(chapter.chapter.toDomainChapter()!!), manga) downloadManager.enqueueChaptersToDelete(chapters, manga)
} }
} }