浏览代码

Fixed issues with party mode: song already in queue with playlist, sometimes 2 songs get added automatically, sometimes 2 same songs gets added, sometimes nothing works, everyone can see the remove button.

KrisVos130 9 年之前
父节点
当前提交
27507b5f4a
共有 3 个文件被更改,包括 103 次插入23 次删除
  1. 92 21
      app/client/scripts/onCreated.js
  2. 3 1
      app/client/templates/communityStation.html
  3. 8 1
      app/server/server.js

+ 92 - 21
app/client/scripts/onCreated.js

@@ -532,14 +532,97 @@ Template.communityStation.onCreated(function () {
                 if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
                     Session.set("previousSong", currentSong);
                     if (currentSong !== undefined) {
-                        var playlistQueueName = Session.get("playlistQueueName");
-                        var playlistQueueCurrentSong = Session.get("playlistQueueCurrentSong");
-                        if (playlistQueueCurrentSong !== undefined) {
-                            if (playlistQueueCurrentSong.id === currentSong.id) {
-                                if (playlistQueueName !== undefined) {
-                                    // If someone selects a different playlist this won't work. This is fine.
-                                    Meteor.call("moveVideoToBottomOfPrivatePlaylist", playlistQueueName, playlistQueueCurrentSong.id, function() {
-                                        var pl = PrivatePlaylists.findOne({owner: Meteor.userId(), name: playlistQueueName});
+                        var coStation = CommunityStations.findOne({name: name});
+                        if (coStation.partyModeEnabled) {
+                            var hasSongInQueue = false;
+                            coStation.queue.forEach(function (queueSong) {
+                                if (Meteor.userId() === queueSong.requestedBy) {
+                                    hasSongInQueue = true;
+                                }
+                            });
+                            if (!hasSongInQueue) {
+                                var playlistQueueName = Session.get("playlistQueueName");
+                                var playlistQueueCurrentSong = Session.get("playlistQueueCurrentSong");
+                                if (playlistQueueCurrentSong !== undefined) {
+                                    if (playlistQueueCurrentSong.id === currentSong.id) {
+                                        if (playlistQueueName !== undefined) {
+                                            // If someone selects a different playlist this won't work. This is fine.
+                                            Meteor.call("moveVideoToBottomOfPrivatePlaylist", playlistQueueName, playlistQueueCurrentSong.id, function () {
+                                                var pl = PrivatePlaylists.findOne({
+                                                    owner: Meteor.userId(),
+                                                    name: playlistQueueName
+                                                });
+                                                if (pl !== undefined) {
+                                                    var plSongs = pl.songs;
+                                                    var plSong;
+
+                                                    if (plSongs.length === 1) {
+                                                        plSong = plSongs[0];
+                                                    } else if (plSongs.length > 1) {
+                                                        if (plSongs[0].id === playlistQueueCurrentSong.id) {
+                                                            plSong = plSongs[1];
+                                                        } else {
+                                                            plSong = plSongs[0];
+                                                        }
+                                                    }
+
+                                                    // Add song to queue
+                                                    if (plSong !== undefined) {
+                                                        var isAlreadyInQueue = false;
+                                                        coStation.queue.forEach(function (queueSong) {
+                                                            if (plSong.id === queueSong.song.id) {
+                                                                isAlreadyInQueue = true;
+                                                            }
+                                                        });
+                                                        if (isAlreadyInQueue) {
+                                                            // If the song we want to add is already in the queue, we moved the song to the bottom a new song will get added next song.
+                                                            Meteor.call("moveVideoToBottomOfPrivatePlaylist", playlistQueueName, plSong.id, function () {});
+                                                            Session.set("playlistQueueCurrentSong", undefined);
+                                                            var $toastContent = $('<span>The top song in your selected playlist is already in the playlist. We will attempt to add a different song when the current song ends.</span>');
+                                                            Materialize.toast($toastContent, 8000);
+                                                        } else {
+                                                            Meteor.call("addSongToCommunityStationQueue", Session.get("CommunityStationName"), plSong.id, function (err) {
+                                                                if (!err) {
+                                                                    Session.set("playlistQueueCurrentSong", plSong);
+                                                                }
+                                                            });
+                                                        }
+                                                    }
+                                                }
+                                            });
+                                        }
+                                    } else {
+                                        var contains = false;
+                                        coStation.queue.forEach(function (queueSong) {
+                                            if (playlistQueueCurrentSong.id === queueSong.song.id) {
+                                                contains = true;
+                                            }
+                                        });
+                                        if (!contains) {
+                                            var pl = PrivatePlaylists.findOne({
+                                                owner: Meteor.userId(),
+                                                name: playlistQueueName
+                                            });
+                                            if (pl !== undefined) {
+                                                var plSongs = pl.songs;
+                                                var plSong = plSongs[0];
+                                                // Add song to queue
+                                                if (plSong !== undefined) {
+                                                    Meteor.call("addSongToCommunityStationQueue", Session.get("CommunityStationName"), plSong.id, function (err) {
+                                                        if (!err) {
+                                                            Session.set("playlistQueueCurrentSong", plSong);
+                                                        }
+                                                    });
+                                                }
+                                            }
+                                        }
+                                    }
+                                } else {
+                                    var pl = PrivatePlaylists.findOne({
+                                        owner: Meteor.userId(),
+                                        name: playlistQueueName
+                                    });
+                                    if (pl !== undefined) {
                                         var plSongs = pl.songs;
                                         var plSong = plSongs[0];
                                         // Add song to queue
@@ -550,20 +633,8 @@ Template.communityStation.onCreated(function () {
                                                 }
                                             });
                                         }
-                                    });
-                                }
-                            }
-                        } else {
-                            var pl = PrivatePlaylists.findOne({owner: Meteor.userId(), name: playlistQueueName});
-                            var plSongs = pl.songs;
-                            var plSong = plSongs[0];
-                            // Add song to queue
-                            if (plSong !== undefined) {
-                                Meteor.call("addSongToCommunityStationQueue", Session.get("CommunityStationName"), plSong.id, function (err) {
-                                    if (!err) {
-                                        Session.set("playlistQueueCurrentSong", plSong);
                                     }
-                                });
+                                }
                             }
                         }
                     }

+ 3 - 1
app/client/templates/communityStation.html

@@ -99,7 +99,9 @@
         <ul id="queue-ul" style="max-height: calc(100% - 105px); overflow-y: auto; margin: 0;">
             {{#each song in queue}}
                 <li class="queue-item" style="clear: both">
-                    <a class="queue-item-remove" style="float:right; height: 0; width: 0;" href="#" data-id={{song.song.id}}><i class="material-icons" data-id={{song.song.id}}>clear</i></a>
+                    {{#if isCommunityStationOwner name}}
+                        <a class="queue-item-remove" style="float:right; height: 0; width: 0;" href="#" data-id={{song.song.id}}><i class="material-icons" data-id={{song.song.id}}>clear</i></a>
+                    {{/if}}
                     <div class="queue-item-text">
                         <p class="queue-item-title">{{song.song.title}}</p>
                         <p class="queue-item-username">Added by <a style="display: inline-block; height: 10px; padding: 0; color: #039be5;" href="/profile/{{getUsernameFromId song.requestedBy}}">{{getUsernameFromId song.requestedBy}}</a></p>

+ 8 - 1
app/server/server.js

@@ -719,7 +719,11 @@ function CommunityStation(name) {
                         if ((this.getQueueDurationFromUser(userId) + duration) <= 900) {
                             if ((this.getSongsInQueueFromUser(userId)) <= 1) {
                                 data.id = id;
-                                CommunityStations.update({name: name}, {
+                                var res = CommunityStations.update(
+                                    {
+                                        name: name,
+                                        "queue.song.id": {"$ne" : data.id}
+                                    }, {
                                     $push: {
                                         queue: {
                                             requestedBy: userId,
@@ -727,6 +731,9 @@ function CommunityStation(name) {
                                         }
                                     }
                                 });
+                                if (res === 0) {
+                                    throw new Meteor.Error(500, "Something went wrong there. Maybe your song is already in the queue?");
+                                }
                                 queue = CommunityStations.findOne({name: name}).queue;
                                 if (queue.length === 1) {
                                     CommunityStations.update({name: name}, {