Revamping radio notifications; Radio current track

This commit is contained in:
James Barnsley
2018-04-01 21:26:42 +12:00
parent 407a2d3a10
commit fcbfc64ec6
27 changed files with 346 additions and 237 deletions

View File

@ -28,7 +28,7 @@ export default function reducer(core = {}, action){
for(var i = 0; i < tracklist.length; i++){
// load our metadata (if we have any for that tlid)
if (typeof(action.queue_metadata['tlid_'+tracklist[i].tlid]) !== 'undefined'){
if (action.queue_metadata['tlid_'+tracklist[i].tlid] !== undefined){
tracklist[i] = Object.assign(
{},
tracklist[i],
@ -38,7 +38,7 @@ export default function reducer(core = {}, action){
}
return Object.assign({}, core, { current_tracklist: tracklist, queue_metadata: action.queue_metadata });
case 'PUSHER_RADIO':
case 'PUSHER_RADIO_LOADED':
case 'PUSHER_RADIO_STARTED':
case 'PUSHER_RADIO_CHANGED':
case 'PUSHER_RADIO_STOPPED':

View File

@ -1395,6 +1395,7 @@ const MopidyMiddleware = (function(){
{
uri: response.uri,
type: 'playlist',
is_completely_loaded: true,
is_mopidy: true,
tracks: (response.tracks ? response.tracks : []),
tracks_total: (response.tracks ? response.tracks.length : [])

View File

@ -128,6 +128,26 @@ export function stopRadio(){
}
}
export function radioStarted(radio){
return {
type: 'PUSHER_RADIO_STARTED',
radio: radio
}
}
export function radioChanged(radio){
return {
type: 'PUSHER_RADIO_CHANGED',
radio: radio
}
}
export function radioStopped(){
return {
type: 'PUSHER_RADIO_STOPPED'
}
}
export function debug(message = null){
return {
type: 'PUSHER_DEBUG',

View File

@ -81,6 +81,15 @@ const PusherMiddleware = (function(){
case 'notification':
store.dispatch(uiActions.createNotification(message.params.notification));
break;
case 'radio_started':
store.dispatch(pusherActions.radioStarted(message.params.radio));
break;
case 'radio_changed':
store.dispatch(pusherActions.radioChanged(message.params.radio));
break;
case 'radio_stopped':
store.dispatch(pusherActions.radioStopped());
break;
}
}
}
@ -360,7 +369,7 @@ const PusherMiddleware = (function(){
.then(
response => {
store.dispatch({
type: 'PUSHER_RADIO',
type: 'PUSHER_RADIO_LOADED',
radio: response.radio
});
},
@ -385,7 +394,7 @@ const PusherMiddleware = (function(){
}
var data = {
update: (action.type == 'PUSHER_UPDATE_RADIO'),
reset: (action.type == 'PUSHER_START_RADIO'),
seed_artists: [],
seed_genres: [],
seed_tracks: []
@ -405,6 +414,18 @@ const PusherMiddleware = (function(){
}
}
if (action.type == 'PUSHER_START_RADIO'){
store.dispatch(pusherActions.deliverBroadcast(
'notification',
{
notification: {
type: 'info',
content: store.getState().pusher.username + ' is starting radio mode'
}
}
));
}
request(store, 'change_radio', data)
.then(
response => {
@ -412,9 +433,10 @@ const PusherMiddleware = (function(){
if (response.status == 0){
store.dispatch(uiActions.createNotification({content: response.message, type: 'bad'}));
}
store.dispatch(pusherActions.radioChanged(response.radio));
},
error => {
store.dispatch(uiActions.processFinishing('PUSHER_RADIO_PROCESS'));
store.dispatch(uiActions.processFinishing('PUSHER_RADIO_PROCESS'));
store.dispatch(coreActions.handleException(
'Could not change radio',
error
@ -427,22 +449,33 @@ const PusherMiddleware = (function(){
store.dispatch(uiActions.createNotification({content: 'Stopping radio'}));
ReactGA.event({ category: 'Pusher', action: 'Stop radio' });
store.dispatch(pusherActions.deliverBroadcast(
'notification',
{
notification: {
type: 'info',
content: store.getState().pusher.username + ' stopped radio mode'
}
}
));
var data = {
seed_artists: [],
seed_genres: [],
seed_tracks: []
}
// we don't need to wait for response, as change will be broadcast
request(store, 'stop_radio', data)
break
case 'PUSHER_RADIO_STARTED':
case 'PUSHER_RADIO_CHANGED':
if (action.radio && action.radio.enabled && store.getState().spotify.enabled){
store.dispatch(spotifyActions.resolveRadioSeeds(action.radio))
}
next(action)
.then(
response => {
store.dispatch(pusherActions.radioStopped());
}, error => {
store.dispatch(coreActions.handleException(
'Could not stop radio',
error
));
}
);
break
case 'PUSHER_BROWSER_NOTIFICATION':

View File

@ -362,6 +362,7 @@ export function getFeaturedPlaylists(){
{},
response.playlists.items[i],
{
is_completely_loaded: false,
can_edit: (getState().spotify.me && response.playlists.items[i].owner.id == getState().spotify.me.id),
tracks_total: response.playlists.items[i].tracks.total
}
@ -1543,6 +1544,7 @@ export function getPlaylist(uri){
{},
response,
{
is_completely_loaded: true,
can_edit: (getState().spotify.me && response.owner.id == getState().spotify.me.id),
tracks: helpers.formatTracks(response.tracks.items),
tracks_more: response.tracks.next,

View File

@ -17,23 +17,6 @@ const SpotifyMiddleware = (function(){
switch(action.type){
case 'SPOTIFY_CONNECTED':
var hashed_username = null
if (store.getState().spotify.me){
hashed_username = md5(store.getState().spotify.me.id);
ReactGA.set({userId: hashed_username});
}
ReactGA.event({category: 'Spotify', action: 'Connected', label: hashed_username})
// TODO: remove this so we don't tap out our API limits before we even get started
// Perhaps fire this on demand? Context menu, playlists loading or AddToPlaylistModal
if (store.getState().spotify_authorized){
store.dispatch(spotifyActions.getAllLibraryPlaylists())
}
next(action);
break
case 'SPOTIFY_AUTHORIZATION_GRANTED':
ReactGA.event({category: 'Spotify', action: 'Authorization granted'});