Sharing of configuration and other authorizations
This commit is contained in:
@ -99,6 +99,13 @@ export function revokeAuthorization(){
|
||||
}
|
||||
}
|
||||
|
||||
export function importAuthorization(authorization){
|
||||
return {
|
||||
type: 'GENIUS_IMPORT_AUTHORIZATION',
|
||||
authorization: authorization
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get current user
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
var helpers = require('./../../helpers')
|
||||
var coreActions = require('../core/actions')
|
||||
var helpers = require('./../../helpers');
|
||||
var coreActions = require('../core/actions');
|
||||
var geniusActions = require('./actions');
|
||||
|
||||
const GeniusMiddleware = (function(){
|
||||
return store => next => action => {
|
||||
@ -38,6 +39,15 @@ const GeniusMiddleware = (function(){
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'GENIUS_IMPORT_AUTHORIZATION':
|
||||
|
||||
// Wait a few moments before we fetch, allowing the import to complete first
|
||||
// TODO: Use callbacks for better code accuracy
|
||||
setTimeout(() => {store.dispatch(geniusActions.getMe())}, 100);
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
|
||||
@ -27,6 +27,15 @@ export default function reducer(genius = {}, action){
|
||||
me: null
|
||||
});
|
||||
|
||||
case 'GENIUS_IMPORT_AUTHORIZATION':
|
||||
return Object.assign({}, genius, {
|
||||
authorizing: false,
|
||||
authorization: action.authorization,
|
||||
authorization_code: action.authorization.authorization_code,
|
||||
access_token: action.authorization.access_token,
|
||||
me: null
|
||||
})
|
||||
|
||||
default:
|
||||
return genius
|
||||
}
|
||||
|
||||
@ -152,6 +152,13 @@ export function revokeAuthorization(){
|
||||
}
|
||||
}
|
||||
|
||||
export function importAuthorization(authorization){
|
||||
return {
|
||||
type: 'LASTFM_IMPORT_AUTHORIZATION',
|
||||
authorization: authorization
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
var helpers = require('./../../helpers');
|
||||
var coreActions = require('../core/actions');
|
||||
var lastfmActions = require('./actions');
|
||||
|
||||
const LastfmMiddleware = (function(){
|
||||
|
||||
@ -20,6 +21,15 @@ const LastfmMiddleware = (function(){
|
||||
next(action);
|
||||
break;
|
||||
|
||||
case 'LASTFM_IMPORT_AUTHORIZATION':
|
||||
|
||||
// Wait a few moments before we fetch, allowing the import to complete first
|
||||
// TODO: Use callbacks for better code accuracy
|
||||
setTimeout(() => {store.dispatch(lastfmActions.getMe())}, 100);
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
default:
|
||||
return next(action);
|
||||
}
|
||||
|
||||
@ -27,7 +27,14 @@ export default function reducer(lastfm = {}, action){
|
||||
return Object.assign({}, lastfm, {
|
||||
authorizing: false,
|
||||
session: false,
|
||||
me: false
|
||||
me: null
|
||||
});
|
||||
|
||||
case 'LASTFM_IMPORT_AUTHORIZATION':
|
||||
return Object.assign({}, lastfm, {
|
||||
authorizing: false,
|
||||
session: action.authorization,
|
||||
me: null
|
||||
});
|
||||
|
||||
default:
|
||||
|
||||
@ -89,11 +89,11 @@ const PusherMiddleware = (function(){
|
||||
case 'spotify_token_changed':
|
||||
store.dispatch(spotifyActions.tokenChanged(message.params.spotify_token));
|
||||
break;
|
||||
case 'spotify_authorization_received':
|
||||
case 'share_configuration_received':
|
||||
console.log(message);
|
||||
store.dispatch(uiActions.createNotification({
|
||||
type: 'spotify-authorization-received',
|
||||
authorization: message.params.authorization,
|
||||
user: message.params.user,
|
||||
type: 'share-configuration-received',
|
||||
configuration: message.params,
|
||||
sticky: true
|
||||
}));
|
||||
break;
|
||||
@ -271,7 +271,7 @@ const PusherMiddleware = (function(){
|
||||
request(store, 'send_message', action.data)
|
||||
.then(
|
||||
response => {
|
||||
store.dispatch(uiActions.createNotification({content: 'Message delivered'}));
|
||||
store.dispatch(uiActions.createNotification({type: 'info', content: 'Message delivered'}));
|
||||
},
|
||||
error => {
|
||||
store.dispatch(coreActions.handleException(
|
||||
|
||||
@ -34,7 +34,6 @@ const SnapcastMiddleware = (function(){
|
||||
method: 'Server.GetStatus'
|
||||
},
|
||||
response => {
|
||||
console.log(response);
|
||||
store.dispatch(snapcastActions.serverLoaded(response.server));
|
||||
},
|
||||
error => {
|
||||
@ -56,7 +55,6 @@ const SnapcastMiddleware = (function(){
|
||||
next(action);
|
||||
break
|
||||
|
||||
|
||||
case 'SNAPCAST_GROUPS_LOADED':
|
||||
var groups_index = Object.assign({}, snapcast.groups);
|
||||
var groups_loaded = [];
|
||||
@ -80,7 +78,7 @@ const SnapcastMiddleware = (function(){
|
||||
action.groups = groups_loaded;
|
||||
|
||||
if (clients_loaded.length > 0){
|
||||
store.dispatch(snapcastActions.clientsLoaded(clients_loaded));
|
||||
store.dispatch(snapcastActions.clientsLoaded(clients_loaded, action.flush));
|
||||
}
|
||||
|
||||
next(action);
|
||||
@ -101,7 +99,7 @@ const SnapcastMiddleware = (function(){
|
||||
}
|
||||
|
||||
action.clients = clients_loaded;
|
||||
|
||||
|
||||
next(action);
|
||||
break;
|
||||
|
||||
@ -241,6 +239,8 @@ const SnapcastMiddleware = (function(){
|
||||
client_commands_index[action.id] = client_command;
|
||||
|
||||
store.dispatch(snapcastActions.clientCommandsUpdated(client_commands_index));
|
||||
|
||||
next(action);
|
||||
break
|
||||
|
||||
case 'SNAPCAST_SEND_CLIENT_COMMAND':
|
||||
@ -249,6 +249,7 @@ const SnapcastMiddleware = (function(){
|
||||
// We try and make it cross-origin compatible
|
||||
var command = JSON.parse(action.command);
|
||||
command.crossDomain = true;
|
||||
command.dataType = "jsonp";
|
||||
|
||||
$.ajax(command)
|
||||
.then(
|
||||
@ -387,7 +388,7 @@ const SnapcastMiddleware = (function(){
|
||||
));
|
||||
}
|
||||
);
|
||||
break
|
||||
break;
|
||||
|
||||
case 'SNAPCAST_SET_GROUP_VOLUME':
|
||||
var clients_to_update = [];
|
||||
@ -423,6 +424,7 @@ const SnapcastMiddleware = (function(){
|
||||
|
||||
store.dispatch(snapcastActions.setClientVolume(client_to_update.id, volume));
|
||||
}
|
||||
break;
|
||||
|
||||
// This action is irrelevant to us, pass it on to the next middleware
|
||||
default:
|
||||
|
||||
@ -5,16 +5,6 @@ export default function reducer(snapcast = {}, action){
|
||||
case 'SNAPCAST_SERVER_LOADED':
|
||||
var server = Object.assign({}, action.server);
|
||||
return Object.assign({}, snapcast, { server: server });
|
||||
break;
|
||||
|
||||
case 'SNAPCAST_SET_CLIENT_COMMAND':
|
||||
var client_commands = snapcast.client_commands[action.id];
|
||||
if (!client_commands){
|
||||
client.commands = {};
|
||||
}
|
||||
client_commands[action.name] = action.command;
|
||||
action.client_commands = client_commands;
|
||||
break
|
||||
|
||||
case 'SNAPCAST_CLIENT_COMMANDS_UPDATED':
|
||||
return Object.assign({}, snapcast, { client_commands: action.client_commands });
|
||||
|
||||
@ -239,10 +239,9 @@ export function tokenChanged(spotify_token){
|
||||
}
|
||||
}
|
||||
|
||||
export function importAuthorization(user, authorization){
|
||||
export function importAuthorization(authorization){
|
||||
return {
|
||||
type: 'SPOTIFY_IMPORT_AUTHORIZATION',
|
||||
user: user,
|
||||
authorization: authorization
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,19 +50,16 @@ const SpotifyMiddleware = (function(){
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_IMPORT_AUTHORIZATION':
|
||||
if (store.getState().ui.allow_reporting){
|
||||
var hashed_username = null
|
||||
if (store.getState().spotify.me){
|
||||
hashed_username = md5(store.getState().spotify.me);
|
||||
ReactGA.set({userId: hashed_username});
|
||||
}
|
||||
ReactGA.event({category: 'Spotify', action: 'Authorization imported', label: hashed_username});
|
||||
}
|
||||
|
||||
// Flush out the previous user's library
|
||||
store.dispatch(spotifyActions.flushLibrary());
|
||||
|
||||
// Pass to reducer
|
||||
next(action);
|
||||
|
||||
// Then get the new user
|
||||
store.dispatch(spotifyActions.getMe());
|
||||
|
||||
break;
|
||||
|
||||
case 'SPOTIFY_RECOMMENDATIONS_LOADED':
|
||||
|
||||
@ -43,8 +43,8 @@ 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: action.user
|
||||
})
|
||||
me: false
|
||||
});
|
||||
|
||||
case 'SPOTIFY_TOKEN_REFRESHING':
|
||||
return Object.assign({}, spotify, { refreshing_token: true })
|
||||
|
||||
Reference in New Issue
Block a user