Skip to content

Fix: Respect excluded categories when manually marking chapters as read#3130

Open
leodyversemilla07 wants to merge 1 commit intomihonapp:mainfrom
leodyversemilla07:fix/delete-after-read-exclusion
Open

Fix: Respect excluded categories when manually marking chapters as read#3130
leodyversemilla07 wants to merge 1 commit intomihonapp:mainfrom
leodyversemilla07:fix/delete-after-read-exclusion

Conversation

@leodyversemilla07
Copy link
Copy Markdown
Contributor

@leodyversemilla07 leodyversemilla07 commented Mar 24, 2026

Fixes #1521

Problem

When manually marking chapters as read via menu, the 'delete after marked as read' feature incorrectly deletes chapters even in excluded categories. This happens because:

  1. Stale data issue: Manual mark-as-read updates the database first, then checks exclusion filters using stale in-memory chapter objects that still have read=false
  2. Exclusion logic: For excluded categories, the filter is: chapters.filterNot { it.read } (only delete unread chapters to protect read ones)
  3. Result: With stale data showing read=false, the filter thinks the chapter is unread and includes it for deletion

Root Cause

The deletion logic in SetReadStatus.kt used in-memory chapter objects before they were refreshed from the database:

  • Database gets updated: chapterRepository.update(readUpdate)
  • Deletion uses old in-memory objects: downloadManager.enqueueChaptersToDelete(chapters, manga)
  • These objects still have read=false even though database has read=true

Solution

Refresh chapter data from database before deletion to ensure exclusion filters see the updated read=true status:

// Fetch fresh data from database after marking as read
val updatedChapters = chapters.mapNotNull { chapter ->
    chapterRepository.getChapterById(chapter.id)
}

// Now deletion uses correct read status
downloadManager.enqueueChaptersToDelete(updatedChapters, manga)

Comparison with Automatic Mark-as-Read

Automatic (after reading in ReaderViewModel) - works correctly:

  • Fetches fresh data: getChaptersByMangaId(manga.id)
  • Uses updated read status for deletion ✅

Manual (via menu) - was broken:

  • Uses stale in-memory data ❌
  • Bypasses exclusion filters ❌

This fix aligns manual behavior with the working automatic behavior.

Testing

  • ✅ Manual mark as read now respects excluded categories
  • ✅ Automatic mark as read continues to work as before
  • ✅ Bookmarked chapter exclusion still works correctly

Technical Details

Files Modified:

  • app/src/main/java/eu/kanade/domain/chapter/interactor/SetReadStatus.kt

Key Methods:

  • DownloadManager.getChaptersToDelete() - contains exclusion filter
  • DownloadManager.enqueueChaptersToDelete() - applies filters correctly
  • ChapterRepository.getChapterById() - fetches fresh data

The exclusion filter protects chapters in excluded categories by only deleting unread ones. With fresh data showing read=true, these chapters are correctly excluded from deletion.

Fixes mihonapp#1521

The bug occurred because manual mark-as-read used stale in-memory chapter
objects (with read=false) when checking exclusion filters, while the database
had already been updated to read=true. This caused the exclusion filter to
incorrectly identify read chapters as unread, allowing them to be deleted
even in excluded categories.

The fix refreshes chapter data from the database after marking as read,
ensuring the exclusion filter sees the correct read=true status and
properly protects chapters in excluded categories from deletion.

Changes:
- Fetch fresh chapter data from database before deletion
- Ensures exclusion filter receives updated read status
- Maintains consistency with automatic mark-as-read behavior

Testing:
- Manual mark as read now respects excluded categories
- Automatic mark as read continues to work as before
- Bookmarked chapter exclusion still works correctly
@leodyversemilla07 leodyversemilla07 force-pushed the fix/delete-after-read-exclusion branch from b276e2a to f636062 Compare March 26, 2026 08:44
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.

Delete after read exclusion categories not respected by manual Delete after Mark as Read

1 participant