Browse Source

Songs in blacklisted playlists cantt be added in party mode anymore

Kristian Vos 3 years ago
parent
commit
bf413ae3a9
1 changed files with 33 additions and 0 deletions
  1. 33 0
      backend/logic/actions/stations.js

+ 33 - 0
backend/logic/actions/stations.js

@@ -2896,6 +2896,39 @@ export default {
 						.catch(next);
 				},
 
+				(song, station, next) => {
+					const excludedPlaylists = [];
+					async.eachLimit(
+						station.excludedPlaylists,
+						1,
+						(playlistId, next) => {
+							PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
+								.then(playlist => {
+									excludedPlaylists.push(playlist);
+									next();
+								})
+								.catch(next);
+						},
+						err => {
+							next(err, song, station, excludedPlaylists);
+						}
+					);
+				},
+
+				(song, station, excludedPlaylists, next) => {
+					const excludedSongs = excludedPlaylists
+						.flatMap(excludedPlaylist => excludedPlaylist.songs)
+						.reduce(
+							(items, item) =>
+								items.find(x => x.youtubeId === item.youtubeId) ? [...items] : [...items, item],
+							[]
+						);
+
+					if (excludedSongs.find(excludedSong => excludedSong._id.toString() === song._id.toString()))
+						next("That song is in an excluded playlist and cannot be played.");
+					else next(null, song, station);
+				},
+
 				(song, station, next) => {
 					song.requestedBy = session.userId;
 					song.requestedAt = Date.now();