For convenience, queue next bumps if the item is already on the playlist

This commit is contained in:
calzoneman 2013-08-26 16:37:09 -05:00
parent c8ce8b530a
commit eee17f9daa
2 changed files with 22 additions and 7 deletions

View File

@ -169,22 +169,37 @@ Playlist.prototype.makeItem = function(media) {
} }
Playlist.prototype.add = function(item, pos) { Playlist.prototype.add = function(item, pos) {
if(this.items.length >= 4000) var self = this;
if(this.items.length >= 4000) {
return "Playlist limit reached (4,000)"; return "Playlist limit reached (4,000)";
}
if(this.items.findVideoId(item.media.id)) var it = this.items.findVideoId(item.media.id);
if(it) {
if(pos === "append" || it == this.current) {
return "This item is already on the playlist"; return "This item is already on the playlist";
}
self.remove(it.uid, function () {
self.channel.sendAll("delete", {
uid: it.uid
});
});
}
if(pos == "append") { if(pos == "append") {
if(!this.items.append(item)) if(!this.items.append(item)) {
return "Playlist failure"; return "Playlist failure";
}
} else if(pos == "prepend") { } else if(pos == "prepend") {
if(!this.items.prepend(item)) if(!this.items.prepend(item)) {
return "Playlist failure"; return "Playlist failure";
}
} else { } else {
if(!this.items.insertAfter(item, pos)) if(!this.items.insertAfter(item, pos)) {
return "Playlist failure"; return "Playlist failure";
} }
}
if(this.items.length == 1) { if(this.items.length == 1) {
this.current = item; this.current = item;

View File

@ -175,7 +175,7 @@ ULList.prototype.findVideoId = function (id) {
var item = this.first; var item = this.first;
while(item !== null) { while(item !== null) {
if(item.media && item.media.id === id) if(item.media && item.media.id === id)
return true; return item;
item = item.next; item = item.next;
} }
return false; return false;