From 36ec043a5c28220cdd880dfd47dcb2f80fab8cc3 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Sat, 10 Oct 2026 02:01:41 +0600 Subject: [PATCH] Delete downloads of duplicates read along with a chapter (#3030) Closes #3030 Fixes #2454 Co-authored-by: Leodyver Semilla --- .../tachiyomi/ui/reader/ReaderViewModel.kt | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index e788eb2e4..8eb34b44c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -77,6 +77,7 @@ import tachiyomi.core.common.util.lang.withUIContext import tachiyomi.core.common.util.system.logcat import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId import tachiyomi.domain.chapter.interactor.UpdateChapter +import tachiyomi.domain.chapter.model.Chapter import tachiyomi.domain.chapter.model.ChapterUpdate import tachiyomi.domain.chapter.service.getChapterSort import tachiyomi.domain.download.service.DownloadPreferences @@ -564,9 +565,23 @@ class ReaderViewModel( // If chapter is completely read, no need to download it chapterToDownload = null - if (chapterToDelete != null) { - enqueueDeleteReadChapters(chapterToDelete) + if (chapterToDelete == null || !chapterToDelete.chapter.read) return + + 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 - * manager handles persisting it across process deaths. + * Enqueues these [chapters] to be deleted when [deletePendingChapters] is called. The download + * manager handles persisting them across process deaths. */ - private fun enqueueDeleteReadChapters(chapter: ReaderChapter) { - if (!chapter.chapter.read) return + private fun enqueueDeleteChapters(chapters: List) { val manga = manga ?: return viewModelScope.launchNonCancellable { - downloadManager.enqueueChaptersToDelete(listOf(chapter.chapter.toDomainChapter()!!), manga) + downloadManager.enqueueChaptersToDelete(chapters, manga) } }