Преглед на файлове

Added ability to lock the queue.

KrisVos130 преди 8 години
родител
ревизия
df1f42be0d
променени са 6 файла, в които са добавени 99 реда и са изтрити 25 реда
  1. 24 0
      app/client/scripts/events.js
  2. 9 0
      app/client/scripts/helpers.js
  3. 7 0
      app/client/templates/communityStation.html
  4. 5 0
      app/lib/schemas.js
  5. 53 25
      app/server/server.js
  6. 1 0
      app/server/updateDatabase.js

+ 24 - 0
app/client/scripts/events.js

@@ -1725,6 +1725,30 @@ Template.communityStation.events({
                 }
             });
         }
+        if (partyMode) {
+            var queueLocked = $("#queueLocked").is(":checked");
+            if (queueLocked !== room.queueLocked) {
+                Meteor.call("setCommunityStationQueueLocked", name, queueLocked, function (err, res) {
+                    if (err) {
+                        if (queueLocked) {
+                            var $toastContent = $('<span><strong>Queue not locked.</strong> ' + err.reason + '</span>');
+                            Materialize.toast($toastContent, 2000);
+                        } else {
+                            var $toastContent = $('<span><strong>Queue not unlocked.</strong> ' + err.reason + '</span>');
+                            Materialize.toast($toastContent, 2000);
+                        }
+                    } else {
+                        if (queueLocked) {
+                            var $toastContent = $('<span><strong>Queue locked.</strong></span>');
+                            Materialize.toast($toastContent, 2000);
+                        } else {
+                            var $toastContent = $('<span><strong>Queue unlocked.</strong></span>');
+                            Materialize.toast($toastContent, 2000);
+                        }
+                    }
+                });
+            }
+        }
         $("#edit_room_modal").closeModal();
     },
     "input #volume_slider": function() {

+ 9 - 0
app/client/scripts/helpers.js

@@ -587,6 +587,15 @@ Template.communityStation.helpers({
             return "";
         }
     },
+    queueLockedChecked: function() {
+        var name = Session.get("CommunityStationName");
+        var room = CommunityStations.findOne({name: name});
+        if (room !== undefined && room.queueLocked === true) {
+            return "checked";
+        } else {
+            return "";
+        }
+    },
     partyModeEnabled: function() {
         var name = Session.get("CommunityStationName");
         var room = CommunityStations.findOne({name: name});

+ 7 - 0
app/client/templates/communityStation.html

@@ -235,6 +235,13 @@
                 <label for="partyModeEnabled">Party Mode Enabled</label>
                 <br><small><b>What is party mode?</b> Party mode is a mode in community stations where, if enabled, people can request songs to be added to the queue, which will then be played in the station.</small>
             </p>
+            {{#if partyModeEnabled}}
+                <p>
+                    <input type="checkbox" id="queueLocked" {{queueLockedChecked}} />
+                    <label for="queueLocked">Queue Locked</label>
+                    <br><small>Locking the queue will disallow normal users from adding songs to the queue.</small>
+                </p>
+            {{/if}}
             <button class="btn waves-effect waves-light" id="save_edit_room_changes">Save Changes</button>
             <button class="btn waves-effect waves-light right red" id="delete_room">Delete Room</button>
         </div>

+ 5 - 0
app/lib/schemas.js

@@ -374,6 +374,11 @@ Schemas.CommunityStation = new SimpleSchema({
         label: "Party mode",
         defaultValue: false
     },
+    queueLocked: {
+        type: Boolean,
+        label: "Queue locked",
+        defaultValue: false
+    },
     queue: {
         type: Array,
         label: "Community station queue",

+ 53 - 25
app/server/server.js

@@ -676,38 +676,52 @@ function CommunityStation(name) {
         });
     };
 
-    this.addSongToQueue = function(id, userId) {
-        var duplicate = false;
-        queue = CommunityStations.findOne({name: name}).queue;
-        queue.forEach(function(song) {
-            if (song.song.id === id) {
-                duplicate = true;
+    this.setQueueLocked = function(queueLocked) {
+        queueLocked = (typeof queueLocked === "boolean") ? queueLocked : false;
+        CommunityStations.update({name: name}, {
+            $set: {
+                queueLocked: queueLocked
             }
         });
-        if (!duplicate) {
-            var data = getSongDataYT(id);
-            if (data !== 0) {
-                data.id = id;
-                CommunityStations.update({name: name}, {$push: {queue: {requestedBy: userId, song: data}}});
-                queue = CommunityStations.findOne({name: name}).queue;
-                if (queue.length === 1) {
-                    CommunityStations.update({name: name}, {
-                        $set: {
-                            timePaused: 0,
-                            currentSong: {
-                                song: queue[0].song,
-                                requestedBy: queue[0].requestedBy,
-                                started: Date.now()
+        this.queueLocked = queueLocked;
+    };
+
+    this.addSongToQueue = function(id, userId) {
+        if (!this.queueLocked) {
+            var duplicate = false;
+            queue = CommunityStations.findOne({name: name}).queue;
+            queue.forEach(function (song) {
+                if (song.song.id === id) {
+                    duplicate = true;
+                }
+            });
+            if (!duplicate) {
+                var data = getSongDataYT(id);
+                if (data !== 0) {
+                    data.id = id;
+                    CommunityStations.update({name: name}, {$push: {queue: {requestedBy: userId, song: data}}});
+                    queue = CommunityStations.findOne({name: name}).queue;
+                    if (queue.length === 1) {
+                        CommunityStations.update({name: name}, {
+                            $set: {
+                                timePaused: 0,
+                                currentSong: {
+                                    song: queue[0].song,
+                                    requestedBy: queue[0].requestedBy,
+                                    started: Date.now()
+                                }
                             }
-                        }
-                    });
-                    this.songTimer();
+                        });
+                        this.songTimer();
+                    }
+                } else {
+                    throw new Meteor.Error(500, "Invalid song id.");
                 }
             } else {
-                throw new Meteor.Error(500, "Invalid song id.");
+                throw new Meteor.Error(500, "This song is already in the queue.");
             }
         } else {
-            throw new Meteor.Error(500, "This song is already in the queue.");
+            throw new Meteor.Error(500, "The queue is currently locked.");
         }
     };
 
@@ -733,6 +747,7 @@ function CommunityStation(name) {
         }
     };
 
+    this.queuelocked = _room.queueLocked;
     this.skipSong();
     this.voted = [];
 }
@@ -1154,6 +1169,19 @@ Meteor.updatedMethods({
             throw new Meteor.Error(403, "Invalid permissions.");
         }
     },
+    setCommunityStationQueueLocked: function(roomName, queueLocked) {
+        if ((isAdmin() || isCommunityStationOwner(roomName)) && !isBanned()) {
+            getCommunityStation(roomName, function(room) {
+                if (room !== 0) {
+                    room.setQueueLocked(queueLocked);
+                } else {
+                    throw new Meteor.Error(500, "Room not found.");
+                }
+            });
+        } else {
+            throw new Meteor.Error(403, "Invalid permissions.");
+        }
+    },
     addSongToCommunityStationQueue: {
         code: function(name, id) {
             getCommunityStation(name, function(station) {

+ 1 - 0
app/server/updateDatabase.js

@@ -1,4 +1,5 @@
 Meteor.startup(function() {
     CommunityStations.update({partyModeEnabled: {$exists: false}}, {$set: {partyModeEnabled: false}});
     CommunityStations.update({queue: {$exists: false}}, {$set: {queue: []}});
+    CommunityStations.update({queueLocked: {$exists: false}}, {$set: {queueLocked: false}});
 });