diff --git a/package.json b/package.json index 49aa01e0..25c8c5a2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.78.2", + "version": "3.79.0", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/channel/poll.js b/src/channel/poll.js index 12b39810..6393e1d4 100644 --- a/src/channel/poll.js +++ b/src/channel/poll.js @@ -8,6 +8,7 @@ const TYPE_NEW_POLL = { title: "string", timeout: "number,optional", obscured: "boolean", + retainVotes: "boolean,optional", opts: "array" }; @@ -84,7 +85,7 @@ PollModule.prototype.addUserToPollRoom = function (user) { }; PollModule.prototype.onUserPart = function(user) { - if (this.poll && this.poll.uncountVote(user.realip)) { + if (this.poll && !this.poll.retainVotes && this.poll.uncountVote(user.realip)) { this.broadcastPoll(false); } }; @@ -183,7 +184,15 @@ PollModule.prototype.handleNewPoll = function (user, data, ack) { return; } - var poll = Poll.create(user.getName(), data.title, data.opts, { hideVotes: data.obscured }); + var poll = Poll.create( + user.getName(), + data.title, + data.opts, + { + hideVotes: data.obscured, + retainVotes: data.retainVotes === undefined ? false : data.retainVotes + } + ); var self = this; if (data.hasOwnProperty("timeout")) { poll.timer = setTimeout(function () { diff --git a/src/poll.js b/src/poll.js index 212a98a8..aa4d9bac 100644 --- a/src/poll.js +++ b/src/poll.js @@ -7,18 +7,19 @@ function sanitizedWithLinksReplaced(text) { } class Poll { - static create(createdBy, title, choices, options = { hideVotes: false }) { + static create(createdBy, title, choices, options = { hideVotes: false, retainVotes: false }) { let poll = new Poll(); poll.createdAt = new Date(); poll.createdBy = createdBy; poll.title = sanitizedWithLinksReplaced(title); poll.choices = choices.map(choice => sanitizedWithLinksReplaced(choice)); poll.hideVotes = options.hideVotes; + poll.retainVotes = options.retainVotes; poll.votes = new Map(); return poll; } - static fromChannelData({ initiator, title, options, _counts, votes, timestamp, obscured }) { + static fromChannelData({ initiator, title, options, _counts, votes, timestamp, obscured, retainVotes }) { let poll = new Poll(); if (timestamp === undefined) // Very old polls still in the database lack timestamps timestamp = Date.now(); @@ -32,6 +33,7 @@ class Poll { poll.votes.set(key, votes[key]); }); poll.hideVotes = obscured; + poll.retainVotes = retainVotes || false; return poll; } @@ -55,6 +57,7 @@ class Poll { counts, votes, obscured: this.hideVotes, + retainVotes: this.retainVotes, timestamp: this.createdAt.getTime() }; } diff --git a/www/js/util.js b/www/js/util.js index 4c06390d..6f77d97f 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -837,6 +837,12 @@ function showPollMenu() { var hidden = $("").attr("type", "checkbox") .prependTo(lbl); + var retainVotesOuter = $("
").addClass("checkbox").appendTo(menu); + var retainVotesLbl = $("").text("Keep poll vote after user leaves") + .appendTo(retainVotesOuter); + var retainVotes = $("").attr("type", "checkbox") + .prependTo(retainVotesLbl); + $("").text("Options").appendTo(menu); var addbtn = $("").addClass("btn btn-sm btn-default") @@ -885,6 +891,7 @@ function showPollMenu() { title: title.val(), opts: opts, obscured: hidden.prop("checked"), + retainVotes: retainVotes.prop("checked"), timeout: t }, function ack(result) { if (result.error) {