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",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.78.2",
"version": "3.79.0",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -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 () {

View File

@ -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()
};
}

View File

@ -837,6 +837,12 @@ function showPollMenu() {
var hidden = $("<input/>").attr("type", "checkbox")
.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);
var addbtn = $("<button/>").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) {