Browse Source

Merge remote-tracking branch 'origin/polishing' into owen

Owen Diffey 3 years ago
parent
commit
e197dc7813

+ 47 - 0
backend/logic/actions/stations.js

@@ -3052,6 +3052,53 @@ export default {
 					return next(null, song);
 				},
 
+				// (song, station, next) => {
+				// 	song.requestedBy = session.userId;
+				// 	song.requestedAt = Date.now();
+				// 	let totalDuration = 0;
+				// 	station.queue.forEach(song => {
+				// 		totalDuration += song.duration;
+				// 	});
+				// 	if (totalDuration >= 3600 * 3) return next("The max length of the queue is 3 hours.");
+				// 	return next(null, song, station);
+				// },
+
+				// (song, station, next) => {
+				// 	if (station.queue.length === 0) return next(null, song, station);
+				// 	let totalDuration = 0;
+				// 	const userId = station.queue[station.queue.length - 1].requestedBy;
+				// 	station.queue.forEach(song => {
+				// 		if (userId === song.requestedBy) {
+				// 			totalDuration += song.duration;
+				// 		}
+				// 	});
+
+				// 	if (totalDuration >= 900) return next("The max length of songs per user is 15 minutes.");
+				// 	return next(null, song, station);
+				// },
+
+				// (song, station, next) => {
+				// 	if (station.queue.length === 0) return next(null, song);
+				// 	let totalSongs = 0;
+				// 	const userId = station.queue[station.queue.length - 1].requestedBy;
+				// 	station.queue.forEach(song => {
+				// 		if (userId === song.requestedBy) {
+				// 			totalSongs += 1;
+				// 		}
+				// 	});
+
+				// 	if (totalSongs <= 2) return next(null, song);
+				// 	if (totalSongs > 3)
+				// 		return next("The max amount of songs per user is 3, and only 2 in a row is allowed.");
+				// 	if (
+				// 		station.queue[station.queue.length - 2].requestedBy !== userId ||
+				// 		station.queue[station.queue.length - 3] !== userId
+				// 	)
+				// 		return next("The max amount of songs per user is 3, and only 2 in a row is allowed.");
+
+				// 	return next(null, song);
+				// },
+
 				(song, next) => {
 					stationModel.updateOne(
 						{ _id: stationId },

+ 5 - 0
backend/logic/db/index.js

@@ -249,6 +249,11 @@ class _DBModule extends CoreClass {
 						.path("songs")
 						.validate(songs => songs.length <= 10000, "Max 10000 songs per playlist.");
 
+					// this.schemas.playlist.path("songs").validate(songs => {
+					// 	if (songs.length === 0) return true;
+					// 	return songs[0].duration <= 10800;
+					// }, "Max 3 hours per song.");
+
 					this.schemas.playlist.index({ createdFor: 1, type: 1 }, { unique: true });
 
 					if (config.get("skipDbDocumentsVersionCheck")) resolve();

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

@@ -552,43 +552,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();
+							}
+						);
 					}
 				}
 			}

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

@@ -895,7 +895,8 @@ export default {
 			beforeEditSongModalLocalPaused: null,
 			socketConnected: null,
 			persistentToastCheckerInterval: null,
-			persistentToasts: []
+			persistentToasts: [],
+			partyPlaylistLock: false
 		};
 	},
 	computed: {
@@ -925,6 +926,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
@@ -1907,43 +1913,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();
+							}
+						);
 					}
 				}
 			}