|
@@ -10,7 +10,6 @@ const UtilsModule = moduleManager.modules.utils;
|
|
|
const WSModule = moduleManager.modules.ws;
|
|
|
const CacheModule = moduleManager.modules.cache;
|
|
|
const SongsModule = moduleManager.modules.songs;
|
|
|
-const ActivitiesModule = moduleManager.modules.activities;
|
|
|
const PlaylistsModule = moduleManager.modules.playlists;
|
|
|
const StationsModule = moduleManager.modules.stations;
|
|
|
|
|
@@ -40,114 +39,6 @@ CacheModule.runJob("SUB", {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-CacheModule.runJob("SUB", {
|
|
|
- channel: "song.like",
|
|
|
- cb: data => {
|
|
|
- WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
- room: `song.${data.youtubeId}`,
|
|
|
- args: [
|
|
|
- "event:song.liked",
|
|
|
- {
|
|
|
- data: { youtubeId: data.youtubeId, likes: data.likes, dislikes: data.dislikes }
|
|
|
- }
|
|
|
- ]
|
|
|
- });
|
|
|
-
|
|
|
- WSModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(sockets => {
|
|
|
- sockets.forEach(socket => {
|
|
|
- socket.dispatch("event:song.ratings.updated", {
|
|
|
- data: {
|
|
|
- youtubeId: data.youtubeId,
|
|
|
- liked: true,
|
|
|
- disliked: false
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-CacheModule.runJob("SUB", {
|
|
|
- channel: "song.dislike",
|
|
|
- cb: data => {
|
|
|
- WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
- room: `song.${data.youtubeId}`,
|
|
|
- args: [
|
|
|
- "event:song.disliked",
|
|
|
- {
|
|
|
- data: { youtubeId: data.youtubeId, likes: data.likes, dislikes: data.dislikes }
|
|
|
- }
|
|
|
- ]
|
|
|
- });
|
|
|
-
|
|
|
- WSModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(sockets => {
|
|
|
- sockets.forEach(socket => {
|
|
|
- socket.dispatch("event:song.ratings.updated", {
|
|
|
- data: {
|
|
|
- youtubeId: data.youtubeId,
|
|
|
- liked: false,
|
|
|
- disliked: true
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-CacheModule.runJob("SUB", {
|
|
|
- channel: "song.unlike",
|
|
|
- cb: data => {
|
|
|
- WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
- room: `song.${data.youtubeId}`,
|
|
|
- args: [
|
|
|
- "event:song.unliked",
|
|
|
- {
|
|
|
- data: { youtubeId: data.youtubeId, likes: data.likes, dislikes: data.dislikes }
|
|
|
- }
|
|
|
- ]
|
|
|
- });
|
|
|
-
|
|
|
- WSModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(sockets => {
|
|
|
- sockets.forEach(socket => {
|
|
|
- socket.dispatch("event:song.ratings.updated", {
|
|
|
- data: {
|
|
|
- youtubeId: data.youtubeId,
|
|
|
- liked: false,
|
|
|
- disliked: false
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-CacheModule.runJob("SUB", {
|
|
|
- channel: "song.undislike",
|
|
|
- cb: data => {
|
|
|
- WSModule.runJob("EMIT_TO_ROOM", {
|
|
|
- room: `song.${data.youtubeId}`,
|
|
|
- args: [
|
|
|
- "event:song.undisliked",
|
|
|
- {
|
|
|
- data: { youtubeId: data.youtubeId, likes: data.likes, dislikes: data.dislikes }
|
|
|
- }
|
|
|
- ]
|
|
|
- });
|
|
|
-
|
|
|
- WSModule.runJob("SOCKETS_FROM_USER", { userId: data.userId }).then(sockets => {
|
|
|
- sockets.forEach(socket => {
|
|
|
- socket.dispatch("event:song.ratings.updated", {
|
|
|
- data: {
|
|
|
- youtubeId: data.youtubeId,
|
|
|
- liked: false,
|
|
|
- disliked: false
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
export default {
|
|
|
/**
|
|
|
* Returns the length of the songs list
|
|
@@ -342,41 +233,6 @@ export default {
|
|
|
);
|
|
|
}),
|
|
|
|
|
|
- /**
|
|
|
- * Recalculates all song ratings
|
|
|
- *
|
|
|
- * @param {object} session - the session object automatically added by the websocket
|
|
|
- * @param cb
|
|
|
- */
|
|
|
- recalculateAllRatings: isAdminRequired(async function recalculateAllRatings(session, cb) {
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => {
|
|
|
- SongsModule.runJob("RECALCULATE_ALL_SONG_RATINGS", {}, this)
|
|
|
- .then(() => {
|
|
|
- next();
|
|
|
- })
|
|
|
- .catch(err => {
|
|
|
- next(err);
|
|
|
- });
|
|
|
- }
|
|
|
- ],
|
|
|
- async err => {
|
|
|
- if (err) {
|
|
|
- err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
- this.log(
|
|
|
- "ERROR",
|
|
|
- "SONGS_RECALCULATE_ALL_RATINGS",
|
|
|
- `Failed to recalculate all song ratings. "${err}"`
|
|
|
- );
|
|
|
- return cb({ status: "error", message: err });
|
|
|
- }
|
|
|
- this.log("SUCCESS", "SONGS_RECALCULATE_ALL_RATINGS", `Recalculated all song ratings successfully.`);
|
|
|
- return cb({ status: "success", message: "Successfully recalculated all song ratings." });
|
|
|
- }
|
|
|
- );
|
|
|
- }),
|
|
|
-
|
|
|
/**
|
|
|
* Gets a song from the Musare song id
|
|
|
*
|
|
@@ -1106,602 +962,6 @@ export default {
|
|
|
);
|
|
|
}),
|
|
|
|
|
|
- /**
|
|
|
- * Likes a song
|
|
|
- *
|
|
|
- * @param session
|
|
|
- * @param youtubeId - the youtube id
|
|
|
- * @param cb
|
|
|
- */
|
|
|
- like: isLoginRequired(async function like(session, youtubeId, cb) {
|
|
|
- const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
|
|
|
- const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
-
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => songModel.findOne({ youtubeId }, next),
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("No song found with that id.");
|
|
|
- return next(null, song);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => userModel.findOne({ _id: session.userId }, (err, user) => next(err, song, user)),
|
|
|
-
|
|
|
- (song, user, next) => {
|
|
|
- if (!user) return next("User does not exist.");
|
|
|
-
|
|
|
- return this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "removeSongFromPlaylist",
|
|
|
- args: [youtubeId, user.dislikedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error" && res.message !== "Song wasn't in playlist.")
|
|
|
- return next("Unable to remove song from the 'Disliked Songs' playlist.");
|
|
|
- return next(null, song, user.likedSongsPlaylist);
|
|
|
- })
|
|
|
- .catch(err => next(err));
|
|
|
- },
|
|
|
-
|
|
|
- (song, likedSongsPlaylist, next) =>
|
|
|
- this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "addSongToPlaylist",
|
|
|
- args: [false, youtubeId, likedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error") {
|
|
|
- if (res.message === "That song is already in the playlist")
|
|
|
- return next("You have already liked this song.");
|
|
|
- return next("Unable to add song to the 'Liked Songs' playlist.");
|
|
|
- }
|
|
|
-
|
|
|
- return next(null, song);
|
|
|
- })
|
|
|
- .catch(err => next(err)),
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- SongsModule.runJob("RECALCULATE_SONG_RATINGS", { songId: song._id, youtubeId })
|
|
|
- .then(ratings => next(null, song, ratings))
|
|
|
- .catch(err => next(err));
|
|
|
- }
|
|
|
- ],
|
|
|
- async (err, song, ratings) => {
|
|
|
- if (err) {
|
|
|
- err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
- this.log(
|
|
|
- "ERROR",
|
|
|
- "SONGS_LIKE",
|
|
|
- `User "${session.userId}" failed to like song ${youtubeId}. "${err}"`
|
|
|
- );
|
|
|
- return cb({ status: "error", message: err });
|
|
|
- }
|
|
|
-
|
|
|
- const { likes, dislikes } = ratings;
|
|
|
-
|
|
|
- SongsModule.runJob("UPDATE_SONG", { songId: song._id });
|
|
|
-
|
|
|
- CacheModule.runJob("PUB", {
|
|
|
- channel: "song.like",
|
|
|
- value: JSON.stringify({
|
|
|
- youtubeId,
|
|
|
- userId: session.userId,
|
|
|
- likes,
|
|
|
- dislikes
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- ActivitiesModule.runJob("ADD_ACTIVITY", {
|
|
|
- userId: session.userId,
|
|
|
- type: "song__like",
|
|
|
- payload: {
|
|
|
- message: `Liked song <youtubeId>${song.title} by ${song.artists.join(", ")}</youtubeId>`,
|
|
|
- youtubeId,
|
|
|
- thumbnail: song.thumbnail
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return cb({
|
|
|
- status: "success",
|
|
|
- message: "You have successfully liked this song."
|
|
|
- });
|
|
|
- }
|
|
|
- );
|
|
|
- }),
|
|
|
-
|
|
|
- /**
|
|
|
- * Dislikes a song
|
|
|
- *
|
|
|
- * @param session
|
|
|
- * @param youtubeId - the youtube id
|
|
|
- * @param cb
|
|
|
- */
|
|
|
- dislike: isLoginRequired(async function dislike(session, youtubeId, cb) {
|
|
|
- const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
|
|
|
- const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
-
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => {
|
|
|
- songModel.findOne({ youtubeId }, next);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("No song found with that id.");
|
|
|
- return next(null, song);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => userModel.findOne({ _id: session.userId }, (err, user) => next(err, song, user)),
|
|
|
-
|
|
|
- (song, user, next) => {
|
|
|
- if (!user) return next("User does not exist.");
|
|
|
-
|
|
|
- return this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "removeSongFromPlaylist",
|
|
|
- args: [youtubeId, user.likedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error" && res.message !== "Song wasn't in playlist.")
|
|
|
- return next("Unable to remove song from the 'Liked Songs' playlist.");
|
|
|
- return next(null, song, user.dislikedSongsPlaylist);
|
|
|
- })
|
|
|
- .catch(err => next(err));
|
|
|
- },
|
|
|
-
|
|
|
- (song, dislikedSongsPlaylist, next) =>
|
|
|
- this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "addSongToPlaylist",
|
|
|
- args: [false, youtubeId, dislikedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error") {
|
|
|
- if (res.message === "That song is already in the playlist")
|
|
|
- return next("You have already disliked this song.");
|
|
|
- return next("Unable to add song to the 'Disliked Songs' playlist.");
|
|
|
- }
|
|
|
-
|
|
|
- return next(null, song);
|
|
|
- })
|
|
|
- .catch(err => next(err)),
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- SongsModule.runJob("RECALCULATE_SONG_RATINGS", { songId: song._id, youtubeId })
|
|
|
- .then(ratings => next(null, song, ratings))
|
|
|
- .catch(err => next(err));
|
|
|
- }
|
|
|
- ],
|
|
|
- async (err, song, ratings) => {
|
|
|
- if (err) {
|
|
|
- err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
- this.log(
|
|
|
- "ERROR",
|
|
|
- "SONGS_DISLIKE",
|
|
|
- `User "${session.userId}" failed to dislike song ${youtubeId}. "${err}"`
|
|
|
- );
|
|
|
- return cb({ status: "error", message: err });
|
|
|
- }
|
|
|
-
|
|
|
- const { likes, dislikes } = ratings;
|
|
|
-
|
|
|
- SongsModule.runJob("UPDATE_SONG", { songId: song._id });
|
|
|
-
|
|
|
- CacheModule.runJob("PUB", {
|
|
|
- channel: "song.dislike",
|
|
|
- value: JSON.stringify({
|
|
|
- youtubeId,
|
|
|
- userId: session.userId,
|
|
|
- likes,
|
|
|
- dislikes
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- ActivitiesModule.runJob("ADD_ACTIVITY", {
|
|
|
- userId: session.userId,
|
|
|
- type: "song__dislike",
|
|
|
- payload: {
|
|
|
- message: `Disliked song <youtubeId>${song.title} by ${song.artists.join(", ")}</youtubeId>`,
|
|
|
- youtubeId,
|
|
|
- thumbnail: song.thumbnail
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return cb({
|
|
|
- status: "success",
|
|
|
- message: "You have successfully disliked this song."
|
|
|
- });
|
|
|
- }
|
|
|
- );
|
|
|
- }),
|
|
|
-
|
|
|
- /**
|
|
|
- * Undislikes a song
|
|
|
- *
|
|
|
- * @param session
|
|
|
- * @param youtubeId - the youtube id
|
|
|
- * @param cb
|
|
|
- */
|
|
|
- undislike: isLoginRequired(async function undislike(session, youtubeId, cb) {
|
|
|
- const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
|
|
|
- const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
-
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => {
|
|
|
- songModel.findOne({ youtubeId }, next);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("No song found with that id.");
|
|
|
- return next(null, song);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => userModel.findOne({ _id: session.userId }, (err, user) => next(err, song, user)),
|
|
|
-
|
|
|
- (song, user, next) => {
|
|
|
- if (!user) return next("User does not exist.");
|
|
|
-
|
|
|
- return this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "removeSongFromPlaylist",
|
|
|
- args: [youtubeId, user.dislikedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error")
|
|
|
- return next("Unable to remove song from the 'Disliked Songs' playlist.");
|
|
|
- return next(null, song, user.likedSongsPlaylist);
|
|
|
- })
|
|
|
- .catch(err => next(err));
|
|
|
- },
|
|
|
-
|
|
|
- (song, likedSongsPlaylist, next) => {
|
|
|
- this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "removeSongFromPlaylist",
|
|
|
- args: [youtubeId, likedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error" && res.message !== "Song wasn't in playlist.")
|
|
|
- return next("Unable to remove song from the 'Liked Songs' playlist.");
|
|
|
- return next(null, song);
|
|
|
- })
|
|
|
- .catch(err => next(err));
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- SongsModule.runJob("RECALCULATE_SONG_RATINGS", { songId: song._id, youtubeId })
|
|
|
- .then(ratings => next(null, song, ratings))
|
|
|
- .catch(err => next(err));
|
|
|
- }
|
|
|
- ],
|
|
|
- async (err, song, ratings) => {
|
|
|
- if (err) {
|
|
|
- err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
- this.log(
|
|
|
- "ERROR",
|
|
|
- "SONGS_UNDISLIKE",
|
|
|
- `User "${session.userId}" failed to undislike song ${youtubeId}. "${err}"`
|
|
|
- );
|
|
|
- return cb({ status: "error", message: err });
|
|
|
- }
|
|
|
-
|
|
|
- const { likes, dislikes } = ratings;
|
|
|
-
|
|
|
- SongsModule.runJob("UPDATE_SONG", { songId: song._id });
|
|
|
-
|
|
|
- CacheModule.runJob("PUB", {
|
|
|
- channel: "song.undislike",
|
|
|
- value: JSON.stringify({
|
|
|
- youtubeId,
|
|
|
- userId: session.userId,
|
|
|
- likes,
|
|
|
- dislikes
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- ActivitiesModule.runJob("ADD_ACTIVITY", {
|
|
|
- userId: session.userId,
|
|
|
- type: "song__undislike",
|
|
|
- payload: {
|
|
|
- message: `Removed <youtubeId>${song.title} by ${song.artists.join(
|
|
|
- ", "
|
|
|
- )}</youtubeId> from your Disliked Songs`,
|
|
|
- youtubeId,
|
|
|
- thumbnail: song.thumbnail
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return cb({
|
|
|
- status: "success",
|
|
|
- message: "You have successfully undisliked this song."
|
|
|
- });
|
|
|
- }
|
|
|
- );
|
|
|
- }),
|
|
|
-
|
|
|
- /**
|
|
|
- * Unlikes a song
|
|
|
- *
|
|
|
- * @param session
|
|
|
- * @param youtubeId - the youtube id
|
|
|
- * @param cb
|
|
|
- */
|
|
|
- unlike: isLoginRequired(async function unlike(session, youtubeId, cb) {
|
|
|
- const userModel = await DBModule.runJob("GET_MODEL", { modelName: "user" }, this);
|
|
|
- const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
-
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => {
|
|
|
- songModel.findOne({ youtubeId }, next);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("No song found with that id.");
|
|
|
- return next(null, song);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => userModel.findOne({ _id: session.userId }, (err, user) => next(err, song, user)),
|
|
|
-
|
|
|
- (song, user, next) => {
|
|
|
- if (!user) return next("User does not exist.");
|
|
|
-
|
|
|
- return this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "removeSongFromPlaylist",
|
|
|
- args: [youtubeId, user.dislikedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error" && res.message !== "Song wasn't in playlist.")
|
|
|
- return next("Unable to remove song from the 'Disliked Songs' playlist.");
|
|
|
- return next(null, song, user.likedSongsPlaylist);
|
|
|
- })
|
|
|
- .catch(err => next(err));
|
|
|
- },
|
|
|
-
|
|
|
- (song, likedSongsPlaylist, next) => {
|
|
|
- this.module
|
|
|
- .runJob(
|
|
|
- "RUN_ACTION2",
|
|
|
- {
|
|
|
- session,
|
|
|
- namespace: "playlists",
|
|
|
- action: "removeSongFromPlaylist",
|
|
|
- args: [youtubeId, likedSongsPlaylist]
|
|
|
- },
|
|
|
- this
|
|
|
- )
|
|
|
- .then(res => {
|
|
|
- if (res.status === "error")
|
|
|
- return next("Unable to remove song from the 'Liked Songs' playlist.");
|
|
|
- return next(null, song);
|
|
|
- })
|
|
|
- .catch(err => next(err));
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- SongsModule.runJob("RECALCULATE_SONG_RATINGS", { songId: song._id, youtubeId })
|
|
|
- .then(ratings => next(null, song, ratings))
|
|
|
- .catch(err => next(err));
|
|
|
- }
|
|
|
- ],
|
|
|
- async (err, song, ratings) => {
|
|
|
- if (err) {
|
|
|
- err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
- this.log(
|
|
|
- "ERROR",
|
|
|
- "SONGS_UNLIKE",
|
|
|
- `User "${session.userId}" failed to unlike song ${youtubeId}. "${err}"`
|
|
|
- );
|
|
|
- return cb({ status: "error", message: err });
|
|
|
- }
|
|
|
-
|
|
|
- const { likes, dislikes } = ratings;
|
|
|
-
|
|
|
- SongsModule.runJob("UPDATE_SONG", { songId: song._id });
|
|
|
-
|
|
|
- CacheModule.runJob("PUB", {
|
|
|
- channel: "song.unlike",
|
|
|
- value: JSON.stringify({
|
|
|
- youtubeId,
|
|
|
- userId: session.userId,
|
|
|
- likes,
|
|
|
- dislikes
|
|
|
- })
|
|
|
- });
|
|
|
-
|
|
|
- ActivitiesModule.runJob("ADD_ACTIVITY", {
|
|
|
- userId: session.userId,
|
|
|
- type: "song__unlike",
|
|
|
- payload: {
|
|
|
- message: `Removed <youtubeId>${song.title} by ${song.artists.join(
|
|
|
- ", "
|
|
|
- )}</youtubeId> from your Liked Songs`,
|
|
|
- youtubeId,
|
|
|
- thumbnail: song.thumbnail
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return cb({
|
|
|
- status: "success",
|
|
|
- message: "You have successfully unliked this song."
|
|
|
- });
|
|
|
- }
|
|
|
- );
|
|
|
- }),
|
|
|
-
|
|
|
- /**
|
|
|
- * Gets song ratings
|
|
|
- *
|
|
|
- * @param session
|
|
|
- * @param songId - the Musare song id
|
|
|
- * @param cb
|
|
|
- */
|
|
|
-
|
|
|
- getSongRatings: isLoginRequired(async function getSongRatings(session, songId, cb) {
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => {
|
|
|
- SongsModule.runJob("GET_SONG", { songId }, this)
|
|
|
- .then(res => next(null, res.song))
|
|
|
- .catch(next);
|
|
|
- },
|
|
|
-
|
|
|
- (song, next) => {
|
|
|
- next(null, {
|
|
|
- likes: song.likes,
|
|
|
- dislikes: song.dislikes
|
|
|
- });
|
|
|
- }
|
|
|
- ],
|
|
|
- async (err, ratings) => {
|
|
|
- if (err) {
|
|
|
- err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
- this.log(
|
|
|
- "ERROR",
|
|
|
- "SONGS_GET_RATINGS",
|
|
|
- `User "${session.userId}" failed to get ratings for ${songId}. "${err}"`
|
|
|
- );
|
|
|
- return cb({ status: "error", message: err });
|
|
|
- }
|
|
|
-
|
|
|
- const { likes, dislikes } = ratings;
|
|
|
-
|
|
|
- return cb({
|
|
|
- status: "success",
|
|
|
- data: {
|
|
|
- likes,
|
|
|
- dislikes
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- );
|
|
|
- }),
|
|
|
-
|
|
|
- /**
|
|
|
- * Gets user's own song ratings
|
|
|
- *
|
|
|
- * @param session
|
|
|
- * @param youtubeId - the youtube id
|
|
|
- * @param cb
|
|
|
- */
|
|
|
- getOwnSongRatings: isLoginRequired(async function getOwnSongRatings(session, youtubeId, cb) {
|
|
|
- const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
|
|
|
- const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" }, this);
|
|
|
-
|
|
|
- async.waterfall(
|
|
|
- [
|
|
|
- next => songModel.findOne({ youtubeId }, next),
|
|
|
- (song, next) => {
|
|
|
- if (!song) return next("No song found with that id.");
|
|
|
- return next(null);
|
|
|
- },
|
|
|
-
|
|
|
- next =>
|
|
|
- playlistModel.findOne(
|
|
|
- { createdBy: session.userId, displayName: "Liked Songs" },
|
|
|
- (err, playlist) => {
|
|
|
- if (err) return next(err);
|
|
|
- if (!playlist) return next("'Liked Songs' playlist does not exist.");
|
|
|
-
|
|
|
- let isLiked = false;
|
|
|
-
|
|
|
- Object.values(playlist.songs).forEach(song => {
|
|
|
- // song is found in 'liked songs' playlist
|
|
|
- if (song.youtubeId === youtubeId) isLiked = true;
|
|
|
- });
|
|
|
-
|
|
|
- return next(null, isLiked);
|
|
|
- }
|
|
|
- ),
|
|
|
-
|
|
|
- (isLiked, next) =>
|
|
|
- playlistModel.findOne(
|
|
|
- { createdBy: session.userId, displayName: "Disliked Songs" },
|
|
|
- (err, playlist) => {
|
|
|
- if (err) return next(err);
|
|
|
- if (!playlist) return next("'Disliked Songs' playlist does not exist.");
|
|
|
-
|
|
|
- const ratings = { isLiked, isDisliked: false };
|
|
|
-
|
|
|
- Object.values(playlist.songs).forEach(song => {
|
|
|
- // song is found in 'disliked songs' playlist
|
|
|
- if (song.youtubeId === youtubeId) ratings.isDisliked = true;
|
|
|
- });
|
|
|
-
|
|
|
- return next(null, ratings);
|
|
|
- }
|
|
|
- )
|
|
|
- ],
|
|
|
- async (err, ratings) => {
|
|
|
- if (err) {
|
|
|
- err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
|
|
|
- this.log(
|
|
|
- "ERROR",
|
|
|
- "SONGS_GET_OWN_RATINGS",
|
|
|
- `User "${session.userId}" failed to get ratings for ${youtubeId}. "${err}"`
|
|
|
- );
|
|
|
- return cb({ status: "error", message: err });
|
|
|
- }
|
|
|
-
|
|
|
- const { isLiked, isDisliked } = ratings;
|
|
|
-
|
|
|
- return cb({
|
|
|
- status: "success",
|
|
|
- data: {
|
|
|
- youtubeId,
|
|
|
- liked: isLiked,
|
|
|
- disliked: isDisliked
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- );
|
|
|
- }),
|
|
|
-
|
|
|
/**
|
|
|
* Gets a list of all genres
|
|
|
*
|