Browse Source

fix(EditSong): events on song being (un)verified/(un)hid

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 3 years ago
parent
commit
1dc34474c2

+ 1 - 0
backend/logic/actions/songs.js

@@ -59,6 +59,7 @@ CacheModule.runJob("SUB", {
 	channel: "song.newVerifiedSong",
 	cb: async songId => {
 		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
+
 		songModel.findOne({ _id: songId }, (err, song) =>
 			WSModule.runJob("EMIT_TO_ROOMS", {
 				rooms: ["admin.songs", `edit-song.${songId}`],

+ 1 - 9
backend/logic/ws.js

@@ -338,15 +338,7 @@ class _WSModule extends CoreClass {
 			async.each(
 				payload.rooms,
 				(room, next) => {
-					// if the room exists
-					if (WSModule.rooms[room] && WSModule.rooms[room].length > 0)
-						return WSModule.rooms[room].forEach(async socketId => {
-							// get every socketId (and thus every socket) in the room, and dispatch to each
-							const socket = await WSModule.runJob("SOCKET_FROM_SOCKET_ID", { socketId }, this);
-							socket.dispatch(...payload.args);
-							return next();
-						});
-
+					WSModule.runJob("EMIT_TO_ROOM", { room, args: payload.args });
 					return next();
 				},
 				() => resolve()

+ 3 - 6
frontend/src/components/modals/EditSong/index.vue

@@ -751,9 +751,8 @@ export default {
 		this.socket.on(
 			"event:admin.hiddenSong.created",
 			res => {
-				if (res.data.songId === this.song._id) {
+				if (res.data.song._id === this.song._id)
 					this.song.status = res.data.song.status;
-				}
 			},
 			{ modal: "editSong" }
 		);
@@ -761,9 +760,8 @@ export default {
 		this.socket.on(
 			"event:admin.unverifiedSong.created",
 			res => {
-				if (res.data.songId === this.song._id) {
+				if (res.data.song._id === this.song._id)
 					this.song.status = res.data.song.status;
-				}
 			},
 			{ modal: "editSong" }
 		);
@@ -771,9 +769,8 @@ export default {
 		this.socket.on(
 			"event:admin.verifiedSong.created",
 			res => {
-				if (res.data.songId === this.song._id) {
+				if (res.data.song._id === this.song._id)
 					this.song.status = res.data.song.status;
-				}
 			},
 			{ modal: "editSong" }
 		);

+ 3 - 4
frontend/src/pages/Admin/tabs/VerifiedSongs.vue

@@ -365,10 +365,9 @@ export default {
 		})
 	},
 	mounted() {
-		this.socket.on("event:admin.verifiedSong.created", res => {
-			this.addSong(res.data.song);
-			console.log("created");
-		});
+		this.socket.on("event:admin.verifiedSong.created", res =>
+			this.addSong(res.data.song)
+		);
 
 		this.socket.on("event:admin.verifiedSong.deleted", res =>
 			this.removeSong(res.data.songId)