| 
														
															@@ -19,7 +19,7 @@ cache.sub('song.added', songId => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 cache.sub('song.like', (data) => { 
														 | 
														
														 | 
														
															 cache.sub('song.like', (data) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	utils.emitToRoom(`song.${data.songId}`, 'event:song.like', {songId: data.songId, undisliked: data.undisliked}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	utils.emitToRoom(`song.${data.songId}`, 'event:song.like', {songId: data.songId, likes: data.likes, dislikes: data.dislikes}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
														
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
														
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: true, disliked: false}); 
														 | 
														
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: true, disliked: false}); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -28,7 +28,7 @@ cache.sub('song.like', (data) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 cache.sub('song.dislike', (data) => { 
														 | 
														
														 | 
														
															 cache.sub('song.dislike', (data) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	utils.emitToRoom(`song.${data.songId}`, 'event:song.dislike', {songId: data.songId, unliked: data.unliked}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	utils.emitToRoom(`song.${data.songId}`, 'event:song.dislike', {songId: data.songId, likes: data.likes, dislikes: data.dislikes}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
														
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
														
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: false, disliked: true}); 
														 | 
														
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: false, disliked: true}); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -37,7 +37,7 @@ cache.sub('song.dislike', (data) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 cache.sub('song.unlike', (data) => { 
														 | 
														
														 | 
														
															 cache.sub('song.unlike', (data) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	utils.emitToRoom(`song.${data.songId}`, 'event:song.unlike', {songId: data.songId}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	utils.emitToRoom(`song.${data.songId}`, 'event:song.unlike', {songId: data.songId, likes: data.likes, dislikes: data.dislikes}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
														
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
														
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: false, disliked: false}); 
														 | 
														
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: false, disliked: false}); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -46,7 +46,7 @@ cache.sub('song.unlike', (data) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 }); 
														 | 
														
														 | 
														
															 }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 cache.sub('song.undislike', (data) => { 
														 | 
														
														 | 
														
															 cache.sub('song.undislike', (data) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-	utils.emitToRoom(`song.${data.songId}`, 'event:song.undislike', {songId: data.songId}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+	utils.emitToRoom(`song.${data.songId}`, 'event:song.undislike', {songId: data.songId, likes: data.likes, dislikes: data.dislikes}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
														
														 | 
														
															 	utils.socketsFromUser(data.userId, (sockets) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
														
														 | 
														
															 		sockets.forEach((socket) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: false, disliked: false}); 
														 | 
														
														 | 
														
															 			socket.emit('event:song.newRatings', {songId: data.songId, liked: false, disliked: false}); 
														 | 
													
												
											
										
											
												
													
														 | 
														
															@@ -106,89 +106,89 @@ module.exports = { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}), 
														 | 
														
														 | 
														
															 	}), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	like: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
														
														 | 
														
															 	like: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		return cb({ status: 'failure', message: 'Ratings are currently disabled.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		db.models.user.findOne({ _id: userId }, (err, user) => { 
														 | 
														
														 | 
														
															 		db.models.user.findOne({ _id: userId }, (err, user) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			if (user.liked.indexOf(songId) !== -1) return cb({ status: 'failure', message: 'You have already liked this song.' }); 
														 | 
														
														 | 
														
															 			if (user.liked.indexOf(songId) !== -1) return cb({ status: 'failure', message: 'You have already liked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			let dislikes = 0; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			if (user.disliked.indexOf(songId) !== -1) dislikes = -1; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			db.models.song.update({ _id: songId }, { $inc: { likes: 1, dislikes: dislikes } }, err => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			db.models.user.update({_id: userId}, {$push: {liked: songId}, $pull: {disliked: songId}}, err => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				if (!err) { 
														 | 
														
														 | 
														
															 				if (!err) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					db.models.user.update({_id: userId}, {$push: {liked: songId}, $pull: {disliked: songId}}, err => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						if (!err) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							songs.updateSong(songId, (err, song) => {}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							cache.pub('song.like', JSON.stringify({ songId, userId: session.userId, undisliked: (dislikes === -1) })); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						} else db.models.song.update({ _id: songId }, { $inc: { likes: -1, dislikes: -dislikes } }, err => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							return cb({ status: 'failure', message: 'Something went wrong while liking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					db.models.user.count({"liked": songId}, (err, likes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						if (err) return cb({ status: 'failure', message: 'Something went wrong while liking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						db.models.user.count({"disliked": songId}, (err, dislikes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							if (err) return cb({ status: 'failure', message: 'Something went wrong while liking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							db.models.song.update({_id: songId}, {$set: {likes: likes, dislikes: dislikes}}, (err) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								if (err) return cb({ status: 'failure', message: 'Something went wrong while liking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								songs.updateSong(songId, (err, song) => {}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								cache.pub('song.like', JSON.stringify({ songId, userId: session.userId, likes: likes, dislikes: dislikes })); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								return cb({ status: 'success', message: 'You have successfully liked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						}); 
														 | 
														
														 | 
														
															 						}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					}); 
														 | 
														
														 | 
														
															 					}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} else { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					return cb({ status: 'failure', message: 'Something went wrong while liking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				} else return cb({ status: 'failure', message: 'Something went wrong while liking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			}); 
														 | 
														
														 | 
														
															 			}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		}); 
														 | 
														
														 | 
														
															 		}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}), 
														 | 
														
														 | 
														
															 	}), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	dislike: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
														
														 | 
														
															 	dislike: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		return cb({ status: 'failure', message: 'Ratings are currently disabled.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		db.models.user.findOne({_id: userId}, (err, user) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		db.models.user.findOne({ _id: userId }, (err, user) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			if (user.disliked.indexOf(songId) !== -1) return cb({ status: 'failure', message: 'You have already disliked this song.' }); 
														 | 
														
														 | 
														
															 			if (user.disliked.indexOf(songId) !== -1) return cb({ status: 'failure', message: 'You have already disliked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			let likes = 0; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			if (user.liked.indexOf(songId) !== -1) likes = -1; 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			db.models.song.update({_id: songId}, {$inc: {likes: likes, dislikes: 1}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			db.models.user.update({_id: userId}, {$push: {disliked: songId}, $pull: {liked: songId}}, err => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				if (!err) { 
														 | 
														
														 | 
														
															 				if (!err) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					db.models.user.update({_id: userId}, {$push: {disliked: songId}, $pull: {liked: songId}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						if (!err) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							songs.updateSong(songId, (err, song) => {}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							cache.pub('song.dislike', JSON.stringify({songId, userId: userId, unliked: (likes === -1)})); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						} else db.models.song.update({_id: songId}, {$inc: {likes: -likes, dislikes: -1}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							return cb({ status: 'failure', message: 'Something went wrong while disliking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					db.models.user.count({"liked": songId}, (err, likes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						if (err) return cb({ status: 'failure', message: 'Something went wrong while disliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						db.models.user.count({"disliked": songId}, (err, dislikes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							if (err) return cb({ status: 'failure', message: 'Something went wrong while disliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							db.models.song.update({_id: songId}, {$set: {likes: likes, dislikes: dislikes}}, (err) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								if (err) return cb({ status: 'failure', message: 'Something went wrong while disliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								songs.updateSong(songId, (err, song) => {}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								cache.pub('song.dislike', JSON.stringify({ songId, userId: session.userId, likes: likes, dislikes: dislikes })); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								return cb({ status: 'success', message: 'You have successfully disliked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						}); 
														 | 
														
														 | 
														
															 						}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					}); 
														 | 
														
														 | 
														
															 					}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} else { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					return cb({ status: 'failure', message: 'Something went wrong while disliking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				} else return cb({ status: 'failure', message: 'Something went wrong while disliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			}); 
														 | 
														
														 | 
														
															 			}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		}); 
														 | 
														
														 | 
														
															 		}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}), 
														 | 
														
														 | 
														
															 	}), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	undislike: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
														
														 | 
														
															 	undislike: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		return cb({ status: 'failure', message: 'Ratings are currently disabled.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		db.models.user.findOne({_id: userId}, (err, user) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		db.models.user.findOne({ _id: userId }, (err, user) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			if (user.disliked.indexOf(songId) === -1) return cb({ status: 'failure', message: 'You have not disliked this song.' }); 
														 | 
														
														 | 
														
															 			if (user.disliked.indexOf(songId) === -1) return cb({ status: 'failure', message: 'You have not disliked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			db.models.song.update({_id: songId}, {$inc: {dislikes: -1}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			db.models.user.update({_id: userId}, {$pull: {liked: songId, disliked: songId}}, err => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				if (!err) { 
														 | 
														
														 | 
														
															 				if (!err) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					db.models.user.update({_id: userId}, {$pull: {disliked: songId}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						if (!err) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							songs.updateSong(songId, (err, song) => {}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							cache.pub('song.undislike', JSON.stringify({songId, userId: userId})); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						} else db.models.song.update({_id: songId}, {$inc: {dislikes: 1}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							return cb({ status: 'failure', message: 'Something went wrong while undisliking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					db.models.user.count({"liked": songId}, (err, likes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						if (err) return cb({ status: 'failure', message: 'Something went wrong while undisliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						db.models.user.count({"disliked": songId}, (err, dislikes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							if (err) return cb({ status: 'failure', message: 'Something went wrong while undisliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							db.models.song.update({_id: songId}, {$set: {likes: likes, dislikes: dislikes}}, (err) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								if (err) return cb({ status: 'failure', message: 'Something went wrong while undisliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								songs.updateSong(songId, (err, song) => {}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								cache.pub('song.undislike', JSON.stringify({ songId, userId: session.userId, likes: likes, dislikes: dislikes })); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								return cb({ status: 'success', message: 'You have successfully undisliked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						}); 
														 | 
														
														 | 
														
															 						}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					}); 
														 | 
														
														 | 
														
															 					}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} else { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					return cb({ status: 'failure', message: 'Something went wrong while undisliking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				} else return cb({ status: 'failure', message: 'Something went wrong while undisliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			}); 
														 | 
														
														 | 
														
															 			}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		}); 
														 | 
														
														 | 
														
															 		}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}), 
														 | 
														
														 | 
														
															 	}), 
														 | 
													
												
											
												
													
														| 
														 | 
														
															  
														 | 
														
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	unlike: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
														
														 | 
														
															 	unlike: hooks.loginRequired((session, songId, cb, userId) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		return cb({ status: 'failure', message: 'Ratings are currently disabled.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-		db.models.user.findOne({_id: userId}, (err, user) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+		db.models.user.findOne({ _id: userId }, (err, user) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			if (user.liked.indexOf(songId) === -1) return cb({ status: 'failure', message: 'You have not liked this song.' }); 
														 | 
														
														 | 
														
															 			if (user.liked.indexOf(songId) === -1) return cb({ status: 'failure', message: 'You have not liked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-			db.models.song.update({_id: songId}, {$inc: {likes: -1}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+			db.models.user.update({_id: userId}, {$pull: {liked: songId, disliked: songId}}, err => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 				if (!err) { 
														 | 
														
														 | 
														
															 				if (!err) { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					db.models.user.update({_id: userId}, {$pull: {liked: songId}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						if (!err) { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							songs.updateSong(songId, (err, song) => {}); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							cache.pub('song.unlike', JSON.stringify({songId, userId: userId})); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-						} else db.models.song.update({_id: songId}, {$inc: {likes: 1}}, (err) => { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-							return cb({ status: 'failure', message: 'Something went wrong while unliking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+					db.models.user.count({"liked": songId}, (err, likes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						if (err) return cb({ status: 'failure', message: 'Something went wrong while unliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+						db.models.user.count({"disliked": songId}, (err, dislikes) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							if (err) return cb({ status: 'failure', message: 'Something went wrong while undiking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							db.models.song.update({_id: songId}, {$set: {likes: likes, dislikes: dislikes}}, (err) => { 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								if (err) return cb({ status: 'failure', message: 'Something went wrong while unliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								songs.updateSong(songId, (err, song) => {}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								cache.pub('song.unlike', JSON.stringify({ songId, userId: session.userId, likes: likes, dislikes: dislikes })); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+								return cb({ status: 'success', message: 'You have successfully unliked this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+							}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 						}); 
														 | 
														
														 | 
														
															 						}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 					}); 
														 | 
														
														 | 
														
															 					}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} else { 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-					return cb({ status: 'failure', message: 'Something went wrong while unliking this song.' }); 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															-				} 
														 | 
														
														 | 
														
															 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 
														 | 
														
														 | 
														
															+				} else return cb({ status: 'failure', message: 'Something went wrong while unliking this song.' }); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 			}); 
														 | 
														
														 | 
														
															 			}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 		}); 
														 | 
														
														 | 
														
															 		}); 
														 | 
													
												
											
												
													
														| 
														 | 
														
															 	}), 
														 | 
														
														 | 
														
															 	}), 
														 |