mirror of https://github.com/calzoneman/sync.git
Add support for hidden polls
This commit is contained in:
parent
020ceecd40
commit
7e9673425d
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 + "'");
|
||||
|
|
20
lib/poll.js
20
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;
|
||||
|
|
|
@ -899,6 +899,13 @@ function showPollMenu() {
|
|||
.appendTo(menu);
|
||||
$("<br/>").appendTo(menu);
|
||||
|
||||
var lbl = $("<label/>").addClass("checkbox")
|
||||
.text("Hide poll results")
|
||||
.appendTo(menu);
|
||||
var hidden = $("<input/>").attr("type", "checkbox")
|
||||
.appendTo(lbl);
|
||||
$("<br/>").appendTo(menu);
|
||||
|
||||
$("<strong/>").text("Options").appendTo(menu);
|
||||
$("<br/>").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+"");
|
||||
|
|
Loading…
Reference in New Issue