Resolving radio seeds
This commit is contained in:
@ -412,6 +412,45 @@ export function following(uri, method = 'GET'){
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve radio seeds into full objects
|
||||
*
|
||||
* @param radio object
|
||||
**/
|
||||
export function resolveRadioSeeds( radio ){
|
||||
return (dispatch, getState) => {
|
||||
|
||||
// flush out the previous store value
|
||||
dispatch({ type: 'PUSHER_RADIO_SEEDS_RESOLVING' });
|
||||
|
||||
var resolved_seeds = {
|
||||
seed_artists: [],
|
||||
seed_tracks: [],
|
||||
seed_genres: []
|
||||
}
|
||||
|
||||
var artist_ids = '';
|
||||
for (var i = 0; i < radio.seed_artists.length; i++){
|
||||
if (i > 0) artist_ids += ','
|
||||
artist_ids += helpers.getFromUri('artistid', radio.seed_artists[i])
|
||||
}
|
||||
|
||||
$.when(
|
||||
sendRequest( dispatch, getState, 'artists/'+ artist_ids )
|
||||
.then( response => {
|
||||
if (!(response instanceof Array)) response = [response]
|
||||
Object.assign(resolved_seeds.seed_artists, response);
|
||||
})
|
||||
|
||||
).then( () => {
|
||||
dispatch({
|
||||
type: 'PUSHER_RADIO_SEEDS_RESOLVED',
|
||||
data: resolved_seeds
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* =============================================================== ARTIST(S) ============
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
|
||||
var helpers = require('./../../helpers.js')
|
||||
var spotifyActions = require('./actions.js')
|
||||
var uiActions = require('../ui/actions.js')
|
||||
|
||||
@ -81,6 +81,19 @@ const SpotifyMiddleware = (function(){
|
||||
if( action.data && action.data.track.uri.substring(0,14) == 'spotify:track:' ){
|
||||
store.dispatch( spotifyActions.getTrack( action.data.track.uri ) )
|
||||
}
|
||||
break
|
||||
|
||||
// when our mopidy server current track changes
|
||||
case 'PUSHER_RADIO':
|
||||
|
||||
// proceed as usual so we don't inhibit default functionality
|
||||
next(action)
|
||||
|
||||
// only resolve if radio is enabled
|
||||
if( action.data.radio.enabled ){
|
||||
store.dispatch( spotifyActions.resolveRadioSeeds( action.data.radio ) )
|
||||
}
|
||||
break
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user