Fix deletion of chapters while reading logic

- Consider duplicated chapters in "should delete chapter" check
- Check each duplicate if it can be deleted
This commit is contained in:
schroda
2025-08-25 01:51:09 +02:00
parent bfb10ad204
commit 403cab7d80

View File

@@ -55,27 +55,26 @@ export const getChapterIdsToDeleteForChapterUpdate = (
return []; return [];
} }
const chapterToDelete = [chapter, ...previousChapters][deleteChaptersWhileReading - 1]; const maybeChapterToDelete = [chapter, ...previousChapters][deleteChaptersWhileReading - 1];
if (!chapterToDelete) { if (!maybeChapterToDelete) {
return []; return [];
} }
const chapterToDeleteUpToDateData = getReaderChapterFromCache(chapterToDelete.id); const maybeChaptersToDelete = shouldSkipDupChapters
if (!chapterToDeleteUpToDateData) { ? Chapters.addDuplicates([maybeChapterToDelete], chapters)
: [maybeChapterToDelete];
const chaptersToDelete = maybeChaptersToDelete
.map(({ id }) => getReaderChapterFromCache(id))
.filter((chapterToDeleteUpToDateData) => chapterToDeleteUpToDateData !== null)
.filter((chapterToDeleteUpToDateData) =>
Chapters.isDeletable(chapterToDeleteUpToDateData, deleteChaptersWithBookmark),
);
if (!chaptersToDelete.length) {
return []; return [];
} }
const shouldDeleteChapter = return Chapters.getIds(chaptersToDelete);
patch.isRead && Chapters.isDeletable(chapterToDeleteUpToDateData, deleteChaptersWithBookmark);
if (!shouldDeleteChapter) {
return [];
}
if (!shouldSkipDupChapters) {
return Chapters.getIds([chapterToDelete]);
}
return Chapters.getIds(Chapters.addDuplicates([chapterToDelete], chapters));
}; };
export const isInDownloadAheadRange = ( export const isInDownloadAheadRange = (