mirror of https://github.com/vector-im/riot-web
Polls: show warning about undecryptable relations (#10179)
* add decryption error message to MPollBody * test poll undecryptable message * tidy + ling * remove unused filepull/28788/head^2
parent
58b8df9868
commit
17bbd4eaac
|
@ -182,12 +182,14 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
|
||||||
private addListeners(): void {
|
private addListeners(): void {
|
||||||
this.state.poll?.on(PollEvent.Responses, this.onResponsesChange);
|
this.state.poll?.on(PollEvent.Responses, this.onResponsesChange);
|
||||||
this.state.poll?.on(PollEvent.End, this.onRelationsChange);
|
this.state.poll?.on(PollEvent.End, this.onRelationsChange);
|
||||||
|
this.state.poll?.on(PollEvent.UndecryptableRelations, this.render.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeListeners(): void {
|
private removeListeners(): void {
|
||||||
if (this.state.poll) {
|
if (this.state.poll) {
|
||||||
this.state.poll.off(PollEvent.Responses, this.onResponsesChange);
|
this.state.poll.off(PollEvent.Responses, this.onResponsesChange);
|
||||||
this.state.poll.off(PollEvent.End, this.onRelationsChange);
|
this.state.poll.off(PollEvent.End, this.onRelationsChange);
|
||||||
|
this.state.poll.off(PollEvent.UndecryptableRelations, this.render.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +299,9 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
|
||||||
const showResults = poll.isEnded || (disclosed && myVote !== undefined);
|
const showResults = poll.isEnded || (disclosed && myVote !== undefined);
|
||||||
|
|
||||||
let totalText: string;
|
let totalText: string;
|
||||||
if (poll.isEnded) {
|
if (showResults && poll.undecryptableRelationsCount) {
|
||||||
|
totalText = _t("Due to decryption errors, some votes may not be counted");
|
||||||
|
} else if (poll.isEnded) {
|
||||||
totalText = _t("Final result based on %(count)s votes", { count: totalVotes });
|
totalText = _t("Final result based on %(count)s votes", { count: totalVotes });
|
||||||
} else if (!disclosed) {
|
} else if (!disclosed) {
|
||||||
totalText = _t("Results will be visible when the poll is ended");
|
totalText = _t("Results will be visible when the poll is ended");
|
||||||
|
|
|
@ -2405,6 +2405,7 @@
|
||||||
"Sorry, you can't edit a poll after votes have been cast.": "Sorry, you can't edit a poll after votes have been cast.",
|
"Sorry, you can't edit a poll after votes have been cast.": "Sorry, you can't edit a poll after votes have been cast.",
|
||||||
"Vote not registered": "Vote not registered",
|
"Vote not registered": "Vote not registered",
|
||||||
"Sorry, your vote was not registered. Please try again.": "Sorry, your vote was not registered. Please try again.",
|
"Sorry, your vote was not registered. Please try again.": "Sorry, your vote was not registered. Please try again.",
|
||||||
|
"Due to decryption errors, some votes may not be counted": "Due to decryption errors, some votes may not be counted",
|
||||||
"Final result based on %(count)s votes|other": "Final result based on %(count)s votes",
|
"Final result based on %(count)s votes|other": "Final result based on %(count)s votes",
|
||||||
"Final result based on %(count)s votes|one": "Final result based on %(count)s vote",
|
"Final result based on %(count)s votes|one": "Final result based on %(count)s vote",
|
||||||
"Results will be visible when the poll is ended": "Results will be visible when the poll is ended",
|
"Results will be visible when the poll is ended": "Results will be visible when the poll is ended",
|
||||||
|
|
|
@ -765,6 +765,20 @@ describe("MPollBody", () => {
|
||||||
expect(container).toMatchSnapshot();
|
expect(container).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renders a warning message when poll has undecryptable relations", async () => {
|
||||||
|
const votes = [
|
||||||
|
responseEvent("@op:example.com", "pizza", 12),
|
||||||
|
responseEvent("@op:example.com", [], 13),
|
||||||
|
responseEvent("@op:example.com", "italian", 14),
|
||||||
|
responseEvent("@me:example.com", "wings", 15),
|
||||||
|
responseEvent("@qr:example.com", "italian", 16),
|
||||||
|
];
|
||||||
|
|
||||||
|
jest.spyOn(votes[1], "isDecryptionFailure").mockReturnValue(true);
|
||||||
|
const { getByText } = await newMPollBody(votes);
|
||||||
|
expect(getByText("Due to decryption errors, some votes may not be counted")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("renders a poll with local, non-local and invalid votes", async () => {
|
it("renders a poll with local, non-local and invalid votes", async () => {
|
||||||
const votes = [
|
const votes = [
|
||||||
responseEvent("@a:example.com", "pizza", 12),
|
responseEvent("@a:example.com", "pizza", 12),
|
||||||
|
|
Loading…
Reference in New Issue