Skip to content

fix: enqueue duplicate chapters for deletion after marking as read#3030

Open
leodyversemilla07 wants to merge 1 commit intomihonapp:mainfrom
leodyversemilla07:fix/duplicate-chapter-not-deleted
Open

fix: enqueue duplicate chapters for deletion after marking as read#3030
leodyversemilla07 wants to merge 1 commit intomihonapp:mainfrom
leodyversemilla07:fix/duplicate-chapter-not-deleted

Conversation

@leodyversemilla07
Copy link

Summary

Fixes #2454

Root Cause

In updateChapterProgressOnComplete(), when duplicate chapters are auto-marked as read (via the 'Mark duplicate chapters as read' setting), enqueueChaptersToDelete() was never called for them.

The code used mapNotNull { ChapterUpdate(...) } which immediately converted full Chapter objects into lightweight ChapterUpdate objects (only id + read flag). This discarded the full chapter data required by downloadManager.enqueueChaptersToDelete(), and the delete call was simply missing from this code path.

Change

File: app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt

Replaced mapNotNull { ChapterUpdate } with filter { Chapter } to retain full Chapter objects, then:

  • Mark duplicates read via inline .map { ChapterUpdate(...) } — identical behavior as before
  • After marking read, enqueue downloaded duplicates for deletion via downloadManager.enqueueChaptersToDelete(), using the same removeAfterReadSlots != -1 guard that protects the existing deleteChapterIfNeeded() call
// Before
val duplicateUnreadChapters = getUnfilteredChapterList()
    .mapNotNull { chapter ->
        if (!chapter.read && chapter.isRecognizedNumber &&
            chapter.chapterNumber.toFloat() == readerChapter.chapter.chapter_number
        ) {
            ChapterUpdate(id = chapter.id, read = true)
        } else { null }
    }
updateChapter.awaitAll(duplicateUnreadChapters)

// After
val duplicateChapters = getUnfilteredChapterList()
    .filter { chapter ->
        !chapter.read &&
            chapter.isRecognizedNumber &&
            chapter.chapterNumber.toFloat() == readerChapter.chapter.chapter_number
    }
updateChapter.awaitAll(duplicateChapters.map { ChapterUpdate(id = it.id, read = true) })

if (downloadPreferences.removeAfterReadSlots().get() != -1) {
    val manga = manga ?: return
    downloadManager.enqueueChaptersToDelete(duplicateChapters, manga)
}

When a chapter is completed and duplicate chapters are auto-marked as
read (via 'Mark duplicate chapters as read' setting), the downloaded
duplicate chapters were never enqueued for deletion.

Root cause: the duplicate-marking code converted Chapter objects into
ChapterUpdate objects immediately (only id + read flag), discarding the
full chapter data needed to call enqueueChaptersToDelete(). The delete
call was also simply missing.

Fix: retain full Chapter objects when collecting duplicates so they can
be passed to downloadManager.enqueueChaptersToDelete(), and add the
missing deletion call — guarded by the existing 'delete after read'
preference (removeAfterReadSlots != -1).

Fixes mihonapp#2454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate chapters marked as read are not automatically deleted

1 participant