LastFM authorization format; Sharing config working
This commit is contained in:
@ -792,7 +792,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
playlists: state.core.playlists,
|
||||
tracks: state.core.tracks,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
lastfm_authorized: state.lastfm.session
|
||||
lastfm_authorized: state.lastfm.authorization
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -98,7 +98,7 @@ class LastfmAuthenticationFrame extends React.Component{
|
||||
Authorizing...
|
||||
</button>
|
||||
)
|
||||
} else if (this.props.authorized){
|
||||
} else if (this.props.authorization){
|
||||
return (
|
||||
<button className="destructive" onClick={() => this.props.lastfmActions.revokeAuthorization()}>Log out</button>
|
||||
)
|
||||
@ -113,7 +113,7 @@ class LastfmAuthenticationFrame extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
authorization_url: state.lastfm.authorization_url,
|
||||
authorized: state.lastfm.session,
|
||||
authorization: state.lastfm.authorization,
|
||||
authorizing: state.lastfm.authorizing
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ class FollowButton extends React.Component{
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
load_queue: state.ui.load_queue,
|
||||
lastfm_authorized: state.lastfm.session
|
||||
lastfm_authorized: state.lastfm.authorization
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,22 +10,23 @@ export default class Notifications extends React.Component{
|
||||
}
|
||||
|
||||
importConfiguration(notification_key, configuration){
|
||||
console.log("Importing configuration", configuration);
|
||||
var configurations = "";
|
||||
|
||||
if (configuration.interface){
|
||||
this.props.uiActions.set(configuration.interface);
|
||||
}
|
||||
|
||||
if (configuration.spotify_authorization){
|
||||
this.props.spotifyActions.importAuthorization(configuration.spotify_authorization);
|
||||
if (configuration.spotify){
|
||||
this.props.spotifyActions.importAuthorization(configuration.spotify.authorization, configuration.spotify.me);
|
||||
}
|
||||
|
||||
if (configuration.lastfm_authorization){
|
||||
this.props.lastfmActions.importAuthorization(configuration.lastfm_authorization);
|
||||
if (configuration.lastfm){
|
||||
this.props.lastfmActions.importAuthorization(configuration.lastfm.authorization, configuration.lastfm.me);
|
||||
}
|
||||
|
||||
if (configuration.genius_authorization){
|
||||
this.props.geniusActions.importAuthorization(configuration.genius_authorization);
|
||||
if (configuration.genius){
|
||||
this.props.geniusActions.importAuthorization(configuration.genius.authorization, configuration.genius.me);
|
||||
}
|
||||
|
||||
if (configuration.snapcast_client_commands){
|
||||
@ -67,10 +68,11 @@ export default class Notifications extends React.Component{
|
||||
<div className="content">
|
||||
<p>Another user has shared their configuration with you. This includes:</p>
|
||||
<ul>
|
||||
{notification.configuration.interface ? <li>Interface</li> : null}
|
||||
{notification.configuration.spotify_authorization ? <li>Spotify authorization</li> : null}
|
||||
{notification.configuration.lastfm_authorization ? <li>LastFM authorization</li> : null}
|
||||
{notification.configuration.genius_authorization ? <li>Genius authorization</li> : null}
|
||||
{notification.configuration.ui ? <li>User interface</li> : null}
|
||||
{notification.configuration.spotify ? <li>Spotify</li> : null}
|
||||
{notification.configuration.lastfm ? <li>LastFM</li> : null}
|
||||
{notification.configuration.genius ? <li>Genius</li> : null}
|
||||
{notification.configuration.snapcast_client_commands ? <li>Snapcast</li> : null}
|
||||
</ul>
|
||||
<p>Do you want to import this?</p>
|
||||
</div>
|
||||
|
||||
@ -35,7 +35,7 @@ class Services extends React.Component{
|
||||
if (this.props.spotify.me && this.props.core.users[this.props.spotify.me.id] === undefined){
|
||||
this.props.spotifyActions.getMe();
|
||||
}
|
||||
if (this.props.lastfm.session && this.props.core.users["lastfm:user:"+this.props.lastfm.session.name] === undefined){
|
||||
if (this.props.lastfm.authorization && this.props.core.users["lastfm:user:"+this.props.lastfm.authorization.name] === undefined){
|
||||
this.props.lastfmActions.getMe();
|
||||
}
|
||||
if (this.props.genius.me && this.props.core.users["genius:user:"+this.props.genius.me.id] === undefined){
|
||||
@ -178,7 +178,7 @@ class Services extends React.Component{
|
||||
|
||||
return (
|
||||
<div>
|
||||
{this.props.lastfm.session ? <div className="field current-user">
|
||||
{this.props.lastfm.authorization ? <div className="field current-user">
|
||||
<div className="name">Current user</div>
|
||||
<div className="input">
|
||||
<div className="text">
|
||||
@ -312,7 +312,7 @@ class Services extends React.Component{
|
||||
<div className="menu-item__title">
|
||||
LastFM
|
||||
</div>
|
||||
{this.props.lastfm.session ? <span className="status green-text">Authorized</span> : <span className="status grey-text">Read-only</span>}
|
||||
{this.props.lastfm.authorization ? <span className="status green-text">Authorized</span> : <span className="status grey-text">Read-only</span>}
|
||||
</div>
|
||||
</Link>
|
||||
<Link className={"menu-item"+(this.props.active == 'genius' ? ' menu-item--active' : '')} to={this.props.active == 'genius' ? global.baseURL+'settings' : global.baseURL+'settings/service/genius'}>
|
||||
@ -327,7 +327,7 @@ class Services extends React.Component{
|
||||
<Link className={"menu-item"+(this.props.active == 'snapcast' ? ' menu-item--active' : '')} to={this.props.active == 'snapcast' ? global.baseURL+'settings' : global.baseURL+'settings/service/snapcast'}>
|
||||
<div className="menu-item__inner">
|
||||
<Icon className="menu-item__icon" name="devices" />
|
||||
<div className="title">
|
||||
<div className="menu-item__title">
|
||||
Snapcast
|
||||
</div>
|
||||
{this.props.pusher.config.snapcast_enabled ? <span className="status green-text">Enabled</span> : <span className="status grey-text">Disabled</span>}
|
||||
|
||||
@ -87,10 +87,10 @@ const sendSignedRequest = (dispatch, getState, params) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// Not authorized
|
||||
if (!getState().lastfm.session){
|
||||
if (!getState().lastfm.authorization){
|
||||
reject({
|
||||
params: params,
|
||||
error: "No active LastFM session"
|
||||
error: "No active LastFM authorization (session)"
|
||||
});
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ const sendSignedRequest = (dispatch, getState, params) => {
|
||||
|
||||
dispatch(uiActions.startLoading(loader_key, 'lastfm_'+method));
|
||||
|
||||
params += "&sk="+getState().lastfm.session.key;
|
||||
params += "&sk="+getState().lastfm.authorization.key;
|
||||
|
||||
var config = {
|
||||
method: 'GET',
|
||||
@ -167,7 +167,7 @@ export function importAuthorization(authorization){
|
||||
|
||||
export function getMe(){
|
||||
return (dispatch, getState) => {
|
||||
var params = 'method=user.getInfo&user='+getState().lastfm.session.name
|
||||
var params = 'method=user.getInfo&user='+getState().lastfm.authorization.name
|
||||
sendRequest(dispatch, getState, params)
|
||||
.then(
|
||||
response => {
|
||||
@ -206,8 +206,8 @@ export function getTrack(uri){
|
||||
var track_name = track.name;
|
||||
var artist_name = encodeURIComponent(track.artists[0].name);
|
||||
var params = 'method=track.getInfo&track='+track_name+'&artist='+artist_name;
|
||||
if (getState().lastfm.session){
|
||||
params += '&username='+getState().lastfm.session.name;
|
||||
if (getState().lastfm.authorization){
|
||||
params += '&username='+getState().lastfm.authorization.name;
|
||||
}
|
||||
sendRequest(dispatch, getState, params)
|
||||
.then(
|
||||
|
||||
@ -20,20 +20,20 @@ export default function reducer(lastfm = {}, action){
|
||||
case 'LASTFM_AUTHORIZATION_GRANTED':
|
||||
return Object.assign({}, lastfm, {
|
||||
authorizing: false,
|
||||
session: action.data.session
|
||||
authorization: action.data.session
|
||||
})
|
||||
|
||||
case 'LASTFM_AUTHORIZATION_REVOKED':
|
||||
return Object.assign({}, lastfm, {
|
||||
authorizing: false,
|
||||
session: false,
|
||||
authorization: false,
|
||||
me: null
|
||||
});
|
||||
|
||||
case 'LASTFM_IMPORT_AUTHORIZATION':
|
||||
return Object.assign({}, lastfm, {
|
||||
authorizing: false,
|
||||
session: action.authorization,
|
||||
authorization: action.authorization,
|
||||
me: null
|
||||
});
|
||||
|
||||
|
||||
@ -67,7 +67,6 @@ const localstorageMiddleware = (function(){
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_IMPORT_AUTHORIZATION':
|
||||
case 'SPOTIFY_AUTHORIZATION_GRANTED':
|
||||
if (action.authorization !== undefined){
|
||||
var authorization = action.authorization;
|
||||
@ -85,14 +84,28 @@ const localstorageMiddleware = (function(){
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_IMPORT_AUTHORIZATION':
|
||||
helpers.setStorage(
|
||||
'spotify',
|
||||
{
|
||||
authorization: action.authorization,
|
||||
access_token: action.authorization.access_token,
|
||||
refresh_token: action.authorization.refresh_token,
|
||||
token_expiry: action.authorization.token_expiry,
|
||||
me: null
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_AUTHORIZATION_REVOKED':
|
||||
helpers.setStorage(
|
||||
'spotify',
|
||||
{
|
||||
authorization: false,
|
||||
access_token: false,
|
||||
refresh_token: false,
|
||||
token_expiry: false
|
||||
authorization: null,
|
||||
access_token: null,
|
||||
refresh_token: null,
|
||||
token_expiry: null,
|
||||
me: null
|
||||
}
|
||||
);
|
||||
break;
|
||||
@ -130,7 +143,7 @@ const localstorageMiddleware = (function(){
|
||||
helpers.setStorage(
|
||||
'lastfm',
|
||||
{
|
||||
session: action.data.session
|
||||
authorization: action.data.session
|
||||
}
|
||||
);
|
||||
break;
|
||||
@ -139,7 +152,18 @@ const localstorageMiddleware = (function(){
|
||||
helpers.setStorage(
|
||||
'lastfm',
|
||||
{
|
||||
session: null
|
||||
authorization: null,
|
||||
me: null
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'LASTFM_IMPORT_AUTHORIZATION':
|
||||
helpers.setStorage(
|
||||
'lastfm',
|
||||
{
|
||||
authorization: action.authorization,
|
||||
me: null
|
||||
}
|
||||
);
|
||||
break;
|
||||
@ -176,6 +200,18 @@ const localstorageMiddleware = (function(){
|
||||
);
|
||||
break;
|
||||
|
||||
case 'GENIUS_IMPORT_AUTHORIZATION':
|
||||
helpers.setStorage(
|
||||
'genius',
|
||||
{
|
||||
authorization: action.authorization,
|
||||
authorization_code: action.authorization.authorization_code,
|
||||
access_token: action.authorization.access_token,
|
||||
me: null
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case 'CORE_SET':
|
||||
helpers.setStorage(
|
||||
'core',
|
||||
|
||||
@ -54,12 +54,11 @@ const SpotifyMiddleware = (function(){
|
||||
// Flush out the previous user's library
|
||||
store.dispatch(spotifyActions.flushLibrary());
|
||||
|
||||
// Pass to reducer
|
||||
// Wait a few moments before we fetch, allowing the import to complete first
|
||||
// TODO: Use callbacks for better code accuracy
|
||||
setTimeout(() => {store.dispatch(spotifyActions.getMe())}, 100);
|
||||
|
||||
next(action);
|
||||
|
||||
// Then get the new user
|
||||
store.dispatch(spotifyActions.getMe());
|
||||
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_RECOMMENDATIONS_LOADED':
|
||||
|
||||
@ -43,7 +43,7 @@ export default function reducer(spotify = {}, action){
|
||||
access_token: action.authorization.access_token,
|
||||
refresh_token: action.authorization.refresh_token,
|
||||
token_expiry: action.authorization.token_expiry,
|
||||
me: false
|
||||
me: action.me
|
||||
});
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHING':
|
||||
|
||||
@ -270,7 +270,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
albums: state.core.albums,
|
||||
spotify_library_albums: state.spotify.library_albums,
|
||||
local_library_albums: state.mopidy.library_albums,
|
||||
lastfm_authorized: state.lastfm.session,
|
||||
lastfm_authorized: state.lastfm.authorization,
|
||||
spotify_authorized: state.spotify.authorization,
|
||||
genius_authorized: state.genius.authorization,
|
||||
mopidy_connected: state.mopidy.connected
|
||||
|
||||
@ -18,11 +18,11 @@ class ShareConfiguration extends React.Component {
|
||||
|
||||
this.state = {
|
||||
recipients: [],
|
||||
spotify_authorization: false,
|
||||
lastfm_authorization: false,
|
||||
genius_authorization: false,
|
||||
spotify: false,
|
||||
lastfm: false,
|
||||
genius: false,
|
||||
snapcast_client_commands: false,
|
||||
interface: true
|
||||
ui: false
|
||||
};
|
||||
}
|
||||
|
||||
@ -45,19 +45,28 @@ class ShareConfiguration extends React.Component {
|
||||
e.preventDefault();
|
||||
|
||||
var configuration = {};
|
||||
if (this.state.spotify_authorization){
|
||||
configuration.spotify_authorization = this.props.spotify_authorization;
|
||||
if (this.state.spotify){
|
||||
configuration.spotify = {
|
||||
authorization: this.props.spotify_authorization,
|
||||
me: this.props.spotify_me
|
||||
}
|
||||
}
|
||||
if (this.state.genius_authorization){
|
||||
configuration.genius_authorization = this.props.genius_authorization;
|
||||
if (this.state.genius){
|
||||
configuration.genius = {
|
||||
authorization: this.props.genius_authorization,
|
||||
me: this.props.genius_me
|
||||
}
|
||||
}
|
||||
if (this.state.lastfm_authorization){
|
||||
configuration.lastfm_authorization = this.props.lastfm_authorization;
|
||||
if (this.state.lastfm){
|
||||
configuration.lastfm = {
|
||||
authorization: this.props.lastfm_authorization,
|
||||
me: this.props.lastfm_me
|
||||
}
|
||||
}
|
||||
if (this.state.interface){
|
||||
configuration.interface = this.props.interface;
|
||||
if (this.state.ui){
|
||||
configuration.ui = this.props.ui;
|
||||
}
|
||||
if (this.state.interface){
|
||||
if (this.state.snapcast_client_commands){
|
||||
configuration.snapcast_client_commands = this.props.snapcast_client_commands;
|
||||
}
|
||||
|
||||
@ -69,7 +78,7 @@ class ShareConfiguration extends React.Component {
|
||||
);
|
||||
}
|
||||
|
||||
window.history.back();
|
||||
//window.history.back();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -133,8 +142,8 @@ class ShareConfiguration extends React.Component {
|
||||
<input
|
||||
type="checkbox"
|
||||
name="interface"
|
||||
checked={ this.state.interface }
|
||||
onChange={ e => this.setState({ interface: !this.state.interface })} />
|
||||
checked={ this.state.ui }
|
||||
onChange={ e => this.setState({ ui: !this.state.ui })} />
|
||||
<span className="label">
|
||||
UI customisation (theme, sorting, filters)
|
||||
</span>
|
||||
@ -154,9 +163,9 @@ class ShareConfiguration extends React.Component {
|
||||
{this.props.spotify_me && this.props.spotify_authorization ? <label>
|
||||
<input
|
||||
type="checkbox"
|
||||
name="spotify_authorization"
|
||||
checked={this.state.spotify_authorization}
|
||||
onChange={ e => this.setState({ spotify_authorization: !this.state.spotify_authorization })} />
|
||||
name="spotify"
|
||||
checked={this.state.spotify}
|
||||
onChange={ e => this.setState({ spotify: !this.state.spotify })} />
|
||||
<span className="label">
|
||||
Spotify authorization <span className="grey-text"> Logged in as {this.props.spotify_me.name}</span>
|
||||
</span>
|
||||
@ -166,8 +175,8 @@ class ShareConfiguration extends React.Component {
|
||||
<input
|
||||
type="checkbox"
|
||||
name="lastfm_authorization"
|
||||
checked={this.state.lastfm_authorization}
|
||||
onChange={ e => this.setState({ lastfm_authorization: !this.state.lastfm_authorization })} />
|
||||
checked={this.state.lastfm}
|
||||
onChange={ e => this.setState({ lastfm: !this.state.lastfm })} />
|
||||
<span className="label">
|
||||
LastFM authorization <span className="grey-text"> Logged in as {this.props.lastfm_me.name}</span>
|
||||
</span>
|
||||
@ -177,8 +186,8 @@ class ShareConfiguration extends React.Component {
|
||||
<input
|
||||
type="checkbox"
|
||||
name="genius_authorization"
|
||||
checked={this.state.genius_authorization}
|
||||
onChange={ e => this.setState({ genius_authorization: !this.state.genius_authorization })} />
|
||||
checked={this.state.genius}
|
||||
onChange={ e => this.setState({ genius: !this.state.genius })} />
|
||||
<span className="label">
|
||||
Genius authorization <span className="grey-text"> Logged in as {this.props.genius_me.name}</span>
|
||||
</span>
|
||||
@ -204,7 +213,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
lastfm_authorization: state.lastfm.authorization,
|
||||
lastfm_me: state.lastfm.me,
|
||||
snapcast_client_commands: state.snapcast.client_commands,
|
||||
interface: state.ui,
|
||||
ui: state.ui,
|
||||
connection_id: state.pusher.connection_id,
|
||||
connections: state.pusher.connections
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user