Poll Visibility
The visibility field of a poll decides who sees which part of the result, both while the poll is running and after it closes. It replaces the deprecated type field. The user facing description of the poll types is on the Poll types page.
visibility is a single number that packs ten settings with two bits each. Every setting holds one of three audiences.
| Value | Audience |
|---|---|
0 | Everyone |
1 | Admins only (members with Manage Server) |
2 | Hidden, nobody |
The value 3 is reserved and rejected.
Bit Layout
| Bits | Setting |
|---|---|
| 0-1 | Vote counts, while running |
| 2-3 | Vote counts, after close |
| 4-5 | Answer ranking, while running |
| 6-7 | Answer ranking, after close |
| 8-9 | Who voted for what, while running |
| 10-11 | Who voted for what, after close |
| 12-13 | Participant list, while running |
| 14-15 | Participant list, after close |
| 16-17 | Total vote count, while running |
| 18-19 | Total vote count, after close |
Poll Types
The ready-made poll types are fixed values. Everything else is a custom visibility.
| Poll type | visibility |
|---|---|
| Public, Normal (Legacy) | 0 |
| Anonymous | 43520 |
| Secret Winner | 546 |
| Reveal at End | 139810 |
| Blind Voting, Anonymous (Legacy) | 174626 |
| Hidden (Legacy) | 152866 |
Working With the Bitfield
Each setting sits at index * 2, in the order of the table above.
const SETTINGS = [
'voteCountsDuring',
'voteCountsAfter',
'answerRankingDuring',
'answerRankingAfter',
'participantAnswersDuring',
'participantAnswersAfter',
'participantsListDuring',
'participantsListAfter',
'totalVotesDuring',
'totalVotesAfter'
];
const decode = (visibility) =>
Object.fromEntries(SETTINGS.map((name, index) => [name, (visibility >> (index * 2)) & 0b11]));
const encode = (settings) =>
SETTINGS.reduce((value, name, index) => value | (settings[name] << (index * 2)), 0);
// Secret Winner, but the participant list is only visible to admins while the poll is running
const settings = decode(546);
settings.participantsListDuring = 1;
await fetch(`https://easypoll.com/api/v1/polls/${pollId}`, {
method: 'PATCH',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ visibility: encode(settings) })
});
Rules
- A value with the reserved audience
3in any setting, or outside of0to1048575, is rejected with400 Bad Request. - Who voted for what names the voters too, so it is never visible to more people than the participant list. A wider value is narrowed to the participant list's audience when the poll is saved, and the response contains the stored value.
- Once a poll has votes, a change that would show its voters to more people than before is rejected with
403 Forbidden. Changes that keep or narrow who sees the voters are always allowed. GET /polls/:pollId/votesanswers403 Forbiddenwhile who voted for what is hidden from everyone.
The Deprecated type Field
type is still accepted when creating or updating a poll, and visibility takes precedence if both are sent. In responses, type is derived from visibility. It is Normal, Anonymous or Hidden when the poll behaves exactly like that legacy type, and null for every other visibility. New integrations should only use visibility.