mirror of https://github.com/calzoneman/sync.git
Fix #924
This commit is contained in:
parent
f41e0bda82
commit
af62fbaef4
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.82.4",
|
"version": "3.82.5",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -97,7 +97,6 @@ PollModule.prototype.sendPoll = function (user) {
|
||||||
|
|
||||||
var perms = this.channel.modules.permissions;
|
var perms = this.channel.modules.permissions;
|
||||||
|
|
||||||
user.socket.emit("closePoll");
|
|
||||||
if (perms.canViewHiddenPoll(user)) {
|
if (perms.canViewHiddenPoll(user)) {
|
||||||
var unobscured = this.poll.toUpdateFrame(true);
|
var unobscured = this.poll.toUpdateFrame(true);
|
||||||
user.socket.emit("newPoll", unobscured);
|
user.socket.emit("newPoll", unobscured);
|
||||||
|
@ -116,9 +115,6 @@ PollModule.prototype.broadcastPoll = function (isNewPoll) {
|
||||||
var unobscured = this.poll.toUpdateFrame(true);
|
var unobscured = this.poll.toUpdateFrame(true);
|
||||||
|
|
||||||
const event = isNewPoll ? "newPoll" : "updatePoll";
|
const event = isNewPoll ? "newPoll" : "updatePoll";
|
||||||
if (isNewPoll) {
|
|
||||||
this.channel.broadcastAll("closePoll");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.channel.broadcastToRoom(event, unobscured, this.roomViewHidden);
|
this.channel.broadcastToRoom(event, unobscured, this.roomViewHidden);
|
||||||
this.channel.broadcastToRoom(event, obscured, this.roomNoViewHidden);
|
this.channel.broadcastToRoom(event, obscured, this.roomNoViewHidden);
|
||||||
|
@ -152,6 +148,9 @@ PollModule.prototype.handleNewPoll = function (user, data, ack) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure any existing poll is closed
|
||||||
|
this.handleClosePoll(user);
|
||||||
|
|
||||||
ack = ackOrErrorMsg(ack, user);
|
ack = ackOrErrorMsg(ack, user);
|
||||||
|
|
||||||
if (typeof data !== 'object' || data === null) {
|
if (typeof data !== 'object' || data === null) {
|
||||||
|
@ -252,6 +251,9 @@ PollModule.prototype.handlePollCmd = function (obscured, user, msg, _meta) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure any existing poll is closed
|
||||||
|
this.handleClosePoll(user);
|
||||||
|
|
||||||
msg = msg.replace(/^\/h?poll/, "");
|
msg = msg.replace(/^\/h?poll/, "");
|
||||||
|
|
||||||
var args = msg.split(",");
|
var args = msg.split(",");
|
||||||
|
|
|
@ -97,7 +97,10 @@ describe('PollModule', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let pollModule = new PollModule(fakeChannel);
|
let pollModule;
|
||||||
|
beforeEach(() => {
|
||||||
|
pollModule = new PollModule(fakeChannel);
|
||||||
|
});
|
||||||
|
|
||||||
it('creates a valid poll', () => {
|
it('creates a valid poll', () => {
|
||||||
let sentNewPoll = false;
|
let sentNewPoll = false;
|
||||||
|
@ -122,10 +125,54 @@ describe('PollModule', () => {
|
||||||
}, (ackResult) => {
|
}, (ackResult) => {
|
||||||
assert(!ackResult.error, `Unexpected error: ${ackResult.error}`);
|
assert(!ackResult.error, `Unexpected error: ${ackResult.error}`);
|
||||||
});
|
});
|
||||||
assert(sentClosePoll, 'Expected broadcast of closePoll event');
|
assert(!sentClosePoll, 'Unexpected broadcast of closePoll event');
|
||||||
assert(sentNewPoll, 'Expected broadcast of newPoll event');
|
assert(sentNewPoll, 'Expected broadcast of newPoll event');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('closes an existing poll when a new one is created', () => {
|
||||||
|
let sentNewPoll = 0;
|
||||||
|
let sentClosePoll = 0;
|
||||||
|
let sentUpdatePoll = 0;
|
||||||
|
fakeChannel.broadcastToRoom = (event, data, room) => {
|
||||||
|
if (room === 'testChannel:viewHidden' && event === 'newPoll') {
|
||||||
|
sentNewPoll++;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fakeChannel.broadcastAll = (event, data) => {
|
||||||
|
if (event === 'closePoll') {
|
||||||
|
sentClosePoll++;
|
||||||
|
} else if (event === 'updatePoll') {
|
||||||
|
sentUpdatePoll++;
|
||||||
|
assert.deepStrictEqual(data.counts, [0, 0]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
pollModule.handleNewPoll(fakeUser, {
|
||||||
|
title: 'test poll',
|
||||||
|
opts: [
|
||||||
|
'option 1',
|
||||||
|
'option 2'
|
||||||
|
],
|
||||||
|
obscured: true
|
||||||
|
}, (ackResult) => {
|
||||||
|
assert(!ackResult.error, `Unexpected error: ${ackResult.error}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
pollModule.handleNewPoll(fakeUser, {
|
||||||
|
title: 'poll 2',
|
||||||
|
opts: [
|
||||||
|
'option 3',
|
||||||
|
'option 4'
|
||||||
|
],
|
||||||
|
obscured: false
|
||||||
|
}, (ackResult) => {
|
||||||
|
assert(!ackResult.error, `Unexpected error: ${ackResult.error}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.strictEqual(sentClosePoll, 1, 'Expected 1 broadcast of closePoll event');
|
||||||
|
assert.strictEqual(sentUpdatePoll, 1, 'Expected 1 broadcast of updatePoll event');
|
||||||
|
assert.strictEqual(sentNewPoll, 2, 'Expected 2 broadcasts of newPoll event');
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects an invalid poll', () => {
|
it('rejects an invalid poll', () => {
|
||||||
fakeChannel.broadcastToRoom = (event, data, room) => {
|
fakeChannel.broadcastToRoom = (event, data, room) => {
|
||||||
assert(false, 'Expected no events to be sent');
|
assert(false, 'Expected no events to be sent');
|
||||||
|
@ -171,4 +218,4 @@ describe('PollModule', () => {
|
||||||
assert(sentErrorMsg, 'Expected to send errorMsg since ack was missing');
|
assert(sentErrorMsg, 'Expected to send errorMsg since ack was missing');
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue