mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-02-06 00:16:02 +01:00
Add support for hide from continue listening on new home page shelves route
This commit is contained in:
parent
efae529fac
commit
066d853156
@ -88,6 +88,10 @@ class Server {
|
|||||||
LibraryScanner.setCancelLibraryScan(libraryId)
|
LibraryScanner.setCancelLibraryScan(libraryId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLibrariesScanning() {
|
||||||
|
return LibraryScanner.librariesScanning
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize database, backups, logs, rss feeds, cron jobs & watcher
|
* Initialize database, backups, logs, rss feeds, cron jobs & watcher
|
||||||
* Cleanup stale/invalid data
|
* Cleanup stale/invalid data
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
const SocketIO = require('socket.io')
|
const SocketIO = require('socket.io')
|
||||||
const Logger = require('./Logger')
|
const Logger = require('./Logger')
|
||||||
const Database = require('./Database')
|
const Database = require('./Database')
|
||||||
const LibraryScanner = require('./scanner/LibraryScanner')
|
|
||||||
|
|
||||||
class SocketAuthority {
|
class SocketAuthority {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -181,7 +180,7 @@ class SocketAuthority {
|
|||||||
const initialPayload = {
|
const initialPayload = {
|
||||||
userId: client.user.id,
|
userId: client.user.id,
|
||||||
username: client.user.username,
|
username: client.user.username,
|
||||||
librariesScanning: LibraryScanner.librariesScanning
|
librariesScanning: this.Server.getLibrariesScanning()
|
||||||
}
|
}
|
||||||
if (user.isAdminOrUp) {
|
if (user.isAdminOrUp) {
|
||||||
initialPayload.usersOnline = this.getUsersOnline()
|
initialPayload.usersOnline = this.getUsersOnline()
|
||||||
|
@ -316,9 +316,19 @@ class MeController {
|
|||||||
|
|
||||||
// GET: api/me/progress/:id/remove-from-continue-listening
|
// GET: api/me/progress/:id/remove-from-continue-listening
|
||||||
async removeItemFromContinueListening(req, res) {
|
async removeItemFromContinueListening(req, res) {
|
||||||
|
const mediaProgress = req.user.mediaProgress.find(mp => mp.id === req.params.id)
|
||||||
|
if (!mediaProgress) {
|
||||||
|
return res.sendStatus(404)
|
||||||
|
}
|
||||||
const hasUpdated = req.user.removeProgressFromContinueListening(req.params.id)
|
const hasUpdated = req.user.removeProgressFromContinueListening(req.params.id)
|
||||||
if (hasUpdated) {
|
if (hasUpdated) {
|
||||||
await Database.updateUser(req.user)
|
await Database.mediaProgressModel.update({
|
||||||
|
hideFromContinueListening: true
|
||||||
|
}, {
|
||||||
|
where: {
|
||||||
|
id: mediaProgress.id
|
||||||
|
}
|
||||||
|
})
|
||||||
SocketAuthority.clientEmitter(req.user.id, 'user_updated', req.user.toJSONForBrowser())
|
SocketAuthority.clientEmitter(req.user.id, 'user_updated', req.user.toJSONForBrowser())
|
||||||
}
|
}
|
||||||
res.json(req.user.toJSONForBrowser())
|
res.json(req.user.toJSONForBrowser())
|
||||||
|
@ -49,7 +49,7 @@ module.exports = {
|
|||||||
*/
|
*/
|
||||||
async getMediaItemsInProgress(library, user, include, limit) {
|
async getMediaItemsInProgress(library, user, include, limit) {
|
||||||
if (library.mediaType === 'book') {
|
if (library.mediaType === 'book') {
|
||||||
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'in-progress', 'progress', true, false, include, limit, 0)
|
const { libraryItems, count } = await libraryItemsBookFilters.getFilteredLibraryItems(library.id, user, 'progress', 'in-progress', 'progress', true, false, include, limit, 0, true)
|
||||||
return {
|
return {
|
||||||
items: libraryItems.map(li => {
|
items: libraryItems.map(li => {
|
||||||
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
const oldLibraryItem = Database.libraryItemModel.getOldLibraryItem(li).toJSONMinified()
|
||||||
@ -61,7 +61,7 @@ module.exports = {
|
|||||||
count
|
count
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredPodcastEpisodes(library.id, user, 'progress', 'in-progress', 'progress', true, limit, 0)
|
const { libraryItems, count } = await libraryItemsPodcastFilters.getFilteredPodcastEpisodes(library.id, user, 'progress', 'in-progress', 'progress', true, limit, 0, true)
|
||||||
return {
|
return {
|
||||||
count,
|
count,
|
||||||
items: libraryItems.map(li => {
|
items: libraryItems.map(li => {
|
||||||
|
@ -337,9 +337,10 @@ module.exports = {
|
|||||||
* @param {string[]} include
|
* @param {string[]} include
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
* @param {number} offset
|
* @param {number} offset
|
||||||
|
* @param {boolean} isHomePage for home page shelves
|
||||||
* @returns {object} { libraryItems:LibraryItem[], count:number }
|
* @returns {object} { libraryItems:LibraryItem[], count:number }
|
||||||
*/
|
*/
|
||||||
async getFilteredLibraryItems(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, collapseseries, include, limit, offset) {
|
async getFilteredLibraryItems(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, collapseseries, include, limit, offset, isHomePage = false) {
|
||||||
// TODO: Handle collapse sub-series
|
// TODO: Handle collapse sub-series
|
||||||
if (filterGroup === 'series' && collapseseries) {
|
if (filterGroup === 'series' && collapseseries) {
|
||||||
collapseseries = false
|
collapseseries = false
|
||||||
@ -471,12 +472,17 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
} else if (filterGroup === 'progress' && user) {
|
} else if (filterGroup === 'progress' && user) {
|
||||||
|
const mediaProgressWhere = {
|
||||||
|
userId: user.id
|
||||||
|
}
|
||||||
|
// Respect hide from continue listening for home page shelf
|
||||||
|
if (isHomePage) {
|
||||||
|
mediaProgressWhere.hideFromContinueListening = false
|
||||||
|
}
|
||||||
bookIncludes.push({
|
bookIncludes.push({
|
||||||
model: Database.mediaProgressModel,
|
model: Database.mediaProgressModel,
|
||||||
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt'],
|
attributes: ['id', 'isFinished', 'currentTime', 'ebookProgress', 'updatedAt'],
|
||||||
where: {
|
where: mediaProgressWhere,
|
||||||
userId: user.id
|
|
||||||
},
|
|
||||||
required: false
|
required: false
|
||||||
})
|
})
|
||||||
} else if (filterGroup === 'recent') {
|
} else if (filterGroup === 'recent') {
|
||||||
|
@ -204,9 +204,10 @@ module.exports = {
|
|||||||
* @param {string} sortDesc
|
* @param {string} sortDesc
|
||||||
* @param {number} limit
|
* @param {number} limit
|
||||||
* @param {number} offset
|
* @param {number} offset
|
||||||
|
* @param {boolean} isHomePage for home page shelves
|
||||||
* @returns {object} {libraryItems:LibraryItem[], count:number}
|
* @returns {object} {libraryItems:LibraryItem[], count:number}
|
||||||
*/
|
*/
|
||||||
async getFilteredPodcastEpisodes(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, limit, offset) {
|
async getFilteredPodcastEpisodes(libraryId, user, filterGroup, filterValue, sortBy, sortDesc, limit, offset, isHomePage = false) {
|
||||||
if (sortBy === 'progress' && filterGroup !== 'progress') {
|
if (sortBy === 'progress' && filterGroup !== 'progress') {
|
||||||
Logger.warn('Cannot sort podcast episodes by progress without filtering by progress')
|
Logger.warn('Cannot sort podcast episodes by progress without filtering by progress')
|
||||||
sortBy = 'createdAt'
|
sortBy = 'createdAt'
|
||||||
@ -218,11 +219,16 @@ module.exports = {
|
|||||||
libraryId
|
libraryId
|
||||||
}
|
}
|
||||||
if (filterGroup === 'progress') {
|
if (filterGroup === 'progress') {
|
||||||
|
const mediaProgressWhere = {
|
||||||
|
userId: user.id
|
||||||
|
}
|
||||||
|
// Respect hide from continue listening for home page shelf
|
||||||
|
if (isHomePage) {
|
||||||
|
mediaProgressWhere.hideFromContinueListening = false
|
||||||
|
}
|
||||||
podcastEpisodeIncludes.push({
|
podcastEpisodeIncludes.push({
|
||||||
model: Database.mediaProgressModel,
|
model: Database.mediaProgressModel,
|
||||||
where: {
|
where: mediaProgressWhere,
|
||||||
userId: user.id
|
|
||||||
},
|
|
||||||
attributes: ['id', 'isFinished', 'currentTime', 'updatedAt']
|
attributes: ['id', 'isFinished', 'currentTime', 'updatedAt']
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user