2016-10-14 22:42:45 +13:00
|
|
|
|
2018-10-17 21:33:54 +13:00
|
|
|
import * as helpers from '../../helpers';
|
2017-08-16 12:40:27 +12:00
|
|
|
|
2016-10-14 22:42:45 +13:00
|
|
|
export default function reducer(mopidy = {}, action){
|
2017-10-10 13:05:28 +13:00
|
|
|
switch (action.type){
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2018-11-02 16:10:38 +13:00
|
|
|
case 'MOPIDY_SET':
|
|
|
|
|
return Object.assign({}, mopidy, action.data);
|
|
|
|
|
|
2016-11-06 15:47:37 +13:00
|
|
|
case 'MOPIDY_CONNECT':
|
|
|
|
|
case 'MOPIDY_CONNECTING':
|
2018-11-02 16:10:38 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
|
|
|
|
connected: false,
|
|
|
|
|
connecting: true
|
|
|
|
|
});
|
2018-04-16 21:58:38 +12:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'MOPIDY_CONNECTED':
|
2018-11-02 16:10:38 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
|
|
|
|
connected: true,
|
|
|
|
|
connecting: false,
|
|
|
|
|
restart_running: false,
|
|
|
|
|
upgrade_running: false
|
|
|
|
|
});
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'MOPIDY_DISCONNECTED':
|
2018-11-02 16:10:38 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
|
|
|
|
connected: false,
|
|
|
|
|
connecting: false
|
|
|
|
|
});
|
2016-10-14 22:42:45 +13:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
case 'MOPIDY_CHANGE_TRACK':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
2016-10-21 09:56:07 +13:00
|
|
|
tlid: action.tlid
|
2016-10-16 12:37:37 +13:00
|
|
|
});
|
|
|
|
|
|
2018-02-26 10:25:56 +13:00
|
|
|
case 'MOPIDY_URI_SCHEMES':
|
2016-11-06 18:29:49 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
uri_schemes: action.uri_schemes
|
2016-11-06 18:29:49 +13:00
|
|
|
});
|
2016-10-21 23:27:50 +13:00
|
|
|
|
2018-11-02 16:10:38 +13:00
|
|
|
case 'MOPIDY_RESTART_STARTED':
|
|
|
|
|
return Object.assign({}, mopidy, { restart_running: true });
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_RESTART_FINISHED':
|
|
|
|
|
return Object.assign({}, mopidy, { restart_running: false });
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_UPGRADE_STARTED':
|
|
|
|
|
return Object.assign({}, mopidy, { upgrade_running: true });
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_UPGRADE_FINISHED':
|
|
|
|
|
return Object.assign({}, mopidy, { upgrade_running: false });
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_LOCAL_SCAN_STARTED':
|
|
|
|
|
return Object.assign({}, mopidy, { local_scan_running: true });
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_LOCAL_SCAN_FINISHED':
|
|
|
|
|
return Object.assign({}, mopidy, { local_scan_running: false });
|
2018-06-10 10:02:31 +12:00
|
|
|
|
2016-10-21 23:27:50 +13:00
|
|
|
|
2016-10-16 12:37:37 +13:00
|
|
|
/**
|
2016-11-06 18:29:49 +13:00
|
|
|
* State-oriented actions
|
2016-10-16 12:37:37 +13:00
|
|
|
**/
|
2018-02-26 10:25:56 +13:00
|
|
|
case 'MOPIDY_PLAY_STATE':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
play_state: action.play_state
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
case 'MOPIDY_CONSUME':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
consume: action.consume
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
case 'MOPIDY_RANDOM':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
random: action.random
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
case 'MOPIDY_REPEAT':
|
2016-10-14 22:42:45 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
repeat: action.repeat
|
2016-10-14 22:42:45 +13:00
|
|
|
});
|
|
|
|
|
|
2016-11-06 18:29:49 +13:00
|
|
|
case 'MOPIDY_VOLUME':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
volume: action.volume
|
2016-11-06 18:29:49 +13:00
|
|
|
});
|
|
|
|
|
|
2017-05-19 11:33:06 +12:00
|
|
|
case 'MOPIDY_MUTE':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
mute: action.mute
|
2017-05-19 11:33:06 +12:00
|
|
|
});
|
|
|
|
|
|
2018-02-26 10:25:56 +13:00
|
|
|
case 'MOPIDY_TIME_POSITION':
|
2016-11-06 18:29:49 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-02-26 10:25:56 +13:00
|
|
|
time_position: action.time_position
|
2016-11-06 18:29:49 +13:00
|
|
|
});
|
|
|
|
|
|
2018-03-02 08:07:30 +13:00
|
|
|
case 'MOPIDY_QUEUE_HISTORY':
|
|
|
|
|
var history = [];
|
|
|
|
|
for (var i = 0; i < action.tracks.length; i++){
|
2017-02-10 09:06:41 +13:00
|
|
|
history.push(Object.assign(
|
|
|
|
|
{},
|
2018-03-02 08:07:30 +13:00
|
|
|
action.tracks[i][1],
|
2017-02-10 09:06:41 +13:00
|
|
|
{
|
2018-03-02 08:07:30 +13:00
|
|
|
played_at: action.tracks[i][0],
|
2017-02-10 09:06:41 +13:00
|
|
|
type: 'history'
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
return Object.assign({}, mopidy, {
|
|
|
|
|
queue_history: history
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-06 18:29:49 +13:00
|
|
|
|
|
|
|
|
/**
|
2018-09-11 21:31:30 +12:00
|
|
|
* Directories
|
|
|
|
|
* This also facilitates all backend-only music providers (SoundCloud, Dirble, etc)
|
2016-11-06 18:29:49 +13:00
|
|
|
**/
|
|
|
|
|
|
2018-09-11 21:31:30 +12:00
|
|
|
case 'MOPIDY_DIRECTORY_FLUSH':
|
|
|
|
|
return Object.assign({}, mopidy, {
|
|
|
|
|
directory: null
|
|
|
|
|
});
|
|
|
|
|
|
2016-11-02 16:51:00 +13:00
|
|
|
case 'MOPIDY_DIRECTORY_LOADED':
|
2016-11-01 07:37:18 +13:00
|
|
|
return Object.assign({}, mopidy, {
|
2018-09-11 21:31:30 +12:00
|
|
|
directory: action.directory
|
2016-11-01 07:37:18 +13:00
|
|
|
});
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Library
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_LIBRARY_PLAYLISTS_LOADED':
|
|
|
|
|
if (mopidy.library_playlists){
|
|
|
|
|
var uris = [...mopidy.library_playlists,...action.uris]
|
|
|
|
|
} else {
|
|
|
|
|
var uris = action.uris
|
|
|
|
|
}
|
2017-08-16 12:40:27 +12:00
|
|
|
return Object.assign({}, mopidy, { library_playlists: helpers.removeDuplicates(uris) })
|
2017-08-12 23:01:55 +12:00
|
|
|
|
2017-09-14 21:05:55 +12:00
|
|
|
case 'MOPIDY_LIBRARY_PLAYLISTS_LOADED_ALL':
|
|
|
|
|
return Object.assign({}, mopidy, { library_playlists_loaded_all: true })
|
|
|
|
|
|
2017-08-22 20:44:36 +12:00
|
|
|
case 'MOPIDY_LIBRARY_PLAYLIST_CREATED':
|
2019-02-01 15:38:15 +13:00
|
|
|
var library_playlists = [];
|
2017-08-22 20:44:36 +12:00
|
|
|
if (mopidy.library_playlists){
|
2019-02-01 15:38:15 +13:00
|
|
|
library_playlists = Object.assign([], mopidy.library_playlists);
|
2017-08-22 20:44:36 +12:00
|
|
|
}
|
2019-02-01 15:38:15 +13:00
|
|
|
library_playlists.push(action.key);
|
2017-08-22 20:44:36 +12:00
|
|
|
return Object.assign({}, mopidy, { library_playlists: library_playlists })
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_LIBRARY_PLAYLIST_DELETED':
|
|
|
|
|
var library_playlists = []
|
|
|
|
|
if (mopidy.library_playlists){
|
2019-02-01 15:38:15 +13:00
|
|
|
library_playlists = Object.assign([], mopidy.library_playlists);
|
|
|
|
|
library_playlists.splice(library_playlists.indexOf(action.uri), 1);
|
2017-08-22 20:44:36 +12:00
|
|
|
}
|
|
|
|
|
return Object.assign({}, mopidy, { library_playlists: library_playlists })
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
case 'MOPIDY_LIBRARY_ARTISTS_LOADED':
|
|
|
|
|
if (mopidy.library_artists){
|
|
|
|
|
var uris = [...mopidy.library_artists,...action.uris]
|
|
|
|
|
} else {
|
|
|
|
|
var uris = action.uris
|
|
|
|
|
}
|
2017-08-16 12:40:27 +12:00
|
|
|
return Object.assign({}, mopidy, { library_artists: helpers.removeDuplicates(uris) })
|
2017-08-12 23:01:55 +12:00
|
|
|
|
2018-06-10 10:02:31 +12:00
|
|
|
case 'MOPIDY_CLEAR_LIBRARY_ARTISTS':
|
|
|
|
|
return Object.assign({}, mopidy, { library_artists: null })
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
case 'MOPIDY_LIBRARY_ALBUMS_LOADED':
|
|
|
|
|
if (mopidy.library_albums){
|
|
|
|
|
var uris = [...mopidy.library_albums,...action.uris]
|
|
|
|
|
} else {
|
|
|
|
|
var uris = action.uris
|
|
|
|
|
}
|
2017-08-16 12:40:27 +12:00
|
|
|
return Object.assign({}, mopidy, { library_albums: helpers.removeDuplicates(uris) })
|
2017-08-15 16:36:50 +12:00
|
|
|
|
2018-06-10 10:02:31 +12:00
|
|
|
case 'MOPIDY_CLEAR_LIBRARY_ALBUMS':
|
|
|
|
|
return Object.assign({}, mopidy, { library_albums: null })
|
|
|
|
|
|
2017-08-31 21:13:10 +12:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Searching
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_CLEAR_SEARCH_RESULTS':
|
|
|
|
|
return Object.assign({}, mopidy, { search_results: {} });
|
|
|
|
|
|
|
|
|
|
case 'MOPIDY_SEARCH_RESULTS_LOADED':
|
|
|
|
|
|
|
|
|
|
// Fetch or create our container
|
|
|
|
|
if (mopidy.search_results){
|
|
|
|
|
var search_results = Object.assign({}, mopidy.search_results)
|
|
|
|
|
} else {
|
|
|
|
|
var search_results = {}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-04 21:04:11 +12:00
|
|
|
if (search_results[action.context]){
|
2017-08-31 21:13:10 +12:00
|
|
|
search_results[action.context] = [...search_results[action.context], ...action.results]
|
|
|
|
|
} else {
|
|
|
|
|
search_results[action.context] = action.results
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Object.assign({}, mopidy, { search_results: search_results });
|
|
|
|
|
|
2016-10-14 22:42:45 +13:00
|
|
|
default:
|
|
|
|
|
return mopidy
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|