Forráskód Böngészése

Fixed issue where requested username of queue songs didn't show up.

KrisVos130 7 éve
szülő
commit
654f5cbe63
2 módosított fájl, 41 hozzáadás és 16 törlés
  1. 37 12
      backend/logic/actions/stations.js
  2. 4 4
      backend/logic/utils.js

+ 37 - 12
backend/logic/actions/stations.js

@@ -147,13 +147,18 @@ cache.sub('station.resume', stationId => {
 
 cache.sub('station.queueUpdate', stationId => {
 	stations.getStation(stationId, (err, station) => {
-		station.queue = station.queue.map((song) => {
-			let username = utils.getUsernameFromUserId(song.requestedBy);
-			if (username === null) username = "Unknown";
-			song.requestedByUsername = username;
-			return song;
+		async.map(station.queue, (song, next) => {
+			utils.getUsernameFromUserId(song.requestedBy, username => {
+				if (username === null) username = "Unknown";
+				song = JSON.parse(JSON.stringify(song));
+				song.requestedByUsername = username;
+				next(null, song);
+			});
+		}, (err, queue) => {
+			station = JSON.parse(JSON.stringify(station));
+			station.queue = queue;
+			if (!err) utils.emitToRoom(`station.${stationId}`, "event:queue.update", station.queue);
 		});
-		if (!err) utils.emitToRoom(`station.${stationId}`, "event:queue.update", station.queue);
 	});
 });
 
@@ -274,6 +279,21 @@ module.exports = {
 			(station, next) => {
 				if (!station) return next('Station not found.');
 				next(null, station);
+			},
+
+			(station, next) => {
+				async.map(station.queue, (song, next) => {
+					utils.getUsernameFromUserId(song.requestedBy, username => {
+						if (username === null) username = "Unknown";
+						song = JSON.parse(JSON.stringify(song));
+						song.requestedByUsername = username;
+						next(null, song);
+					});
+				}, (err, queue) => {
+					station = JSON.parse(JSON.stringify(station));
+					station.queue = queue;
+					next(null, station);
+				});
 			}
 		], (err, station) => {
 			if (err) {
@@ -1072,13 +1092,18 @@ module.exports = {
 			},
 
 			(station, next) => {
-				station.queue = station.queue.map((song) => {
-					let username = utils.getUsernameFromUserId(song.requestedBy);
-					if (username === null) username = "Unknown";
-					song.requestedByUsername = username;
-					return song;
+				async.map(station.queue, (song, next) => {
+					utils.getUsernameFromUserId(song.requestedBy, username => {
+						if (username === null) username = "Unknown";
+						song = JSON.parse(JSON.stringify(song));
+						song.requestedByUsername = username;
+						next(null, song);
+					});
+				}, (err, queue) => {
+					station = JSON.parse(JSON.stringify(station));
+					station.queue = queue;
+					next(null, station);
 				});
-				next(null, station);
 			}
 		], (err, station) => {
 			if (err) {

+ 4 - 4
backend/logic/utils.js

@@ -479,18 +479,18 @@ module.exports = {
 			return cb(false);
 		});
 	},
-	getUsernameFromUserId: (userId) => {
+	getUsernameFromUserId: (userId, cb) => {
 		async.waterfall([
 			(next) => {
 				if (!userId) return next(false);
 				db.models.user.findOne({_id: userId}, next);
 			}
 		], (err, user) => {
-			if (err === false) return null;
+			if (err === false) return cb(null);
 			else if (err) {
-				return null;
+				return cb(null);
 			}
-			return user.username;
+			return cb(user.username);
 		});
 	}
 };