Implement #884
This commit is contained in:
parent
9a008d4623
commit
c717a55c2d
4 changed files with 24 additions and 5 deletions
|
|
@ -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 () {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue