mirror of https://github.com/calzoneman/sync.git
made slightly more efficient in response to comments
This commit is contained in:
parent
c905280125
commit
48de471064
|
@ -254,26 +254,21 @@ function handleClean(chan, user, target) {
|
||||||
// you can use regexps, in case someone tries
|
// you can use regexps, in case someone tries
|
||||||
// to fool you with cyrillic or something.
|
// to fool you with cyrillic or something.
|
||||||
target = new RegExp(target);
|
target = new RegExp(target);
|
||||||
var uid = false; // to skip first chan.sendAll()
|
|
||||||
// local variables for deleteNext() callback
|
// local variables for deleteNext() callback
|
||||||
var pl = chan.playlist;
|
var pl = chan.playlist;
|
||||||
var count = 0;
|
var count = 0;
|
||||||
|
var matches = pl.items.findAll(function(item) {
|
||||||
|
return target.test(item.queueby);
|
||||||
|
});
|
||||||
|
console.log(matches);
|
||||||
var deleteNext;
|
var deleteNext;
|
||||||
// this callback will search for matching items,
|
|
||||||
// and if one is found, call the remove method
|
|
||||||
// with itself as the callback to execute after
|
|
||||||
// the remove is finished.
|
|
||||||
deleteNext = function() {
|
deleteNext = function() {
|
||||||
// notify channel that this is deleted
|
if (count < matches.length) {
|
||||||
if (uid !== false) {
|
var uid=matches[count].uid;
|
||||||
|
count += 1
|
||||||
chan.sendAll("delete", {
|
chan.sendAll("delete", {
|
||||||
uid: uid
|
uid: uid
|
||||||
});
|
});
|
||||||
}
|
|
||||||
// find next match
|
|
||||||
uid = pl.items.findSubmitter(target);
|
|
||||||
if (uid !== false) {
|
|
||||||
// remove, and restart callback when removed.
|
|
||||||
pl.remove(uid, deleteNext);
|
pl.remove(uid, deleteNext);
|
||||||
} else {
|
} else {
|
||||||
// refresh playlist only once, at the end
|
// refresh playlist only once, at the end
|
||||||
|
|
21
ullist.js
21
ullist.js
|
@ -181,21 +181,14 @@ ULList.prototype.findVideoId = function (id) {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
ULList.prototype.findAll = function(fn) {
|
||||||
returns the UID of the first item in the queue that
|
var result = [];
|
||||||
was submitted by a user matching the target regexp.
|
this.forEach(function(item) {
|
||||||
*/
|
if( fn(item) ) {
|
||||||
ULList.prototype.findSubmitter = function(target) {
|
result.push(item);
|
||||||
var item = this.first;
|
|
||||||
|
|
||||||
while(item !== null) {
|
|
||||||
if(item.queueby && target.test(item.queueby)) {
|
|
||||||
console.log("found", item.uid, target, item.queueby);
|
|
||||||
return item.uid;
|
|
||||||
}
|
}
|
||||||
item = item.next;
|
});
|
||||||
}
|
return result;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.ULList = ULList;
|
exports.ULList = ULList;
|
||||||
|
|
Loading…
Reference in New Issue