Browse Source

Added the code to display who requested a song.

KrisVos130 8 years ago
parent
commit
52be9f3005

+ 1 - 1
backend/logic/actions/stations.js

@@ -885,7 +885,7 @@ module.exports = {
 				if (!station) return next('Station not found.');
 				if (station.locked) {
 					db.models.user.findOne({ _id: userId }, (err, user) => {
-						if (user.role !== 'admin' || station.owner !== userId) return next('Only owners and admins can add songs to a locked queue.');
+						if (user.role !== 'admin' && station.owner !== userId) return next('Only owners and admins can add songs to a locked queue.');
 						else return next(null, station);
 					});
 				} else {

+ 28 - 0
backend/logic/actions/users.js

@@ -398,6 +398,34 @@ module.exports = {
 		});
 	},
 
+
+	/**
+	 * Gets a username from an userId
+	 *
+	 * @param {Object} session - the session object automatically added by socket.io
+	 * @param {String} userId - the userId of the person we are trying to get the username from
+	 * @param {Function} cb - gets called with the result
+	 */
+	getUsernameFromId: (session, userId, cb) => {
+		async.waterfall([
+			(next) => {
+				db.models.user.findOne({ _id: userId }, next);
+			},
+		], (err, user) => {
+			if (err && err !== true) {
+				err = utils.getError(err);
+				logger.error("GET_USERNAME_FROM_ID", `Getting the username from userId "${userId}" failed. "${err}"`);
+				cb({status: 'failure', message: err});
+			} else {
+				logger.success("GET_USERNAME_FROM_ID", `Found username for userId "${userId}".`);
+				return cb({
+					status: 'success',
+					data: user.username
+				});
+			}
+		});
+	},
+
 	//TODO Fix security issues
 	/**
 	 * Gets user info from session

+ 16 - 1
frontend/App.vue

@@ -41,7 +41,9 @@
 				isRegisterActive: false,
 				isLoginActive: false,
 				serverDomain: '',
-				socketConnected: true
+				socketConnected: true,
+				userIdMap: {},
+				currentlyGettingUsernameFrom: {}
 			}
 		},
 		methods: {
@@ -56,6 +58,19 @@
 			},
 			'submitOnEnter': (cb, event) => {
 				if (event.which == 13) cb();
+			},
+			getUsernameFromId: function(userId) {
+			    if (typeof this.userIdMap[userId] !== 'string' && !this.currentlyGettingUsernameFrom[userId]) {
+					this.currentlyGettingUsernameFrom[userId] = true;
+			        io.getSocket(socket => {
+			            socket.emit('users.getUsernameFromId', userId, (data) => {
+			                if (data.status === 'success') {
+								this.$set(`userIdMap.${userId}`, data.data);
+							}
+							this.currentlyGettingUsernameFrom[userId] = false;
+						});
+					});
+				}
 			}
 		},
 		ready: function () {

+ 6 - 1
frontend/components/Sidebars/SongsList.vue

@@ -32,6 +32,10 @@
 							<strong>{{ song.title }}</strong>
 							<br>
 							<small>{{ song.artists.join(', ') }}</small>
+							<div v-if="this.$parent.$parent.type === 'community'">
+								<br>
+								<small>Requested by <b>{{this.$parent.$parent.$parent.getUsernameFromId(song.requestedBy)}} {{this.userIdMap[song.requestedBy]}}</b></small>
+							</div>
 						</p>
 					</div>
 				</div>
@@ -54,7 +58,8 @@
 	export default {
 		data: function () {
 			return {
-				dismissedWarning: false
+				dismissedWarning: false,
+				userIdMap: this.$parent.$parent.userIdMap
 			}
 		},
 		methods: {