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.
This commit is contained in:
@@ -441,18 +441,10 @@ export class ReaderControls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const actualPageIndex = endReached ? currentChapterUpToDate.pageCount - 1 : pageIndex;
|
const actualPageIndex = endReached ? currentChapterUpToDate.pageCount - 1 : pageIndex;
|
||||||
|
|
||||||
const hasLastPageReadChanged = actualPageIndex !== currentChapterUpToDate.lastPageRead;
|
|
||||||
const isLastPage = actualPageIndex === currentChapterUpToDate.pageCount - 1;
|
const isLastPage = actualPageIndex === currentChapterUpToDate.pageCount - 1;
|
||||||
const hasIsReadChanged = (isLastPage || endReached) && !currentChapterUpToDate.isRead;
|
|
||||||
|
|
||||||
const shouldUpdateChapter = hasLastPageReadChanged || hasIsReadChanged;
|
|
||||||
if (!shouldUpdateChapter) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateChapter({
|
updateChapter({
|
||||||
lastPageRead: hasLastPageReadChanged ? actualPageIndex : undefined,
|
lastPageRead: actualPageIndex,
|
||||||
isRead: isLastPage ? true : undefined,
|
isRead: isLastPage ? true : undefined,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -153,24 +153,6 @@ export class ReaderService {
|
|||||||
: [currentChapter],
|
: [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(
|
const chapterIdsToDelete = getChapterIdsToDeleteForChapterUpdate(
|
||||||
currentChapter,
|
currentChapter,
|
||||||
mangaChapters,
|
mangaChapters,
|
||||||
@@ -181,6 +163,26 @@ export class ReaderService {
|
|||||||
shouldSkipDupChapters,
|
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
|
await requestManager
|
||||||
.updateChapters(
|
.updateChapters(
|
||||||
chapterIdsToUpdate,
|
chapterIdsToUpdate,
|
||||||
@@ -197,9 +199,7 @@ export class ReaderService {
|
|||||||
.response.catch(defaultPromiseErrorHandler('ReaderService::useUpdateChapter'));
|
.response.catch(defaultPromiseErrorHandler('ReaderService::useUpdateChapter'));
|
||||||
};
|
};
|
||||||
|
|
||||||
ReaderService.getOrCreateChapterUpdateQueue(currentChapter.id).enqueue(`${currentChapter.id}`, () =>
|
ReaderService.getOrCreateChapterUpdateQueue(currentChapter.id).enqueue(`${currentChapter.id}`, update);
|
||||||
update(),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
manga?.id,
|
manga?.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user