Browse Source

fix(ManageStation): Currently playing doesnt update in manage station queue on admin page

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

+ 86 - 97
backend/logic/stations.js

@@ -933,113 +933,102 @@ class _StationsModule extends CoreClass {
 				],
 				async (err, station) => {
 					if (err) {
-						err = await UtilsModule.runJob(
-							"GET_ERROR",
-							{
-								error: err
-							},
-							this
-						);
+						err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 						StationsModule.log("ERROR", `Skipping station "${payload.stationId}" failed. "${err}"`);
-						reject(new Error(err));
-					} else {
-						if (station.currentSong !== null && station.currentSong.youtubeId !== undefined) {
-							station.currentSong.skipVotes = 0;
-						}
-						// TODO Pub/Sub this
+						return reject(new Error(err));
+					}
 
-						WSModule.runJob("EMIT_TO_ROOM", {
-							room: `station.${station._id}`,
-							args: [
-								"event:station.nextSong",
-								{
-									data: {
-										currentSong: station.currentSong,
-										startedAt: station.startedAt,
-										paused: station.paused,
-										timePaused: 0,
-										natural: payload.natural
-									}
+					if (station.currentSong !== null && station.currentSong.youtubeId !== undefined)
+						station.currentSong.skipVotes = 0;
+
+					// TODO Pub/Sub this
+
+					const { currentSong } = station;
+
+					WSModule.runJob("EMIT_TO_ROOM", {
+						room: `station.${station._id}`,
+						args: [
+							"event:station.nextSong",
+							{
+								data: {
+									currentSong,
+									startedAt: station.startedAt,
+									paused: station.paused,
+									timePaused: 0,
+									natural: payload.natural
 								}
-							]
-						});
+							}
+						]
+					});
 
-						if (station.privacy === "public")
-							WSModule.runJob("EMIT_TO_ROOM", {
-								room: "home",
-								args: [
-									"event:station.nextSong",
-									{ data: { stationId: station._id, song: station.currentSong } }
-								]
-							});
-						else {
-							const sockets = await WSModule.runJob("GET_SOCKETS_FOR_ROOM", { room: "home" }, this);
-
-							sockets.forEach(async socketId => {
-								const socket = await WSModule.runJob("SOCKET_FROM_SOCKET_ID", { socketId });
-								const { session } = socket;
-
-								if (session.sessionId) {
-									CacheModule.runJob("HGET", { table: "sessions", key: session.sessionId }).then(
-										session => {
-											if (session) {
-												DBModule.runJob("GET_MODEL", { modelName: "user" }).then(userModel => {
-													userModel.findOne(
-														{
-															_id: session.userId
-														},
-														(err, user) => {
-															if (!err && user) {
-																if (user.role === "admin")
-																	socket.dispatch("event:station.nextSong", {
-																		data: {
-																			stationId: station._id,
-																			song: station.currentSong
-																		}
-																	});
-																else if (
-																	station.type === "community" &&
-																	station.owner === session.userId
-																)
-																	socket.dispatch("event:station.nextSong", {
-																		data: {
-																			stationId: station._id,
-																			song: station.currentSong
-																		}
-																	});
-															}
-														}
-													);
+					WSModule.runJob("EMIT_TO_ROOM", {
+						room: `manage-station.${station._id}`,
+						args: ["event:station.nextSong", { data: { stationId: station._id, currentSong } }]
+					});
+
+					if (station.privacy === "public")
+						WSModule.runJob("EMIT_TO_ROOM", {
+							room: "home",
+							args: ["event:station.nextSong", { data: { stationId: station._id, currentSong } }]
+						});
+					else {
+						const sockets = await WSModule.runJob("GET_SOCKETS_FOR_ROOM", { room: "home" }, this);
+
+						sockets.forEach(async socketId => {
+							const socket = await WSModule.runJob("SOCKET_FROM_SOCKET_ID", { socketId });
+							const { session } = socket;
+
+							if (session.sessionId) {
+								CacheModule.runJob("HGET", { table: "sessions", key: session.sessionId }).then(
+									session => {
+										if (session) {
+											DBModule.runJob("GET_MODEL", { modelName: "user" }).then(userModel => {
+												userModel.findOne({ _id: session.userId }, (err, user) => {
+													if (!err && user) {
+														if (user.role === "admin")
+															socket.dispatch("event:station.nextSong", {
+																data: {
+																	stationId: station._id,
+																	currentSong
+																}
+															});
+														else if (
+															station.type === "community" &&
+															station.owner === session.userId
+														)
+															socket.dispatch("event:station.nextSong", {
+																data: {
+																	stationId: station._id,
+																	currentSong
+																}
+															});
+													}
 												});
-											}
+											});
 										}
-									);
-								}
-							});
-						}
+									}
+								);
+							}
+						});
+					}
 
-						WSModule.runJob("GET_SOCKETS_FOR_ROOM", { room: `station.${station._id}` }).then(sockets => {
-							if (station.currentSong !== null && station.currentSong.youtubeId !== undefined) {
-								WSModule.runJob("SOCKETS_JOIN_SONG_ROOM", {
-									sockets,
-									room: `song.${station.currentSong.youtubeId}`
-								});
-								if (!station.paused) {
-									NotificationsModule.runJob("SCHEDULE", {
-										name: `stations.nextSong?id=${station._id}`,
-										time: station.currentSong.duration * 1000,
-										station
-									});
-								}
-							} else {
-								WSModule.runJob("SOCKETS_LEAVE_SONG_ROOMS", {
-									sockets
+					WSModule.runJob("GET_SOCKETS_FOR_ROOM", { room: `station.${station._id}` }).then(sockets => {
+						if (station.currentSong !== null && station.currentSong.youtubeId !== undefined) {
+							WSModule.runJob("SOCKETS_JOIN_SONG_ROOM", {
+								sockets,
+								room: `song.${station.currentSong.youtubeId}`
+							});
+							if (!station.paused) {
+								NotificationsModule.runJob("SCHEDULE", {
+									name: `stations.nextSong?id=${station._id}`,
+									time: station.currentSong.duration * 1000,
+									station
 								});
 							}
-						});
+						} else WSModule.runJob("SOCKETS_LEAVE_SONG_ROOMS", { sockets });
+					});
 
-						resolve({ station });
-					}
+					return resolve({ station });
 				}
 			);
 		});

+ 0 - 1
frontend/src/components/modals/ManageStation/index.vue

@@ -440,7 +440,6 @@ export default {
 			"event:station.nextSong",
 			res => {
 				const { currentSong } = res.data;
-
 				this.updateCurrentSong(currentSong || {});
 			},
 			{ modal: "manageStation" }

+ 1 - 1
frontend/src/pages/Home.vue

@@ -620,7 +620,7 @@ export default {
 			);
 
 			if (station) {
-				let newSong = res.data.song;
+				let newSong = res.data.currentSong;
 
 				if (!newSong)
 					newSong = {

+ 0 - 0
frontend/src/pages/Profile/tabs/Playlists.vue → frontend/src/pages/Profile/Tabs/Playlists.vue


+ 1 - 1
frontend/src/pages/Profile/tabs/RecentActivity.vue → frontend/src/pages/Profile/Tabs/RecentActivity.vue

@@ -108,7 +108,7 @@ export default {
 			this.offsettedFromNextSet += 1;
 		});
 
-		this.socket.on("event:activity.hide", res => {
+		this.socket.on("event:activity.hidden", res => {
 			this.activities = this.activities.filter(
 				activity => activity._id !== res.data.activityId
 			);

+ 2 - 2
frontend/src/pages/Profile/index.vue

@@ -114,8 +114,8 @@ import MainFooter from "@/components/layout/MainFooter.vue";
 
 import TabQueryHandler from "@/mixins/TabQueryHandler.vue";
 
-import RecentActivity from "./tabs/RecentActivity.vue";
-import Playlists from "./tabs/Playlists.vue";
+import RecentActivity from "./Tabs/RecentActivity.vue";
+import Playlists from "./Tabs/Playlists.vue";
 
 export default {
 	components: {

+ 0 - 0
frontend/src/pages/Settings/tabs/Account.vue → frontend/src/pages/Settings/Tabs/Account.vue


+ 0 - 0
frontend/src/pages/Settings/tabs/Preferences.vue → frontend/src/pages/Settings/Tabs/Preferences.vue


+ 0 - 0
frontend/src/pages/Settings/tabs/Profile.vue → frontend/src/pages/Settings/Tabs/Profile.vue


+ 0 - 0
frontend/src/pages/Settings/tabs/Security.vue → frontend/src/pages/Settings/Tabs/Security.vue


+ 8 - 8
frontend/src/pages/Settings/index.vue

@@ -59,10 +59,10 @@ export default {
 	components: {
 		MainHeader,
 		MainFooter,
-		SecuritySettings: () => import("./tabs/Security.vue"),
-		AccountSettings: () => import("./tabs/Account.vue"),
-		ProfileSettings: () => import("./tabs/Profile.vue"),
-		PreferencesSettings: () => import("./tabs/Preferences.vue"),
+		SecuritySettings: () => import("./Tabs/Security.vue"),
+		AccountSettings: () => import("./Tabs/Account.vue"),
+		ProfileSettings: () => import("./Tabs/Profile.vue"),
+		PreferencesSettings: () => import("./Tabs/Preferences.vue"),
 		RemoveAccount: () => import("@/components/modals/RemoveAccount.vue")
 	},
 	mixins: [TabQueryHandler],
@@ -96,28 +96,28 @@ export default {
 			else new Toast("You're not currently signed in.");
 		});
 
-		this.socket.on("event:user.linkPassword", () =>
+		this.socket.on("event:user.password.linked", () =>
 			this.updateOriginalUser({
 				property: "password",
 				value: true
 			})
 		);
 
-		this.socket.on("event:user.unlinkPassword", () =>
+		this.socket.on("event:user.password.unlinked", () =>
 			this.updateOriginalUser({
 				property: "password",
 				value: false
 			})
 		);
 
-		this.socket.on("event:user.linkGithub", () =>
+		this.socket.on("event:user.github.linked", () =>
 			this.updateOriginalUser({
 				property: "github",
 				value: true
 			})
 		);
 
-		this.socket.on("event:user.unlinkGithub", () =>
+		this.socket.on("event:user.github.unlinked", () =>
 			this.updateOriginalUser({
 				property: "github",
 				value: false

+ 2 - 2
frontend/src/pages/Station/index.vue

@@ -772,9 +772,9 @@ export default {
 				startedAt,
 				paused,
 				timePaused,
-				naturel
+				natural
 			} = res.data;
-			if (this.noSong || !naturel) {
+			if (this.noSong || !natural) {
 				this.setCurrentSong({
 					currentSong,
 					startedAt,