瀏覽代碼

Improved party mode auto add playlist song to queue functionality (#400)

Owen Diffey 3 年之前
父節點
當前提交
9b6252518c

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

@@ -919,43 +919,35 @@ export default {
 			);
 		},
 		addPartyPlaylistSongToQueue() {
-			let isInQueue = false;
 			if (
 				this.station.type === "community" &&
-				this.station.partyMode === true
+				this.station.partyMode === true &&
+				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();
+							}
+						);
 					}
 				}
 			}

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

@@ -274,43 +274,35 @@ export default {
 			);
 		},
 		addPartyPlaylistSongToQueue() {
-			let isInQueue = false;
 			if (
 				this.station.type === "community" &&
-				this.station.partyMode === true
+				this.station.partyMode === true &&
+				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();
+							}
+						);
 					}
 				}
 			}

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

@@ -929,6 +929,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
@@ -959,6 +964,16 @@ export default {
 			socket: "websockets/getSocket"
 		})
 	},
+	watch: {
+		currentUserQueueSongs(total) {
+			if (
+				this.station.type === "community" &&
+				this.station.partyMode === true &&
+				total < 3
+			)
+				this.addPartyPlaylistSongToQueue();
+		}
+	},
 	async mounted() {
 		this.editSongModalWatcher = this.$store.watch(
 			state => state.modals.editSong.video.paused,
@@ -1128,8 +1143,6 @@ export default {
 					: null;
 
 			this.updateNextSong(nextSong);
-
-			this.addPartyPlaylistSongToQueue();
 		});
 
 		this.socket.on("event:station.queue.song.repositioned", res => {
@@ -1905,43 +1918,33 @@ export default {
 			);
 		},
 		addPartyPlaylistSongToQueue() {
-			let isInQueue = false;
 			if (
 				this.station.type === "community" &&
-				this.station.partyMode === true
+				this.station.partyMode === true &&
+				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.socket.dispatch(
+							"stations.addToQueue",
+							this.station._id,
+							selectedSong.youtubeId,
+							data => {
+								if (data.status !== "success")
+									this.addPartyPlaylistSongToQueue();
+							}
+						);
 					}
 				}
 			}