Browse Source

refactor: Filter out user-type featured playlists in official stations

Owen Diffey 11 months ago
parent
commit
346715657b
2 changed files with 17 additions and 6 deletions
  1. 9 2
      backend/logic/actions/playlists.js
  2. 8 4
      frontend/src/components/PlaylistTabBase.vue

+ 9 - 2
backend/logic/actions/playlists.js

@@ -766,13 +766,20 @@ export default {
 	/**
 	 * Fetch 3 featured playlists at random
 	 * @param {object} session - the session object automatically added by the websocket
+	 * @param {boolean} includeUser - whether to include user playlists
 	 * @param {Function} cb - gets called with the result
 	 */
-	indexFeaturedPlaylists: isLoginRequired(async function indexMyPlaylists(session, cb) {
+	indexFeaturedPlaylists: isLoginRequired(async function indexMyPlaylists(session, includeUser, cb) {
 		const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
 
+		const types = ["genre", "admin"];
+		if (includeUser) types.push("user", "user-liked", "user-disliked");
+
 		playlistModel
-			.aggregate([{ $match: { featured: true } }, { $sample: { size: 3 } }])
+			.aggregate([
+				{ $match: { featured: true, privacy: "public", type: { $in: types } } },
+				{ $sample: { size: 3 } }
+			])
 			.exec(async (err, playlists) => {
 				if (err && err !== true) {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);

+ 8 - 4
frontend/src/components/PlaylistTabBase.vue

@@ -365,10 +365,14 @@ onMounted(() => {
 			orderOfPlaylists.value = calculatePlaylistOrder(); // order in regards to the database
 		});
 
-		socket.dispatch("playlists.indexFeaturedPlaylists", res => {
-			if (res.status === "success")
-				featuredPlaylists.value = res.data.playlists;
-		});
+		socket.dispatch(
+			"playlists.indexFeaturedPlaylists",
+			station.value.type === "community",
+			res => {
+				if (res.status === "success")
+					featuredPlaylists.value = res.data.playlists;
+			}
+		);
 
 		if (props.type === "autofill")
 			socket.dispatch(