Support "closed" polls whose votes are not visible until they are ended (#7842)
This commit is contained in:
parent
eca64d776a
commit
f1e1b7be86
8 changed files with 248 additions and 11 deletions
|
@ -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 });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue