mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Update:User getMostRecentItemProgress method to support podcast episode progress
This commit is contained in:
parent
dc156a2eac
commit
31be2ba4fb
@ -266,16 +266,42 @@ class User {
|
|||||||
return firstAccessibleLibrary.id
|
return firstAccessibleLibrary.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns most recent media progress w/ `media` object and optionally an `episode` object
|
||||||
getMostRecentItemProgress(libraryItems) {
|
getMostRecentItemProgress(libraryItems) {
|
||||||
if (!this.mediaProgress.length) return null
|
if (!this.mediaProgress.length) return null
|
||||||
var lip = this.mediaProgress.map(lip => lip.toJSON())
|
var mediaProgressObjects = this.mediaProgress.map(lip => lip.toJSON())
|
||||||
lip.sort((a, b) => b.lastUpdate - a.lastUpdate)
|
mediaProgressObjects.sort((a, b) => b.lastUpdate - a.lastUpdate)
|
||||||
var mostRecentWithLip = lip.find(li => libraryItems.find(_li => _li.id === li.id))
|
|
||||||
if (!mostRecentWithLip) return null
|
var libraryItemMedia = null
|
||||||
var libraryItem = libraryItems.find(li => li.id === mostRecentWithLip.id)
|
var progressEpisode = null
|
||||||
|
// Find the most recent progress that still has a libraryItem and episode
|
||||||
|
var mostRecentProgress = mediaProgressObjects.find((progress) => {
|
||||||
|
const libraryItem = libraryItems.find(li => li.id === progress.libraryItemId)
|
||||||
|
if (!libraryItem) {
|
||||||
|
Logger.warn('[User] Library item not found for users progress ' + progress.libraryItemId)
|
||||||
|
return false
|
||||||
|
} else if (progress.episodeId) {
|
||||||
|
const episode = libraryItem.mediaType === 'podcast' ? libraryItem.media.getEpisode(progress.episodeId) : null
|
||||||
|
if (!episode) {
|
||||||
|
Logger.warn(`[User] Episode ${progress.episodeId} not found for user media progress, podcast: ${libraryItem.media.metadata.title}`)
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
libraryItemMedia = libraryItem.media.toJSONExpanded()
|
||||||
|
progressEpisode = episode.toJSON()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
libraryItemMedia = libraryItem.media.toJSONExpanded()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!mostRecentProgress) return null
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...mostRecentWithLip,
|
...mostRecentProgress,
|
||||||
media: libraryItem.media.toJSONExpanded()
|
media: libraryItemMedia,
|
||||||
|
episode: progressEpisode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user