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,