Support "closed" polls whose votes are not visible until they are ended (#7842)

This commit is contained in:
Andy Balaam 2022-02-21 10:21:35 +00:00 committed by GitHub
parent eca64d776a
commit f1e1b7be86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 248 additions and 11 deletions

View file

@ -21,6 +21,7 @@ import { Relations } from 'matrix-js-sdk/src/models/relations';
import { MatrixClient } from 'matrix-js-sdk/src/matrix';
import {
M_POLL_END,
M_POLL_KIND_DISCLOSED,
M_POLL_RESPONSE,
M_POLL_START,
NamespacedValue,
@ -431,6 +432,11 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
const winCount = Math.max(...votes.values());
const userId = this.context.getUserId();
const myVote = userVotes.get(userId)?.answers[0];
const disclosed = M_POLL_KIND_DISCLOSED.matches(poll.kind.name);
// Disclosed: votes are hidden until I vote or the poll ends
// Undisclosed: votes are hidden until poll ends
const showResults = ended || (disclosed && myVote !== undefined);
let totalText: string;
if (ended) {
@ -438,6 +444,8 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
"Final result based on %(count)s votes",
{ count: totalVotes },
);
} else if (!disclosed) {
totalText = _t("Results will be visible when the poll is ended");
} else if (myVote === undefined) {
if (totalVotes === 0) {
totalText = _t("No votes cast");
@ -465,8 +473,7 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
let answerVotes = 0;
let votesText = "";
// Votes are hidden until I vote or the poll ends
if (ended || myVote !== undefined) {
if (showResults) {
answerVotes = votes.get(answer.id) ?? 0;
votesText = _t("%(count)s votes", { count: answerVotes });
}