Skip to main content

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.

ValueAudience
0Everyone
1Admins only (members with Manage Server)
2Hidden, nobody

The value 3 is reserved and rejected.

Bit Layout​

BitsSetting
0-1Vote counts, while running
2-3Vote counts, after close
4-5Answer ranking, while running
6-7Answer ranking, after close
8-9Who voted for what, while running
10-11Who voted for what, after close
12-13Participant list, while running
14-15Participant list, after close
16-17Total vote count, while running
18-19Total vote count, after close

Poll Types​

The ready-made poll types are fixed values. Everything else is a custom visibility.

Poll typevisibility
Public, Normal (Legacy)0
Anonymous43520
Secret Winner546
Reveal at End139810
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 3 in any setting, or outside of 0 to 1048575, is rejected with 400 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/votes answers 403 Forbidden while 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.