From a96bc2c1dac96ca93afed1143969211c22b99d10 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:22:13 +0100 Subject: [PATCH] Delete chapter when read even if already marked as read ReaderControls#useUpdateCurrentPageIndex: On a page change the chapter update needs to be always queued since the deletion of downloaded chapters while reading logic is in the "ReaderService#updateChapter" function. Thus, when the update is prevented here, this logic would never get triggered. ReaderService#useUpdateChapter: In case the read status or lastPageRead of a chapter did not change, the update was not triggered. However, there might still be chapter downloads that need to be de deleted, which was never handled in such a case. --- src/modules/reader/services/ReaderControls.ts | 10 +---- src/modules/reader/services/ReaderService.ts | 42 +++++++++---------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/modules/reader/services/ReaderControls.ts b/src/modules/reader/services/ReaderControls.ts index 67ee34df..1cc9a019 100644 --- a/src/modules/reader/services/ReaderControls.ts +++ b/src/modules/reader/services/ReaderControls.ts @@ -441,18 +441,10 @@ export class ReaderControls { } const actualPageIndex = endReached ? currentChapterUpToDate.pageCount - 1 : pageIndex; - - const hasLastPageReadChanged = actualPageIndex !== currentChapterUpToDate.lastPageRead; const isLastPage = actualPageIndex === currentChapterUpToDate.pageCount - 1; - const hasIsReadChanged = (isLastPage || endReached) && !currentChapterUpToDate.isRead; - - const shouldUpdateChapter = hasLastPageReadChanged || hasIsReadChanged; - if (!shouldUpdateChapter) { - return; - } updateChapter({ - lastPageRead: hasLastPageReadChanged ? actualPageIndex : undefined, + lastPageRead: actualPageIndex, isRead: isLastPage ? true : undefined, }); }; diff --git a/src/modules/reader/services/ReaderService.ts b/src/modules/reader/services/ReaderService.ts index ad454071..ef0525e9 100644 --- a/src/modules/reader/services/ReaderService.ts +++ b/src/modules/reader/services/ReaderService.ts @@ -153,24 +153,6 @@ export class ReaderService { : [currentChapter], ); - const isUpdateRequired = chapterIdsToUpdate.some((id) => { - const chapterUpToDateData = getReaderChapterFromCache(id); - if (!chapterUpToDateData) { - return false; - } - - return ( - (patch.isRead !== undefined && patch.isRead !== chapterUpToDateData.isRead) || - (patch.lastPageRead !== undefined && - patch.lastPageRead !== chapterUpToDateData.lastPageRead) || - (patch.isBookmarked !== undefined && - patch.isBookmarked !== chapterUpToDateData.isBookmarked) - ); - }); - if (!isUpdateRequired) { - return; - } - const chapterIdsToDelete = getChapterIdsToDeleteForChapterUpdate( currentChapter, mangaChapters, @@ -181,6 +163,26 @@ export class ReaderService { shouldSkipDupChapters, ); + const isUpdateRequired = + !!chapterIdsToDelete.length || + chapterIdsToUpdate.some((id) => { + const chapterUpToDateData = getReaderChapterFromCache(id); + if (!chapterUpToDateData) { + return false; + } + + return ( + (patch.isRead !== undefined && patch.isRead !== chapterUpToDateData.isRead) || + (patch.lastPageRead !== undefined && + patch.lastPageRead !== chapterUpToDateData.lastPageRead) || + (patch.isBookmarked !== undefined && + patch.isBookmarked !== chapterUpToDateData.isBookmarked) + ); + }); + if (!isUpdateRequired) { + return; + } + await requestManager .updateChapters( chapterIdsToUpdate, @@ -197,9 +199,7 @@ export class ReaderService { .response.catch(defaultPromiseErrorHandler('ReaderService::useUpdateChapter')); }; - ReaderService.getOrCreateChapterUpdateQueue(currentChapter.id).enqueue(`${currentChapter.id}`, () => - update(), - ); + ReaderService.getOrCreateChapterUpdateQueue(currentChapter.id).enqueue(`${currentChapter.id}`, update); }, [ manga?.id,