From 64f12cc6a589ef47fcff56ce3ca61c8956e37889 Mon Sep 17 00:00:00 2001 From: Cuong-Tran <16017808+cuong-tran@users.noreply.github.com> Date: Mon, 26 Jan 2026 13:59:38 +0700 Subject: [PATCH] fix(reader-chapter): Fix deletion of duplicated chapters when automatically mark as read (#1421) --- .../tachiyomi/ui/reader/ReaderViewModel.kt | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 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 8b4183d9b..1f8650d6f 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 @@ -761,7 +761,10 @@ class ReaderViewModel @JvmOverloads constructor( /** * Determines if deleting option is enabled and nth to last chapter actually exists. - * If both conditions are satisfied enqueues chapter for delete + * If both conditions are satisfied enqueues chapter for delete. + * + * This deletes chapters from reading list (filtered, unduplicated if any set). + * * @param currentChapter current chapter, which is going to be marked as read. */ private fun deleteChapterIfNeeded(currentChapter: ReaderChapter) { @@ -780,6 +783,23 @@ class ReaderViewModel @JvmOverloads constructor( } } + // KMK --> + /** + * Deletes duplicate chapters when `removeAfterReadSlots` = "Last read chapter" (0). + * + * Ignore the case where `removeAfterReadSlots` > 0 while `skipDupe` = true as we don't know + * where the chapters to be deleted are in the filtered [chapterList]. + * + * For the case where `skipDupe` = false, chapters at should be deleted normally by [deleteChapterIfNeeded] + * based on the `removeAfterReadSlots` offset while the user is reading sequentially. + */ + private fun deleteDupChapterIfNeeded(chapterToDelete: ReaderChapter) { + val removeAfterReadSlots = downloadPreferences.removeAfterReadSlots().get() + if (removeAfterReadSlots != 0) return + enqueueDeleteReadChapters(chapterToDelete) + } + // KMK <-- + /** * Saves the chapter progress (last read page and whether it's read) * if incognito mode isn't on. @@ -866,9 +886,9 @@ class ReaderViewModel @JvmOverloads constructor( chapter.chapterNumber.toFloat() == readerChapter.chapter.chapter_number ) { ChapterUpdate(id = chapter.id, read = true) - // SY --> - .also { deleteChapterIfNeeded(ReaderChapter(chapter)) } - // SY <-- + // KMK --> + .also { deleteDupChapterIfNeeded(ReaderChapter(chapter.copy(read = true))) } + // KMK <-- } else { null }