Browse Source

fix(Station): skip votes would sometimes not load when skipping naturally

Kristian Vos 3 years ago
parent
commit
382199ea2f

+ 11 - 6
backend/logic/actions/stations.js

@@ -3957,10 +3957,11 @@ export default {
 	 *
 	 * @param session
 	 * @param stationId - the station id
+	 * @param stationId - the song id to get skipvotes for
 	 * @param cb
 	 */
 
-	getSkipVotes: isLoginRequired(async function getSkipVotes(session, stationId, cb) {
+	getSkipVotes: isLoginRequired(async function getSkipVotes(session, stationId, songId, cb) {
 		async.waterfall(
 			[
 				next => {
@@ -3970,12 +3971,16 @@ export default {
 				},
 
 				(currentSong, next) => {
-					if (currentSong)
+					if (currentSong && currentSong._id === songId)
 						next(null, {
 							skipVotes: currentSong.skipVotes.length,
-							songId: currentSong._id
+							skipVotesCurrent: true
+						});
+					else
+						next(null, {
+							skipVotes: 0,
+							skipVotesCurrent: false
 						});
-					else next("There is no song currently playing.");
 				}
 			],
 			async (err, data) => {
@@ -3989,13 +3994,13 @@ export default {
 					return cb({ status: "error", message: err });
 				}
 
-				const { skipVotes, songId } = data;
+				const { skipVotes, skipVotesCurrent } = data;
 
 				return cb({
 					status: "success",
 					data: {
 						skipVotes,
-						songId
+						skipVotesCurrent
 					}
 				});
 			}

+ 33 - 4
frontend/src/pages/Station/index.vue

@@ -678,6 +678,15 @@
 					><b>Party playlists selected</b>: {{ partyPlaylists }}</span
 				>
 				<span><b>Skip votes loaded</b>: {{ skipVotesLoaded }}</span>
+				<span
+					><b>Skip votes current</b>:
+					{{
+						currentSong.skipVotesCurrent === true ||
+						currentSong.skipVotesCurrent === false
+							? currentSong.skipVotesCurrent
+							: "N/A"
+					}}</span
+				>
 				<span
 					><b>Skip votes</b>:
 					{{ skipVotesLoaded ? currentSong.skipVotes : "N/A" }}</span
@@ -912,6 +921,13 @@ export default {
 					timePaused,
 					pausedAt: 0
 				});
+			} else if (this.currentSong._id === currentSong._id) {
+				if (this.currentSong.skipVotesLoaded !== true) {
+					this.updateCurrentSongSkipVotes({
+						skipVotes: currentSong.skipVotes,
+						skipVotesCurrent: true
+					});
+				}
 			} else {
 				this.setNextCurrentSong({
 					currentSong,
@@ -1053,7 +1069,10 @@ export default {
 
 		this.socket.on("event:station.voteSkipSong", () => {
 			if (this.currentSong)
-				this.updateCurrentSongSkipVotes(this.currentSong.skipVotes + 1);
+				this.updateCurrentSongSkipVotes({
+					skipVotes: this.currentSong.skipVotes + 1,
+					skipVotesCurrent: null
+				});
 		});
 
 		this.socket.on("event:privatePlaylist.selected", res => {
@@ -1299,14 +1318,24 @@ export default {
 					}, this.getTimeRemaining());
 				}
 
+				const currentSongId = this.currentSong._id;
+
 				this.socket.dispatch(
 					"stations.getSkipVotes",
 					this.station._id,
+					currentSongId,
 					res => {
 						if (res.status === "success") {
-							const { skipVotes, songId } = res.data;
-							if (!this.noSong && this.currentSong._id === songId)
-								this.updateCurrentSongSkipVotes(skipVotes);
+							const { skipVotes, skipVotesCurrent } = res.data;
+							if (
+								!this.noSong &&
+								this.currentSong._id === currentSongId
+							) {
+								this.updateCurrentSongSkipVotes({
+									skipVotes,
+									skipVotesCurrent
+								});
+							}
 						}
 					}
 				);

+ 8 - 3
frontend/src/store/modules/station.js

@@ -76,8 +76,11 @@ const actions = {
 	updateOwnCurrentSongRatings: ({ commit }, ownSongRatings) => {
 		commit("updateOwnCurrentSongRatings", ownSongRatings);
 	},
-	updateCurrentSongSkipVotes: ({ commit }, skipVotes) => {
-		commit("updateCurrentSongSkipVotes", skipVotes);
+	updateCurrentSongSkipVotes: (
+		{ commit },
+		{ skipVotes, skipVotesCurrent }
+	) => {
+		commit("updateCurrentSongSkipVotes", { skipVotes, skipVotesCurrent });
 	}
 };
 
@@ -167,8 +170,10 @@ const mutations = {
 		state.currentSong.liked = ownSongRatings.liked;
 		state.currentSong.disliked = ownSongRatings.disliked;
 	},
-	updateCurrentSongSkipVotes(state, skipVotes) {
+	updateCurrentSongSkipVotes(state, { skipVotes, skipVotesCurrent }) {
 		state.currentSong.skipVotes = skipVotes;
+		if (skipVotesCurrent !== null)
+			state.currentSong.skipVotesCurrent = skipVotesCurrent;
 	}
 };