| 
														
															@@ -324,6 +324,16 @@ CacheModule.runJob("SUB", { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	} 
														 | 
														
														 | 
														
															 	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+CacheModule.runJob("SUB", { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	channel: "station.repositionSongInQueue", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	cb: res => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		WSModule.runJob("EMIT_TO_ROOM", { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			room: `station.${res.stationId}`, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			args: ["event:queue.repositionSong", res.song] 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 CacheModule.runJob("SUB", { 
														 | 
														
														 | 
														
															 CacheModule.runJob("SUB", { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	channel: "station.voteSkipSong", 
														 | 
														
														 | 
														
															 	channel: "station.voteSkipSong", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	cb: stationId => { 
														 | 
														
														 | 
														
															 	cb: stationId => { 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -3075,64 +3085,81 @@ export default { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}, 
														 | 
														
														 | 
														
															 	}, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	/** 
														 | 
														
														 | 
														
															 	/** 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	 * Reposition station queue 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * Reposition a song in station queue 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	 * 
														 | 
														
														 | 
														
															 	 * 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	 * @param session 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	 * @param stationId - the station id 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	 * @param queue - queue data 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	 * @param cb 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * @param {object} session - user session 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * @param {object} song - contains details about the song that is to be repositioned 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * @param {string} song.songId - the id of the song 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * @param {number} song.newIndex - the new position for the song in the queue 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * @param {number} song.oldIndex - the old position of the song in the queue 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * @param {string} stationId - the station id 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	 * @param {Function} cb - callback 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	 */ 
														 | 
														
														 | 
														
															 	 */ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	repositionQueue: isOwnerRequired(async function repositionQueue(session, stationId, queue, cb) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	repositionSongInQueue: isOwnerRequired(async function repositionQueue(session, song, stationId, cb) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		const stationModel = await DBModule.runJob("GET_MODEL", { modelName: "station" }, this); 
														 | 
														
														 | 
														
															 		const stationModel = await DBModule.runJob("GET_MODEL", { modelName: "station" }, this); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		async.waterfall( 
														 | 
														
														 | 
														
															 		async.waterfall( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			[ 
														 | 
														
														 | 
														
															 			[ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				next => { 
														 | 
														
														 | 
														
															 				next => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					if (!queue) return next("Invalid queue data."); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					return StationsModule.runJob("GET_STATION", { stationId }, this) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						.then(station => next(null, station)) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						.catch(next); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					if (!song || !song.songId) return next("You must provide a song to reposition."); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					return next(); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				}, 
														 | 
														
														 | 
														
															 				}, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				(station, next) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					if (!station) return next("Station not found."); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					return stationModel 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						.updateOne({ _id: stationId }, { $set: { queue } }, this) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						.then(station => next(null, station)) 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						.catch(next); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// remove song from queue 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				next => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					stationModel.updateOne({ _id: stationId }, { $pull: { queue: { songId: song.songId } } }, next); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				}, 
														 | 
														
														 | 
														
															 				}, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// add song back to queue (in new position) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				(res, next) => { 
														 | 
														
														 | 
														
															 				(res, next) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					stationModel.updateOne( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						{ _id: stationId }, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						{ $push: { queue: { $each: [song], $position: song.newIndex } } }, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						err => next(err) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				}, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				// update the cache representation of the station 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				next => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					StationsModule.runJob("UPDATE_STATION", { stationId }, this) 
														 | 
														
														 | 
														
															 					StationsModule.runJob("UPDATE_STATION", { stationId }, this) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						.then(station => next(null, station)) 
														 | 
														
														 | 
														
															 						.then(station => next(null, station)) 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						.catch(next); 
														 | 
														
														 | 
														
															 						.catch(next); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				} 
														 | 
														
														 | 
														
															 				} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			], 
														 | 
														
														 | 
														
															 			], 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			async err => { 
														 | 
														
														 | 
														
															 			async err => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				console.log(err); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				if (err) { 
														 | 
														
														 | 
														
															 				if (err) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this); 
														 | 
														
														 | 
														
															 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					this.log( 
														 | 
														
														 | 
														
															 					this.log( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						"ERROR", 
														 | 
														
														 | 
														
															 						"ERROR", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						"STATIONS_REPOSITION_QUEUE", 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						`Repositioning station "${stationId}" queue failed. "${err}"` 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						"STATIONS_REPOSITION_SONG_IN_QUEUE", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						`Repositioning song ${song.songId} in queue of station "${stationId}" failed. "${err}"` 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					); 
														 | 
														
														 | 
														
															 					); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					return cb({ status: "failure", message: err }); 
														 | 
														
														 | 
														
															 					return cb({ status: "failure", message: err }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				} 
														 | 
														
														 | 
														
															 				} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				this.log( 
														 | 
														
														 | 
														
															 				this.log( 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					"SUCCESS", 
														 | 
														
														 | 
														
															 					"SUCCESS", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					"STATIONS_REPOSITION_QUEUE", 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					`Repositioned station "${stationId}" queue successfully.` 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					"STATIONS_REPOSITION_SONG_IN_QUEUE", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					`Repositioned song ${song.songId} in queue of station "${stationId}" successfully.` 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				); 
														 | 
														
														 | 
														
															 				); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				CacheModule.runJob("PUB", { 
														 | 
														
														 | 
														
															 				CacheModule.runJob("PUB", { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					channel: "station.queueUpdate", 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					value: stationId 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					channel: "station.repositionSongInQueue", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					value: { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						song: { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							songId: song.songId, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							oldIndex: song.oldIndex, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							newIndex: song.newIndex 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						}, 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						stationId 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				}); 
														 | 
														
														 | 
														
															 				}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				return cb({ 
														 | 
														
														 | 
														
															 				return cb({ 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					status: "success", 
														 | 
														
														 | 
														
															 					status: "success", 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					message: "Successfully repositioned queue." 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					message: "Successfully repositioned song in queue." 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				}); 
														 | 
														
														 | 
														
															 				}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			} 
														 | 
														
														 | 
														
															 			} 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		); 
														 | 
														
														 | 
														
															 		); 
														 |