mirror of https://github.com/calzoneman/sync.git
Add poll timers
This commit is contained in:
parent
3bebc34e21
commit
cec68d0f2a
|
@ -2112,6 +2112,14 @@ Channel.prototype.handleOpenPoll = function (user, data) {
|
||||||
|
|
||||||
var obscured = (data.obscured === true);
|
var obscured = (data.obscured === true);
|
||||||
var poll = new Poll(user.name, title, opts, obscured);
|
var poll = new Poll(user.name, title, opts, obscured);
|
||||||
|
var self = this;
|
||||||
|
if (typeof data.timeout === "number" && !isNaN(data.timeout) && data.timeout > 0) {
|
||||||
|
poll.timer = setTimeout(function () {
|
||||||
|
if (self.poll === poll) {
|
||||||
|
self.handleClosePoll({ name: "[poll timer]", rank: 255 });
|
||||||
|
}
|
||||||
|
}, data.timeout * 1000);
|
||||||
|
}
|
||||||
this.poll = poll;
|
this.poll = poll;
|
||||||
this.sendPoll(this.users, true);
|
this.sendPoll(this.users, true);
|
||||||
this.logger.log("[poll] " + user.name + " Opened Poll: '" + poll.title + "'");
|
this.logger.log("[poll] " + user.name + " Opened Poll: '" + poll.title + "'");
|
||||||
|
@ -2131,6 +2139,10 @@ Channel.prototype.handleClosePoll = function (user) {
|
||||||
this.sendPollUpdate(this.users);
|
this.sendPollUpdate(this.users);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.poll.timer) {
|
||||||
|
clearTimeout(this.poll.timer);
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.log("[poll] " + user.name + " closed the active poll");
|
this.logger.log("[poll] " + user.name + " closed the active poll");
|
||||||
this.poll = false;
|
this.poll = false;
|
||||||
this.sendAll("closePoll");
|
this.sendAll("closePoll");
|
||||||
|
|
|
@ -73,7 +73,6 @@ var handlers = {
|
||||||
|
|
||||||
/* commands that do not send chat messages */
|
/* commands that do not send chat messages */
|
||||||
"afk": function (chan, user, msg, meta) {
|
"afk": function (chan, user, msg, meta) {
|
||||||
console.log("/afk => setAfk(!" + user.meta.afk + ")");
|
|
||||||
user.setAFK(!user.meta.afk);
|
user.setAFK(!user.meta.afk);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|
|
@ -720,6 +720,11 @@ function showPollMenu() {
|
||||||
.attr("type", "text")
|
.attr("type", "text")
|
||||||
.appendTo(menu);
|
.appendTo(menu);
|
||||||
|
|
||||||
|
$("<strong/>").text("Timeout (optional)").appendTo(menu);
|
||||||
|
var timeout = $("<input/>").addClass("form-control")
|
||||||
|
.attr("type", "text")
|
||||||
|
.appendTo(menu);
|
||||||
|
|
||||||
var lbl = $("<label/>").addClass("checkbox")
|
var lbl = $("<label/>").addClass("checkbox")
|
||||||
.text("Hide poll results")
|
.text("Hide poll results")
|
||||||
.appendTo(menu);
|
.appendTo(menu);
|
||||||
|
@ -747,7 +752,7 @@ function showPollMenu() {
|
||||||
.text("Open Poll")
|
.text("Open Poll")
|
||||||
.appendTo(menu)
|
.appendTo(menu)
|
||||||
.click(function() {
|
.click(function() {
|
||||||
var opts = []
|
var opts = [];
|
||||||
menu.find(".poll-menu-option").each(function() {
|
menu.find(".poll-menu-option").each(function() {
|
||||||
if($(this).val() != "")
|
if($(this).val() != "")
|
||||||
opts.push($(this).val());
|
opts.push($(this).val());
|
||||||
|
@ -755,7 +760,8 @@ function showPollMenu() {
|
||||||
socket.emit("newPoll", {
|
socket.emit("newPoll", {
|
||||||
title: title.val(),
|
title: title.val(),
|
||||||
opts: opts,
|
opts: opts,
|
||||||
obscured: hidden.prop("checked")
|
obscured: hidden.prop("checked"),
|
||||||
|
timeout: timeout.val() ? parseInt(timeout.val()) : undefined
|
||||||
});
|
});
|
||||||
menu.remove();
|
menu.remove();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue