Merge pull request #1388 from lkiesow/continue-listening

Show next book only if previous book is finished
This commit is contained in:
advplyr 2023-01-10 16:39:59 -06:00 committed by GitHub
commit dd5c940d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -499,6 +499,7 @@ module.exports = {
for (const librarySeries of libraryItem.media.metadata.series) { for (const librarySeries of libraryItem.media.metadata.series) {
const mediaProgress = allItemProgress.length ? allItemProgress[0] : null const mediaProgress = allItemProgress.length ? allItemProgress[0] : null
const bookInProgress = mediaProgress && (mediaProgress.inProgress || mediaProgress.isFinished) const bookInProgress = mediaProgress && (mediaProgress.inProgress || mediaProgress.isFinished)
const bookActive = mediaProgress && mediaProgress.inProgress && !mediaProgress.isFinished
const libraryItemJson = libraryItem.toJSONMinified() const libraryItemJson = libraryItem.toJSONMinified()
libraryItemJson.seriesSequence = librarySeries.sequence libraryItemJson.seriesSequence = librarySeries.sequence
@ -511,6 +512,7 @@ module.exports = {
...seriesObj.toJSON(), ...seriesObj.toJSON(),
books: [libraryItemJson], books: [libraryItemJson],
inProgress: bookInProgress, inProgress: bookInProgress,
hasActiveBook: bookActive,
hideFromContinueListening, hideFromContinueListening,
bookInProgressLastUpdate: bookInProgress ? mediaProgress.lastUpdate : null, bookInProgressLastUpdate: bookInProgress ? mediaProgress.lastUpdate : null,
firstBookUnread: bookInProgress ? null : libraryItemJson firstBookUnread: bookInProgress ? null : libraryItemJson
@ -553,6 +555,11 @@ module.exports = {
seriesMap[librarySeries.id].firstBookUnread = libraryItemJson seriesMap[librarySeries.id].firstBookUnread = libraryItemJson
} }
} }
// Update if series has an active (progress < 100%) book
if (bookActive) {
seriesMap[librarySeries.id].hasActiveBook = true
}
} }
} }
} }
@ -648,10 +655,12 @@ module.exports = {
if (seriesMap[seriesId].inProgress && !seriesMap[seriesId].hideFromContinueListening) { if (seriesMap[seriesId].inProgress && !seriesMap[seriesId].hideFromContinueListening) {
seriesMap[seriesId].books = naturalSort(seriesMap[seriesId].books).asc(li => li.seriesSequence) seriesMap[seriesId].books = naturalSort(seriesMap[seriesId].books).asc(li => li.seriesSequence)
// NEW implementation takes the first book unread with the smallest series sequence // take the first book unread with the smallest series sequence
// unless the user is already listening to a book from this series
const hasActiveBook = seriesMap[seriesId].hasActiveBook
const nextBookInSeries = seriesMap[seriesId].firstBookUnread const nextBookInSeries = seriesMap[seriesId].firstBookUnread
if (nextBookInSeries) { if (!hasActiveBook && nextBookInSeries) {
const bookForContinueSeries = { const bookForContinueSeries = {
...nextBookInSeries, ...nextBookInSeries,
prevBookInProgressLastUpdate: seriesMap[seriesId].bookInProgressLastUpdate prevBookInProgressLastUpdate: seriesMap[seriesId].bookInProgressLastUpdate