This commit is contained in:
Calvin Montgomery 2021-08-11 21:13:59 -07:00
parent 9a008d4623
commit c717a55c2d
4 changed files with 24 additions and 5 deletions

View File

@ -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.78.2", "version": "3.79.0",
"repository": { "repository": {
"url": "http://github.com/calzoneman/sync" "url": "http://github.com/calzoneman/sync"
}, },

View File

@ -8,6 +8,7 @@ const TYPE_NEW_POLL = {
title: "string", title: "string",
timeout: "number,optional", timeout: "number,optional",
obscured: "boolean", obscured: "boolean",
retainVotes: "boolean,optional",
opts: "array" opts: "array"
}; };
@ -84,7 +85,7 @@ PollModule.prototype.addUserToPollRoom = function (user) {
}; };
PollModule.prototype.onUserPart = 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); this.broadcastPoll(false);
} }
}; };
@ -183,7 +184,15 @@ PollModule.prototype.handleNewPoll = function (user, data, ack) {
return; 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; var self = this;
if (data.hasOwnProperty("timeout")) { if (data.hasOwnProperty("timeout")) {
poll.timer = setTimeout(function () { poll.timer = setTimeout(function () {

View File

@ -7,18 +7,19 @@ function sanitizedWithLinksReplaced(text) {
} }
class Poll { class Poll {
static create(createdBy, title, choices, options = { hideVotes: false }) { static create(createdBy, title, choices, options = { hideVotes: false, retainVotes: false }) {
let poll = new Poll(); let poll = new Poll();
poll.createdAt = new Date(); poll.createdAt = new Date();
poll.createdBy = createdBy; poll.createdBy = createdBy;
poll.title = sanitizedWithLinksReplaced(title); poll.title = sanitizedWithLinksReplaced(title);
poll.choices = choices.map(choice => sanitizedWithLinksReplaced(choice)); poll.choices = choices.map(choice => sanitizedWithLinksReplaced(choice));
poll.hideVotes = options.hideVotes; poll.hideVotes = options.hideVotes;
poll.retainVotes = options.retainVotes;
poll.votes = new Map(); poll.votes = new Map();
return poll; 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(); let poll = new Poll();
if (timestamp === undefined) // Very old polls still in the database lack timestamps if (timestamp === undefined) // Very old polls still in the database lack timestamps
timestamp = Date.now(); timestamp = Date.now();
@ -32,6 +33,7 @@ class Poll {
poll.votes.set(key, votes[key]); poll.votes.set(key, votes[key]);
}); });
poll.hideVotes = obscured; poll.hideVotes = obscured;
poll.retainVotes = retainVotes || false;
return poll; return poll;
} }
@ -55,6 +57,7 @@ class Poll {
counts, counts,
votes, votes,
obscured: this.hideVotes, obscured: this.hideVotes,
retainVotes: this.retainVotes,
timestamp: this.createdAt.getTime() timestamp: this.createdAt.getTime()
}; };
} }

View File

@ -837,6 +837,12 @@ function showPollMenu() {
var hidden = $("<input/>").attr("type", "checkbox") var hidden = $("<input/>").attr("type", "checkbox")
.prependTo(lbl); .prependTo(lbl);
var retainVotesOuter = $("<div/>").addClass("checkbox").appendTo(menu);
var retainVotesLbl = $("<label/>").text("Keep poll vote after user leaves")
.appendTo(retainVotesOuter);
var retainVotes = $("<input/>").attr("type", "checkbox")
.prependTo(retainVotesLbl);
$("<strong/>").text("Options").appendTo(menu); $("<strong/>").text("Options").appendTo(menu);
var addbtn = $("<button/>").addClass("btn btn-sm btn-default") var addbtn = $("<button/>").addClass("btn btn-sm btn-default")
@ -885,6 +891,7 @@ function showPollMenu() {
title: title.val(), title: title.val(),
opts: opts, opts: opts,
obscured: hidden.prop("checked"), obscured: hidden.prop("checked"),
retainVotes: retainVotes.prop("checked"),
timeout: t timeout: t
}, function ack(result) { }, function ack(result) {
if (result.error) { if (result.error) {