Browse Source

fix: fixed issue where admin queuesongs and songs list didn't update properly

Kristian Vos 5 years ago
parent
commit
14ff74c17e

+ 2 - 2
backend/logic/actions/queueSongs.js

@@ -14,7 +14,7 @@ const logger = moduleManager.modules["logger"];
 const cache = moduleManager.modules["cache"];
 
 cache.sub('queue.newSong', songId => {
-	db.models.queueSong.findOne({songId}, (err, song) => {
+	db.models.queueSong.findOne({_id: songId}, (err, song) => {
 		utils.emitToRoom('admin.queue', 'event:admin.queueSong.added', song);
 	});
 });
@@ -24,7 +24,7 @@ cache.sub('queue.removedSong', songId => {
 });
 
 cache.sub('queue.update', songId => {
-	db.models.queueSong.findOne({songId}, (err, song) => {
+	db.models.queueSong.findOne({_id: songId}, (err, song) => {
 		utils.emitToRoom('admin.queue', 'event:admin.queueSong.updated', song);
 	});
 });

+ 2 - 2
backend/logic/actions/songs.js

@@ -18,13 +18,13 @@ cache.sub('song.removed', songId => {
 });
 
 cache.sub('song.added', songId => {
-	db.models.song.findOne({songId}, (err, song) => {
+	db.models.song.findOne({_id: songId}, (err, song) => {
 		utils.emitToRoom('admin.songs', 'event:admin.song.added', song);
 	});
 });
 
 cache.sub('song.updated', songId => {
-	db.models.song.findOne({songId}, (err, song) => {
+	db.models.song.findOne({_id: songId}, (err, song) => {
 		utils.emitToRoom('admin.songs', 'event:admin.song.updated', song);
 	});
 });

+ 1 - 5
backend/logic/utils.js

@@ -303,17 +303,13 @@ module.exports = class extends coreClass {
 		}
 	}
 
-	async emitToRoom(room) {
+	async emitToRoom(room, ...args) {
 		try { await this._validateHook(); } catch { return; }
 		
 		let sockets = this.io.io.sockets.sockets;
 		for (let id in sockets) {
 			let socket = sockets[id];
 			if (socket.rooms[room]) {
-				let args = [];
-				for (let i = 1; i < Object.keys(arguments).length; i++) {
-					args.push(arguments[i]);
-				}
 				socket.emit.apply(socket, args);
 			}
 		}

+ 18 - 19
frontend/components/Admin/QueueSongs.vue

@@ -181,27 +181,26 @@ export default {
 		const _this = this;
 		io.getSocket(socket => {
 			_this.socket = socket;
-			if (_this.socket.connected) {
-				_this.init();
-				_this.socket.on("event:admin.queueSong.added", queueSong => {
-					_this.songs.push(queueSong);
-				});
-				_this.socket.on("event:admin.queueSong.removed", songId => {
-					_this.songs = _this.songs.filter(song => {
-						return song._id !== songId;
-					});
+
+			_this.socket.on("event:admin.queueSong.added", queueSong => {
+				_this.songs.push(queueSong);
+			});
+			_this.socket.on("event:admin.queueSong.removed", songId => {
+				_this.songs = _this.songs.filter(song => {
+					return song._id !== songId;
 				});
-				_this.socket.on(
-					"event:admin.queueSong.updated",
-					updatedSong => {
-						for (let i = 0; i < _this.songs.length; i += 1) {
-							const song = _this.songs[i];
-							if (song._id === updatedSong._id) {
-								_this.songs.$set(i, updatedSong);
-							}
-						}
+			});
+			_this.socket.on("event:admin.queueSong.updated", updatedSong => {
+				for (let i = 0; i < _this.songs.length; i += 1) {
+					const song = _this.songs[i];
+					if (song._id === updatedSong._id) {
+						_this.songs.$set(i, updatedSong);
 					}
-				);
+				}
+			});
+
+			if (_this.socket.connected) {
+				_this.init();
 			}
 			io.onConnect(() => {
 				_this.init();

+ 17 - 16
frontend/components/Admin/Songs.vue

@@ -162,24 +162,25 @@ export default {
 		const _this = this;
 		io.getSocket(socket => {
 			_this.socket = socket;
-			if (_this.socket.connected) {
-				_this.init();
-				_this.socket.on("event:admin.song.added", song => {
-					_this.songs.push(song);
-				});
-				_this.socket.on("event:admin.song.removed", songId => {
-					_this.songs = _this.songs.filter(song => {
-						return song._id !== songId;
-					});
+			_this.socket.on("event:admin.song.added", song => {
+				_this.songs.push(song);
+			});
+			_this.socket.on("event:admin.song.removed", songId => {
+				_this.songs = _this.songs.filter(song => {
+					return song._id !== songId;
 				});
-				_this.socket.on("event:admin.song.updated", updatedSong => {
-					for (let i = 0; i < _this.songs.length; i += 1) {
-						const song = _this.songs[i];
-						if (song._id === updatedSong._id) {
-							_this.songs.$set(i, updatedSong);
-						}
+			});
+			_this.socket.on("event:admin.song.updated", updatedSong => {
+				for (let i = 0; i < _this.songs.length; i += 1) {
+					const song = _this.songs[i];
+					if (song._id === updatedSong._id) {
+						_this.songs.$set(i, updatedSong);
 					}
-				});
+				}
+			});
+
+			if (_this.socket.connected) {
+				_this.init();
 			}
 			io.onConnect(() => {
 				_this.init();