Fix voteskip issue when there are no videos left
This commit is contained in:
parent
309cd40da2
commit
7595faf11d
|
@ -2,7 +2,7 @@
|
|||
"author": "Calvin Montgomery",
|
||||
"name": "CyTube",
|
||||
"description": "Online media synchronizer and chat",
|
||||
"version": "3.34.5",
|
||||
"version": "3.34.6",
|
||||
"repository": {
|
||||
"url": "http://github.com/calzoneman/sync"
|
||||
},
|
||||
|
|
|
@ -75,13 +75,14 @@ VoteskipModule.prototype.update = function () {
|
|||
return;
|
||||
}
|
||||
|
||||
this.sendVoteskipData(this.channel.users);
|
||||
|
||||
var max = this.calcVoteskipMax();
|
||||
var need = Math.ceil(max * this.channel.modules.options.get("voteskip_ratio"));
|
||||
if (this.poll.counts[0] >= need) {
|
||||
this.channel.logger.log("[playlist] Voteskip passed.");
|
||||
this.reset();
|
||||
this.channel.modules.playlist._playNext();
|
||||
} else {
|
||||
this.sendVoteskipData(this.channel.users);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -115,9 +116,13 @@ VoteskipModule.prototype.calcVoteskipMax = function () {
|
|||
}, 0);
|
||||
};
|
||||
|
||||
VoteskipModule.prototype.onMediaChange = function (data) {
|
||||
VoteskipModule.prototype.reset = function reset() {
|
||||
this.poll = false;
|
||||
this.sendVoteskipData(this.channel.users);
|
||||
};
|
||||
|
||||
VoteskipModule.prototype.onMediaChange = function (data) {
|
||||
this.reset();
|
||||
};
|
||||
|
||||
module.exports = VoteskipModule;
|
||||
|
|
76
test/channel/voteskip.js
Normal file
76
test/channel/voteskip.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
const VoteskipModule = require('../../lib/channel/voteskip');
|
||||
const assert = require('assert');
|
||||
|
||||
describe('VoteskipModule', () => {
|
||||
describe('#update', () => {
|
||||
let fakeUser = {
|
||||
socket: {
|
||||
emit() {
|
||||
|
||||
}
|
||||
},
|
||||
is() {
|
||||
return false
|
||||
}
|
||||
};
|
||||
let fakeChannel = {
|
||||
logger: {
|
||||
log() {
|
||||
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
permissions: {
|
||||
canSeeVoteskipResults() {
|
||||
return true;
|
||||
},
|
||||
canVoteskip() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
options: {
|
||||
get(key) {
|
||||
if (key === 'voteskip_ratio') {
|
||||
return 0.5;
|
||||
} else if (key === 'allow_voteskip') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
playlist: {
|
||||
meta: {
|
||||
count: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
users: [fakeUser]
|
||||
};
|
||||
|
||||
let voteskipModule = new VoteskipModule(fakeChannel);
|
||||
|
||||
it('resets the vote before changing to the next video', () => {
|
||||
let reset = false, playNext = false;
|
||||
fakeChannel.modules.playlist._playNext = () => {
|
||||
if (!reset) {
|
||||
assert(false, 'Expected voteskip reset prior to playlist._playNext');
|
||||
}
|
||||
|
||||
playNext = true;
|
||||
};
|
||||
fakeUser.socket.emit = (event, data) => {
|
||||
if (event === 'voteskip') {
|
||||
assert.deepEqual(data, { count: 0, need: 0 });
|
||||
reset = true;
|
||||
}
|
||||
};
|
||||
|
||||
voteskipModule.poll = {
|
||||
counts: [1]
|
||||
};
|
||||
voteskipModule.update();
|
||||
assert.equal(voteskipModule.poll, false, 'Expected voteskip poll to be reset to false');
|
||||
assert(reset, 'Expected voteskip to be reset');
|
||||
assert(playNext, 'Expected playlist to be advanced');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue