-
- { this.renderSpotifyUser() }
+
+
-
-
-
Authentication
-
-
- { this.renderSendAuthorizationButton() }
+ {this.props.spotify.authentication_provider == 'http_api' ?
+
Authentication
+
+
+ { this.renderSendAuthorizationButton() }
+
+
: null}
+
+
Current user
+
+
+ { this.renderSpotifyUser() }
+
+
-
+
);
}
@@ -197,6 +208,7 @@ class Services extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
+ uri_schemes: (state.mopidy.uri_schemes ? state.mopidy.uri_schemes : []),
core: state.core,
spotify: state.spotify
}
diff --git a/src/js/components/Sidebar.js b/src/js/components/Sidebar.js
index cd29d3ff..367be4c5 100755
--- a/src/js/components/Sidebar.js
+++ b/src/js/components/Sidebar.js
@@ -68,18 +68,14 @@ class Sidebar extends React.Component{
Playlists
-
+
Artists
-
+
Albums
-
-
- Tracks
-
Browse
@@ -116,6 +112,7 @@ const mapStateToProps = (state, ownProps) => {
mopidy_connected: state.mopidy.connected,
pusher_connected: state.pusher.connected,
spotify_enabled: state.spotify.enabled,
+ spotify_access: state.spotify.access,
spotify_connected: state.spotify.connected,
spotify_authorized: state.spotify.authorized,
dragger: state.ui.dragger
diff --git a/src/js/services/mopidy/middleware.js b/src/js/services/mopidy/middleware.js
index f26650bd..9e5b238f 100755
--- a/src/js/services/mopidy/middleware.js
+++ b/src/js/services/mopidy/middleware.js
@@ -1034,8 +1034,14 @@ const MopidyMiddleware = (function(){
// Fire off our universal track index loader
store.dispatch({ type: 'TRACK_LOADED', key: action.data.track.uri, track: action.data.track })
- // Get me some images
- store.dispatch(mopidyActions.getImages('tracks',[action.data.track.uri]))
+ // We've got Spotify running, and it's a spotify track - go straight to the source!
+ if (helpers.uriSource(action.data.track.uri) == 'spotify' && store.getState().spotify.access != 'none'){
+ store.dispatch(spotifyActions.getTrack(action.data.track.uri))
+
+ // Some other source, rely on Mopidy backends to do their work
+ } else {
+ store.dispatch(mopidyActions.getImages('tracks',[action.data.track.uri]))
+ }
}
next(action)
diff --git a/src/js/services/spotify/actions.js b/src/js/services/spotify/actions.js
index 9d9ca40d..dd627ed6 100755
--- a/src/js/services/spotify/actions.js
+++ b/src/js/services/spotify/actions.js
@@ -126,7 +126,7 @@ function refreshToken( dispatch, getState ){
response.source = 'spotify'
dispatch({
type: 'SPOTIFY_TOKEN_REFRESHED',
- provider: 'spotify-http-api',
+ access_token_provider: 'http_api',
data: response
})
resolve(response)
@@ -154,7 +154,7 @@ function refreshToken( dispatch, getState ){
token.source = 'mopidy';
dispatch({
type: 'SPOTIFY_TOKEN_REFRESHED',
- provider: 'mopidy-spotify',
+ access_token_provider: 'backend',
data: token
});
resolve(token);
@@ -257,9 +257,17 @@ export function getTrack( uri ){
sendRequest( dispatch, getState, 'tracks/'+ helpers.getFromUri('trackid', uri) )
.then( response => {
+ let track = Object.assign(
+ {},
+ response,
+ {
+ images: response.album.images
+ }
+ )
dispatch({
- type: 'SPOTIFY_TRACK_LOADED',
- data: response
+ type: 'TRACK_LOADED',
+ key: uri,
+ track: track
});
}
);
diff --git a/src/js/services/spotify/reducer.js b/src/js/services/spotify/reducer.js
index 9a1d16a3..2f13b5d9 100755
--- a/src/js/services/spotify/reducer.js
+++ b/src/js/services/spotify/reducer.js
@@ -15,13 +15,21 @@ export default function reducer(spotify = {}, action){
return Object.assign({}, spotify, { connected: false, connecting: false })
case 'SPOTIFY_SET_CONFIG':
- return Object.assign({}, spotify, action.config)
+ var spotify = Object.assign({},spotify,action.config)
+
+ let access = 'none'
+ if (spotify.authentication_provider == 'http_api' && spotify.authorized){
+ access = 'full'
+ } else if (spotify.authentication_provider == 'backend' && spotify.backend_username){
+ access = 'limited'
+ }
+ spotify.access = access
+ return spotify
case 'PUSHER_SPOTIFY_TOKEN':
if( spotify.authorized ) return spotify;
return Object.assign({}, spotify, {
authorizing: false,
- authorized: false,
authorization: false,
access_token: action.data.access_token,
token_expiry: action.data.token_expiry
@@ -29,8 +37,8 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_AUTHORIZATION_GRANTED':
return Object.assign({}, spotify, {
+ access: (spotify.authentication_provider == 'http_api' ? 'full' : 'limited'),
authorizing: false,
- authorized: true,
authorization: action.data,
access_token: action.data.access_token,
refresh_token: action.data.refresh_token,
@@ -39,9 +47,9 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_AUTHORIZATION_REVOKED':
return Object.assign({}, spotify, {
+ access: (spotify.authentication_provider == 'http_api' ? 'none' : 'limited'),
authorizing: false,
authorization: false,
- authorized: false,
access_token: false,
refresh_token: false,
token_expiry: 0,
@@ -50,8 +58,9 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_IMPORT_AUTHORIZATION':
return Object.assign({}, spotify, {
+ authentication_provider: 'http_api',
+ access: 'full',
authorizing: false,
- authorized: true,
authorization: action.authorization,
access_token: action.authorization.access_token,
refresh_token: action.authorization.refresh_token,
@@ -68,7 +77,7 @@ export default function reducer(spotify = {}, action){
refreshing_token: false,
access_token: action.data.access_token,
token_expiry: action.data.token_expiry,
- provider: action.provider
+ access_token_provider: action.access_token_provider
})
case 'SPOTIFY_DISCONNECTED':
@@ -76,26 +85,6 @@ export default function reducer(spotify = {}, action){
case 'SPOTIFY_ME_LOADED':
return Object.assign({}, spotify, { me: action.data })
-/*
- case 'SPOTIFY_ARTISTS_LOADED':
- if( !action.data ) return Object.assign({}, spotify)
- return Object.assign({}, spotify, {
- artists: action.data.artists.items,
- artists_more: action.data.artists.next
- })
-
- case 'SPOTIFY_LIBRARY_ARTISTS_LOADED':
- if( !action.data ) return Object.assign({}, spotify)
- return Object.assign({}, spotify, {
- library_artists: action.data.artists.items,
- library_artists_more: action.data.artists.next
- })
-
- case 'SPOTIFY_LIBRARY_ARTISTS_LOADED_MORE':
- return Object.assign({}, spotify, {
- library_artists: [ ...spotify.library_artists, ...action.data.artists.items ],
- library_artists_more: action.data.artists.next
- })*/
case 'SPOTIFY_LIBRARY_ALBUMS_LOADED':
if( !action.data ) return Object.assign({}, spotify)
diff --git a/src/js/views/User.js b/src/js/views/User.js
index 46a639f4..864de4ec 100755
--- a/src/js/views/User.js
+++ b/src/js/views/User.js
@@ -39,8 +39,21 @@ class User extends React.Component{
}
isMe(){
- if( !this.props.spotify_authorized ) return null
- return helpers.getFromUri('userid',this.props.params.uri) == this.props.me.id
+ let userid = helpers.getFromUri('userid',this.props.params.uri)
+ switch (this.props.spotify_authentication_provider){
+ case 'backend':
+ if (this.props.spotify_authorized && this.props.me){
+ return userid == this.props.me.id
+ }
+ return false
+ break
+
+ case 'http_api':
+ return userid == this.props.spotify_backend_username
+
+ default:
+ return false
+ }
}
render(){
@@ -109,6 +122,8 @@ const mapStateToProps = (state, ownProps) => {
return {
load_queue: state.ui.load_queue,
spotify_authorized: state.spotify.authorized,
+ spotify_authentication_provider: state.spotify.authentication_provider,
+ spotify_backend_username: state.spotify.backend_username,
me: state.spotify.me,
playlists: state.core.playlists,
user: (state.core.users && state.core.users[ownProps.params.uri] !== undefined ? state.core.users[ownProps.params.uri] : false),