Bläddra i källkod

Merge branch 'odiffey-owen-party-playlist-fix' into polishing

Kristian Vos 2 år sedan
förälder
incheckning
4f71f419c6

+ 24 - 31
frontend/src/components/modals/ManageStation/Tabs/Playlists.vue

@@ -919,43 +919,36 @@ export default {
 			);
 		},
 		addPartyPlaylistSongToQueue() {
-			let isInQueue = false;
 			if (
 				this.station.type === "community" &&
-				this.station.partyMode === true
+				this.station.partyMode === true &&
+				this.songsList.length < 50 &&
+				this.songsList.filter(
+					queueSong => queueSong.requestedBy === this.userId
+				).length < 3 &&
+				this.partyPlaylists
 			) {
-				this.songsList.forEach(queueSong => {
-					if (queueSong.requestedBy === this.userId) isInQueue = true;
-				});
-				if (!isInQueue && this.partyPlaylists) {
-					const selectedPlaylist =
-						this.partyPlaylists[
+				const selectedPlaylist =
+					this.partyPlaylists[
+						Math.floor(Math.random() * this.partyPlaylists.length)
+					];
+				if (selectedPlaylist._id && selectedPlaylist.songs.length > 0) {
+					const selectedSong =
+						selectedPlaylist.songs[
 							Math.floor(
-								Math.random() * this.partyPlaylists.length
+								Math.random() * selectedPlaylist.songs.length
 							)
 						];
-					if (
-						selectedPlaylist._id &&
-						selectedPlaylist.songs.length > 0
-					) {
-						const selectedSong =
-							selectedPlaylist.songs[
-								Math.floor(
-									Math.random() *
-										selectedPlaylist.songs.length
-								)
-							];
-						if (selectedSong.youtubeId) {
-							this.socket.dispatch(
-								"stations.addToQueue",
-								this.station._id,
-								selectedSong.youtubeId,
-								data => {
-									if (data.status !== "success")
-										new Toast("Error auto queueing song");
-								}
-							);
-						}
+					if (selectedSong.youtubeId) {
+						this.socket.dispatch(
+							"stations.addToQueue",
+							this.station._id,
+							selectedSong.youtubeId,
+							data => {
+								if (data.status !== "success")
+									this.addPartyPlaylistSongToQueue();
+							}
+						);
 					}
 				}
 			}

+ 24 - 31
frontend/src/pages/Station/Sidebar/Playlists.vue

@@ -274,43 +274,36 @@ export default {
 			);
 		},
 		addPartyPlaylistSongToQueue() {
-			let isInQueue = false;
 			if (
 				this.station.type === "community" &&
-				this.station.partyMode === true
+				this.station.partyMode === true &&
+				this.songsList.length < 50 &&
+				this.songsList.filter(
+					queueSong => queueSong.requestedBy === this.userId
+				).length < 3 &&
+				this.partyPlaylists
 			) {
-				this.songsList.forEach(queueSong => {
-					if (queueSong.requestedBy === this.userId) isInQueue = true;
-				});
-				if (!isInQueue && this.partyPlaylists) {
-					const selectedPlaylist =
-						this.partyPlaylists[
+				const selectedPlaylist =
+					this.partyPlaylists[
+						Math.floor(Math.random() * this.partyPlaylists.length)
+					];
+				if (selectedPlaylist._id && selectedPlaylist.songs.length > 0) {
+					const selectedSong =
+						selectedPlaylist.songs[
 							Math.floor(
-								Math.random() * this.partyPlaylists.length
+								Math.random() * selectedPlaylist.songs.length
 							)
 						];
-					if (
-						selectedPlaylist._id &&
-						selectedPlaylist.songs.length > 0
-					) {
-						const selectedSong =
-							selectedPlaylist.songs[
-								Math.floor(
-									Math.random() *
-										selectedPlaylist.songs.length
-								)
-							];
-						if (selectedSong.youtubeId) {
-							this.socket.dispatch(
-								"stations.addToQueue",
-								this.station._id,
-								selectedSong.youtubeId,
-								data => {
-									if (data.status !== "success")
-										new Toast("Error auto queueing song");
-								}
-							);
-						}
+					if (selectedSong.youtubeId) {
+						this.socket.dispatch(
+							"stations.addToQueue",
+							this.station._id,
+							selectedSong.youtubeId,
+							data => {
+								if (data.status !== "success")
+									this.addPartyPlaylistSongToQueue();
+							}
+						);
 					}
 				}
 			}

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

@@ -899,7 +899,8 @@ export default {
 			beforeEditSongModalLocalPaused: null,
 			socketConnected: null,
 			persistentToastCheckerInterval: null,
-			persistentToasts: []
+			persistentToasts: [],
+			partyPlaylistLock: false
 		};
 	},
 	computed: {
@@ -929,6 +930,11 @@ export default {
 		aModalIsOpen() {
 			return Object.keys(this.currentlyActive).length > 0;
 		},
+		currentUserQueueSongs() {
+			return this.songsList.filter(
+				queueSong => queueSong.requestedBy === this.userId
+			).length;
+		},
 		...mapState("modalVisibility", {
 			modals: state => state.modals,
 			currentlyActive: state => state.currentlyActive
@@ -1129,7 +1135,7 @@ export default {
 
 			this.updateNextSong(nextSong);
 
-			this.addPartyPlaylistSongToQueue();
+			if (res.data.queue.length < 50) this.addPartyPlaylistSongToQueue();
 		});
 
 		this.socket.on("event:station.queue.song.repositioned", res => {
@@ -1905,43 +1911,37 @@ export default {
 			);
 		},
 		addPartyPlaylistSongToQueue() {
-			let isInQueue = false;
 			if (
+				!this.partyPlaylistLock &&
 				this.station.type === "community" &&
-				this.station.partyMode === true
+				this.station.partyMode === true &&
+				this.songsList.length < 50 &&
+				this.currentUserQueueSongs < 3 &&
+				this.partyPlaylists.length > 0
 			) {
-				this.songsList.forEach(queueSong => {
-					if (queueSong.requestedBy === this.userId) isInQueue = true;
-				});
-				if (!isInQueue && this.partyPlaylists.length > 0) {
-					const selectedPlaylist =
-						this.partyPlaylists[
+				const selectedPlaylist =
+					this.partyPlaylists[
+						Math.floor(Math.random() * this.partyPlaylists.length)
+					];
+				if (selectedPlaylist._id && selectedPlaylist.songs.length > 0) {
+					const selectedSong =
+						selectedPlaylist.songs[
 							Math.floor(
-								Math.random() * this.partyPlaylists.length
+								Math.random() * selectedPlaylist.songs.length
 							)
 						];
-					if (
-						selectedPlaylist._id &&
-						selectedPlaylist.songs.length > 0
-					) {
-						const selectedSong =
-							selectedPlaylist.songs[
-								Math.floor(
-									Math.random() *
-										selectedPlaylist.songs.length
-								)
-							];
-						if (selectedSong.youtubeId) {
-							this.socket.dispatch(
-								"stations.addToQueue",
-								this.station._id,
-								selectedSong.youtubeId,
-								data => {
-									if (data.status !== "success")
-										new Toast("Error auto queueing song");
-								}
-							);
-						}
+					if (selectedSong.youtubeId) {
+						this.partyPlaylistLock = true;
+						this.socket.dispatch(
+							"stations.addToQueue",
+							this.station._id,
+							selectedSong.youtubeId,
+							data => {
+								this.partyPlaylistLock = false;
+								if (data.status !== "success")
+									this.addPartyPlaylistSongToQueue();
+							}
+						);
 					}
 				}
 			}