Procházet zdrojové kódy

Station playlist now updates when a genre playlist updates

Kristian Vos před 4 roky
rodič
revize
17e08a0464

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

@@ -1683,6 +1683,7 @@ export default {
 				},
 
 				next => {
+					PlaylistsModule.runJob("AUTOFILL_STATION_PLAYLIST", { stationId }).then().catch();
 					StationsModule.runJob("UPDATE_STATION", { stationId }, this)
 						.then(station => next(null, station))
 						.catch(next);
@@ -1857,6 +1858,7 @@ export default {
 				},
 
 				next => {
+					PlaylistsModule.runJob("AUTOFILL_STATION_PLAYLIST", { stationId }).then().catch();
 					StationsModule.runJob("UPDATE_STATION", { stationId }, this)
 						.then(station => next(null, station))
 						.catch(next);
@@ -2530,6 +2532,11 @@ export default {
 									},
 									next
 								);
+							},
+
+							next => {
+								PlaylistsModule.runJob("AUTOFILL_STATION_PLAYLIST", { stationId }).then().catch();
+								next();
 							}
 						],
 						async err => {

+ 14 - 1
backend/logic/playlists.js

@@ -361,11 +361,24 @@ class _PlaylistsModule extends CoreClass {
 
 						Promise.allSettled(promises)
 							.then(() => {
-								next();
+								next(null, data.playlist._id);
 							})
 							.catch(err => {
 								next(err);
 							});
+					},
+
+					(playlistId, next) => {
+						StationsModule.runJob("GET_STATIONS_THAT_INCLUDE_OR_EXCLUDE_PLAYLIST", { playlistId })
+							.then(response => {
+								response.stationIds.forEach(stationId => {
+									PlaylistsModule.runJob("AUTOFILL_STATION_PLAYLIST", { stationId })
+										.then()
+										.catch();
+								});
+							})
+							.catch();
+						next();
 					}
 				],
 				err => {

+ 27 - 0
backend/logic/stations.js

@@ -1549,6 +1549,33 @@ class _StationsModule extends CoreClass {
 			);
 		});
 	}
+
+	/**
+	 * Gets stations that include or exclude a specific playlist
+	 *
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.playlistId - the playlist id
+	 * @returns {Promise} - returns promise (reject, resolve)
+	 */
+	GET_STATIONS_THAT_INCLUDE_OR_EXCLUDE_PLAYLIST(payload) {
+		return new Promise((resolve, reject) => {
+			DBModule.runJob(
+				"GET_MODEL",
+				{
+					modelName: "station"
+				},
+				this
+			).then(stationModel => {
+				stationModel.find(
+					{ $or: [{ includedPlaylists: payload.playlistId }, { excludedPlaylists: payload.playlistId }] },
+					(err, stations) => {
+						if (err) reject(err);
+						else resolve({ stationIds: stations.map(station => station._id) });
+					}
+				);
+			});
+		});
+	}
 }
 
 export default new _StationsModule();