Mark chapters as read based on highest read chapter number during migration

This commit is contained in:
schroda
2026-05-08 16:02:04 +02:00
parent 06eb6a12d6
commit 3ba5edefbd
2 changed files with 16 additions and 6 deletions

View File

@@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- (**Browse**) Merge languages filter of the sources and extensions into one
- (**Search**) Hide "pinned" sources button in global search in case no sources are pinned
- (**Extensions**) Show "obsolete" information more discretely with the "uninstall" action instead of grouping obsolete extensions at the top of the page
- (**Migration**) Mark all chapters as read up to the highest read chapter number. Previously matching chapter numbers got marked as read. E.g., Read up to chapter 250. The destination has a chapter 249.5 but the original source does not. Chapter 249.5 did not get marked as read.
### Fixed

View File

@@ -138,18 +138,27 @@ export class MangaMigration {
const chaptersToMigrateTo = mangaToMigrateToInfo.fetchChapters?.chapters;
const migratableChapters = Chapters.getMatchingChapterNumberChapters(chaptersToMigrate, chaptersToMigrateTo);
const readChapters: number[] = [];
const highestReadChapterNumber = chaptersToMigrate.reduce((chapterNumber, chapterToMigrate) => {
if (chapterToMigrate.isRead && chapterNumber < chapterToMigrate.chapterNumber) {
return chapterToMigrate.chapterNumber;
}
return chapterNumber;
}, Number.MIN_SAFE_INTEGER);
const bookmarkedChapters: number[] = [];
const chapterPreDeleteIds: number[] = [];
const chapterUpdateItems: SetChapterMetasItemInput[] = [];
migratableChapters.forEach(([chapterToMigrate, chapterToMigrateTo]) => {
const { isRead, isBookmarked, meta } = chapterToMigrate;
const readChapters = Chapters.getIds(
chaptersToMigrateTo.filter(
(chapterToMigrateTo) => chapterToMigrateTo.chapterNumber <= highestReadChapterNumber,
),
);
if (isRead) {
readChapters.push(chapterToMigrateTo.id);
}
migratableChapters.forEach(([chapterToMigrate, chapterToMigrateTo]) => {
const { isBookmarked, meta } = chapterToMigrate;
if (isBookmarked) {
bookmarkedChapters.push(chapterToMigrateTo.id);