From eee17f9daa33a0d72729ff360fb75f758bf6982e Mon Sep 17 00:00:00 2001 From: calzoneman Date: Mon, 26 Aug 2013 16:37:09 -0500 Subject: [PATCH] For convenience, queue next bumps if the item is already on the playlist --- playlist.js | 27 +++++++++++++++++++++------ ullist.js | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/playlist.js b/playlist.js index a65d1ccf..baba946d 100644 --- a/playlist.js +++ b/playlist.js @@ -169,21 +169,36 @@ Playlist.prototype.makeItem = function(media) { } 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)"; + } - if(this.items.findVideoId(item.media.id)) - return "This item is already on the playlist"; + var it = this.items.findVideoId(item.media.id); + if(it) { + if(pos === "append" || it == this.current) { + return "This item is already on the playlist"; + } + + self.remove(it.uid, function () { + self.channel.sendAll("delete", { + uid: it.uid + }); + }); + } if(pos == "append") { - if(!this.items.append(item)) + if(!this.items.append(item)) { return "Playlist failure"; + } } else if(pos == "prepend") { - if(!this.items.prepend(item)) + if(!this.items.prepend(item)) { return "Playlist failure"; + } } else { - if(!this.items.insertAfter(item, pos)) + if(!this.items.insertAfter(item, pos)) { return "Playlist failure"; + } } if(this.items.length == 1) { diff --git a/ullist.js b/ullist.js index f4ad4638..24785fad 100644 --- a/ullist.js +++ b/ullist.js @@ -175,7 +175,7 @@ ULList.prototype.findVideoId = function (id) { var item = this.first; while(item !== null) { if(item.media && item.media.id === id) - return true; + return item; item = item.next; } return false;