diff --git a/changelog b/changelog
index cf57da7f..cbada241 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,11 @@
+Wed Sep 11 20:19 2013 CDT
+ * lib/poll.js: Add support for hidden polls
+ * lib/channel.js: Check permissions for viewing hidden polls
+ * lib/chatcommand.js: Add /hpoll for opening hidden polls
+ * www/assets/js/util.js: Update poll interface to include a checkbox
+ for whether or not to hide a poll. Update permissions interface to
+ allow for changing the permission to view obscured polls.
+
Tue Sep 10 22:40 2013 CDT
* www/account.html, www/acp.html, www/login.html:
Import www/assets/js/data.js for easy access to user preferences
diff --git a/lib/channel.js b/lib/channel.js
index ce0c1ea1..a0129e63 100644
--- a/lib/channel.js
+++ b/lib/channel.js
@@ -66,6 +66,7 @@ var Channel = function(name, Server) {
playlistclear: 2,
pollctl: 1.5,
pollvote: -1,
+ viewhiddenpoll: 1.5,
mute: 1.5,
kick: 1.5,
ban: 2,
@@ -1095,11 +1096,29 @@ Channel.prototype.broadcastUserUpdate = function(user) {
}
Channel.prototype.broadcastPoll = function() {
- this.sendAll("newPoll", this.poll.packUpdate());
+ var self = this;
+ var unhidden = this.poll.packUpdate(true);
+ var hidden = this.poll.packUpdate(false);
+
+ this.users.forEach(function (u) {
+ if (self.hasPermission(u, "viewhiddenpoll"))
+ u.socket.emit("newPoll", unhidden);
+ else
+ u.socket.emit("newPoll", hidden);
+ });
}
Channel.prototype.broadcastPollUpdate = function() {
- this.sendAll("updatePoll", this.poll.packUpdate());
+ var self = this;
+ var unhidden = this.poll.packUpdate(true);
+ var hidden = this.poll.packUpdate(false);
+
+ this.users.forEach(function (u) {
+ if (self.hasPermission(u, "viewhiddenpoll"))
+ u.socket.emit("updatePoll", unhidden);
+ else
+ u.socket.emit("updatePoll", hidden);
+ });
}
Channel.prototype.broadcastPollClose = function() {
@@ -1679,7 +1698,8 @@ Channel.prototype.tryOpenPoll = function(user, data) {
return;
}
- var poll = new Poll(user.name, data.title, data.opts);
+ var obscured = (data.obscured === true);
+ var poll = new Poll(user.name, data.title, data.opts, obscured);
this.poll = poll;
this.broadcastPoll();
this.logger.log("*** " + user.name + " Opened Poll: '" + poll.title + "'");
@@ -1691,6 +1711,10 @@ Channel.prototype.tryClosePoll = function(user) {
}
if(this.poll) {
+ if (this.poll.obscured) {
+ this.poll.obscured = false;
+ this.broadcastPollUpdate();
+ }
this.logger.log("*** " + user.name + " closed the active poll");
this.poll = false;
this.broadcastPollClose();
diff --git a/lib/chatcommand.js b/lib/chatcommand.js
index 1ad2d946..83a14614 100644
--- a/lib/chatcommand.js
+++ b/lib/chatcommand.js
@@ -73,7 +73,10 @@ function handle(chan, user, msg, data) {
handleUnban(chan, user, msg.substring(7).split(" "));
}
else if(msg.indexOf("/poll ") == 0) {
- handlePoll(chan, user, msg.substring(6));
+ handlePoll(chan, user, msg.substring(6), false);
+ }
+ else if(msg.indexOf("/hpoll ") == 0) {
+ handlePoll(chan, user, msg.substring(6), true);
}
else if(msg.indexOf("/d") == 0 && msg.length > 2 &&
msg[2].match(/[-0-9 ]/)) {
@@ -195,12 +198,12 @@ function handleUnban(chan, user, args) {
}
}
-function handlePoll(chan, user, msg) {
+function handlePoll(chan, user, msg, hidden) {
if(chan.hasPermission(user, "pollctl")) {
var args = msg.split(",");
var title = args[0];
args.splice(0, 1);
- var poll = new Poll(user.name, title, args);
+ var poll = new Poll(user.name, title, args, hidden === true);
chan.poll = poll;
chan.broadcastPoll();
chan.logger.log("*** " + user.name + " Opened Poll: '" + poll.title + "'");
diff --git a/lib/poll.js b/lib/poll.js
index 37b6d94b..396e6ae0 100644
--- a/lib/poll.js
+++ b/lib/poll.js
@@ -9,10 +9,11 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-var Poll = function(initiator, title, options) {
+var Poll = function(initiator, title, options, obscured) {
this.initiator = initiator;
this.title = title;
this.options = options;
+ this.obscured = obscured || false;
this.counts = new Array(options.length);
for(var i = 0; i < this.counts.length; i++) {
this.counts[i] = 0;
@@ -34,13 +35,22 @@ Poll.prototype.unvote = function(ip) {
}
}
-Poll.prototype.packUpdate = function() {
- return {
+Poll.prototype.packUpdate = function (showhidden) {
+ var counts = Array.prototype.slice.call(this.counts);
+ if (this.obscured) {
+ for(var i = 0; i < counts.length; i++) {
+ if (!showhidden)
+ counts[i] = "";
+ counts[i] += "?";
+ }
+ }
+ var packed = {
title: this.title,
options: this.options,
- counts: this.counts,
+ counts: counts,
initiator: this.initiator
- }
+ };
+ return packed;
}
exports.Poll = Poll;
diff --git a/www/assets/js/util.js b/www/assets/js/util.js
index bb57ba2a..9fb8b4fe 100644
--- a/www/assets/js/util.js
+++ b/www/assets/js/util.js
@@ -899,6 +899,13 @@ function showPollMenu() {
.appendTo(menu);
$("
").appendTo(menu);
+ var lbl = $("").addClass("checkbox")
+ .text("Hide poll results")
+ .appendTo(menu);
+ var hidden = $("").attr("type", "checkbox")
+ .appendTo(lbl);
+ $("
").appendTo(menu);
+
$("").text("Options").appendTo(menu);
$("
").appendTo(menu);
@@ -931,7 +938,8 @@ function showPollMenu() {
});
socket.emit("newPoll", {
title: title.val(),
- opts: opts
+ opts: opts,
+ obscured: hidden.prop("checked")
});
menu.remove();
});
@@ -1589,6 +1597,7 @@ function genPermissionsEditor() {
addDivider("Polls");
makeOption("Open/Close poll", "pollctl", modleader, CHANNEL.perms.pollctl+"");
makeOption("Vote", "pollvote", standard, CHANNEL.perms.pollvote+"");
+ makeOption("View hidden poll results", "viewhiddenpoll", standard, CHANNEL.perms.viewhiddenpoll+"");
addDivider("Moderation");
makeOption("Mute users", "mute", modleader, CHANNEL.perms.mute+"");