Skip to content

Commit

Permalink
Merging from develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jaedb committed Nov 12, 2020
2 parents 1278c32 + 2d359f1 commit de0a32c
Show file tree
Hide file tree
Showing 14 changed files with 632 additions and 261 deletions.
446 changes: 305 additions & 141 deletions mopidy_iris/static/app.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion mopidy_iris/static/app.js.map

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions mopidy_iris/static/app.min.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions mopidy_iris/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@

// Release details
// These are automatically injected to built HTML
<<<<<<< HEAD
var build = "1605168574";
=======
var build = "1605167537";
>>>>>>> develop
var version = "3.54.0";

// Construct the script tag
Expand Down
32 changes: 24 additions & 8 deletions src/js/services/mopidy/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const MopidyMiddleware = (function () {
};

// Give a 5-second leeway for allowing Mopidy to connect, if it isn't already connected
if (store.getState().mopidy.connected) {
if (socket) {
doRequest();
} else {
console.info('Mopidy not yet connected, waiting 2 seconds');
Expand Down Expand Up @@ -1606,19 +1606,35 @@ const MopidyMiddleware = (function () {
store.dispatch({
type: 'MOPIDY_DIRECTORY_FLUSH',
});
const uri = action.uri ? decodeURIComponent(action.uri) : null;

if (action.uri) {
request(store, 'library.lookup', { uris: [action.uri] })
if (uri) {
request(store, 'library.lookup', { uris: [uri] })
.then((response) => {
if (!response[action.uri] || !response[action.uri].length) return;
const {
[uri]: results = [],
} = response;

if (!results.length) return;

let result = results[0];
if (result.album) {
result = {
...result,
name: result.album.name,
};
}

store.dispatch({
type: 'MOPIDY_DIRECTORY_LOADED',
directory: formatSimpleObject(response[action.uri][0]),
directory: {
...formatSimpleObject(result),
},
});
});
}

request(store, 'library.browse', { uri: action.uri })
request(store, 'library.browse', { uri })
.then((response) => {
const tracks_uris = [];
const tracks = [];
Expand All @@ -1643,8 +1659,8 @@ const MopidyMiddleware = (function () {
}
return {
...subdir,
images: images,
}
images,
};
});

store.dispatch({
Expand Down
155 changes: 103 additions & 52 deletions src/js/services/spotify/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,13 @@ export function getMore(url, core_action = null, custom_action = null, extra_dat
export function getSearchResults({ type, term }, limit = 50, offset = 0) {
const processKey = 'SPOTIFY_GET_SEARCH_RESULTS';
return (dispatch, getState) => {
const {
spotify: {
me: {
id: meId,
} = {},
},
} = getState();
dispatch(uiActions.startProcess(processKey, { content: 'Searching Spotify' }));

let typeString = type.replace(/s+$/, '');
Expand Down Expand Up @@ -602,7 +609,7 @@ export function getSearchResults({ type, term }, limit = 50, offset = 0) {
if (response.playlists !== undefined) {
const playlists = response.playlists.items.map((item) => ({
...formatPlaylist(item),
can_edit: (getState().spotify.me && item.owner.id === getState().spotify.me.id),
can_edit: (meId === item.owner.id),
}));
dispatch(coreActions.searchResultsLoaded(
{ term, type },
Expand Down Expand Up @@ -747,8 +754,15 @@ export function following(uri, method = 'GET') {
}
break;
case 'playlist':
const {
spotify: {
me: {
id: meId,
} = {},
},
} = getState();
if (method === 'GET') {
endpoint = `playlists/${getFromUri('playlistid', uri)}/followers/contains?ids=${getState().spotify.me.id}`;
endpoint = `playlists/${getFromUri('playlistid', uri)}/followers/contains?ids=${meId}`;
} else {
endpoint = `playlists/${getFromUri('playlistid', uri)}/followers?`;
}
Expand Down Expand Up @@ -1221,8 +1235,15 @@ export function createPlaylist(name, description, is_public, is_collaborative) {
public: is_public,
collaborative: is_collaborative,
};
const {
spotify: {
me: {
id: meId,
} = {},
},
} = getState();

request(dispatch, getState, `users/${getState().spotify.me.id}/playlists/`, 'POST', data)
request(dispatch, getState, `users/${meId}/playlists/`, 'POST', data)
.then(
(response) => {
dispatch(coreActions.itemLoaded({
Expand Down Expand Up @@ -1256,18 +1277,25 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
public: is_public,
collaborative: is_collaborative,
};
const {
spotify: {
me: {
id: meId,
} = {},
},
} = getState();

// Update the playlist fields
request(
dispatch, getState, `users/${getState().spotify.me.id}/playlists/${getFromUri('playlistid', uri)}`, 'PUT', data,
dispatch, getState, `users/${meId}/playlists/${getFromUri('playlistid', uri)}`, 'PUT', data,
)
.then(
(response) => {
dispatch(uiActions.createNotification({ level: 'warning', content: 'Playlist saved' }));

// Save the image
if (image) {
request(dispatch, getState, `users/${getState().spotify.me.id}/playlists/${getFromUri('playlistid', uri)}/images`, 'PUT', image)
request(dispatch, getState, `users/${meId}/playlists/${getFromUri('playlistid', uri)}/images`, 'PUT', image)
.then(

(response) => {
Expand Down Expand Up @@ -1314,8 +1342,65 @@ export function savePlaylist(uri, name, description, is_public, is_collaborative
};
}

export function getPlaylist(uri, { full, forceRefetch, callbackAction } = {}) {
export function getPlaylistTracks(uri, { forceRefetch, callbackAction } = {}) {
return (dispatch, getState) => {
let initialEndpoint = `playlists/${getFromUri('playlistid', uri)}/tracks`;
initialEndpoint += `?market=${getState().spotify.country}`;
if (forceRefetch) initialEndpoint += `&refetch=${Date.now()}`;

let tracks = [];

const fetchTracks = (endpoint) => request(dispatch, getState, endpoint)
.then((response) => {
tracks = [...tracks, ...formatTracks(response.items)];
if (response.next) {
fetchTracks(response.next);
} else {
dispatch(coreActions.itemLoaded({
uri,
tracks: injectSortId(tracks), // only inject sort_id when we've loaded them all
}));

if (callbackAction) {
switch (callbackAction.name) {
case 'enqueue':
dispatch(mopidyActions.enqueueURIs(
arrayOf('uri', tracks),
uri,
callbackAction.play_next,
callbackAction.at_position,
callbackAction.offset,
));
break;
case 'play':
dispatch(mopidyActions.playURIs(
arrayOf('uri', tracks),
uri,
callbackAction.shuffle,
));
break;
default:
break;
}
}
}
});

fetchTracks(initialEndpoint);
}
}

export function getPlaylist(uri, options) {
const { full, forceRefetch } = options;

return (dispatch, getState) => {
const {
spotify: {
me: {
id: meId,
} = {},
},
} = getState();
let endpoint = `playlists/${getFromUri('playlistid', uri)}`;
endpoint += `?market=${getState().spotify.country}`;
if (forceRefetch) endpoint += `&refetch=${Date.now()}`;
Expand All @@ -1329,9 +1414,6 @@ export function getPlaylist(uri, { full, forceRefetch, callbackAction } = {}) {
request(dispatch, getState, endpoint)
.then(
(response) => {
let tracks = injectSortId(formatTracks(response.tracks.items));

// convert links in description
let description = null;
if (response.description) {
description = response.description;
Expand All @@ -1342,54 +1424,16 @@ export function getPlaylist(uri, { full, forceRefetch, callbackAction } = {}) {

dispatch(coreActions.itemLoaded({
...formatPlaylist(response),
can_edit: (getState().spotify.me && getState().spotify.me.id === response.owner.id),
can_edit: (meId === response.owner.id),
description,
// Remove tracks unless we're looking for the full object. This allows our detector
// Remove tracks. They're handed by another query which allows our detector
// to accurately identify whether we've loaded *ALL* the tracks. Without this, it
// doesn't know if we've loaded all tracks, or just the first page.
...(full ? {} : { tracks: null }),
tracks: null,
}));

if (full) {
const fetchTracks = (endpoint) => request(dispatch, getState, endpoint)
.then((response) => {
tracks = [...tracks, ...formatTracks(response.items)];
if (response.next) {
fetchTracks(response.next);
} else {
dispatch(coreActions.itemLoaded({
uri,
tracks: injectSortId(tracks),
}));

if (callbackAction) {
switch (callbackAction.name) {
case 'enqueue':
dispatch(mopidyActions.enqueueURIs(
arrayOf('uri', tracks),
uri,
callbackAction.play_next,
callbackAction.at_position,
callbackAction.offset,
));
break;
case 'play':
dispatch(mopidyActions.playURIs(
arrayOf('uri', tracks),
uri,
callbackAction.shuffle,
));
break;
default:
break;
}
}
}
});

if (response.tracks.next) {
fetchTracks(response.tracks.next);
}
dispatch(getPlaylistTracks(uri, options));
};
},
(error) => {
Expand Down Expand Up @@ -1495,6 +1539,13 @@ export function flushLibrary() {

export function getLibraryPlaylists(forceRefetch) {
return (dispatch, getState) => {
const {
spotify: {
me: {
id: meId,
} = {},
},
} = getState();
const processKey = 'SPOTIFY_GET_LIBRARY_PLAYLISTS';
dispatch(uiActions.startProcess(processKey, { notification: false }));

Expand All @@ -1517,7 +1568,7 @@ export function getLibraryPlaylists(forceRefetch) {
(item) => ({
...formatPlaylist(item),
in_library: true,
can_edit: (getState().spotify.me && item.owner.id === getState().spotify.me.id),
can_edit: (meId === item.owner.id),
}),
);
libraryItems = [...libraryItems, ...items];
Expand Down
Loading

0 comments on commit de0a32c

Please sign in to comment.