Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 17bbd4e

Browse files
author
Kerry
authored
Polls: show warning about undecryptable relations (#10179)
* add decryption error message to MPollBody * test poll undecryptable message * tidy + ling * remove unused file
1 parent 58b8df9 commit 17bbd4e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/components/views/messages/MPollBody.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,14 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
182182
private addListeners(): void {
183183
this.state.poll?.on(PollEvent.Responses, this.onResponsesChange);
184184
this.state.poll?.on(PollEvent.End, this.onRelationsChange);
185+
this.state.poll?.on(PollEvent.UndecryptableRelations, this.render.bind(this));
185186
}
186187

187188
private removeListeners(): void {
188189
if (this.state.poll) {
189190
this.state.poll.off(PollEvent.Responses, this.onResponsesChange);
190191
this.state.poll.off(PollEvent.End, this.onRelationsChange);
192+
this.state.poll.off(PollEvent.UndecryptableRelations, this.render.bind(this));
191193
}
192194
}
193195

@@ -297,7 +299,9 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
297299
const showResults = poll.isEnded || (disclosed && myVote !== undefined);
298300

299301
let totalText: string;
300-
if (poll.isEnded) {
302+
if (showResults && poll.undecryptableRelationsCount) {
303+
totalText = _t("Due to decryption errors, some votes may not be counted");
304+
} else if (poll.isEnded) {
301305
totalText = _t("Final result based on %(count)s votes", { count: totalVotes });
302306
} else if (!disclosed) {
303307
totalText = _t("Results will be visible when the poll is ended");

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,7 @@
24052405
"Sorry, you can't edit a poll after votes have been cast.": "Sorry, you can't edit a poll after votes have been cast.",
24062406
"Vote not registered": "Vote not registered",
24072407
"Sorry, your vote was not registered. Please try again.": "Sorry, your vote was not registered. Please try again.",
2408+
"Due to decryption errors, some votes may not be counted": "Due to decryption errors, some votes may not be counted",
24082409
"Final result based on %(count)s votes|other": "Final result based on %(count)s votes",
24092410
"Final result based on %(count)s votes|one": "Final result based on %(count)s vote",
24102411
"Results will be visible when the poll is ended": "Results will be visible when the poll is ended",

test/components/views/messages/MPollBody-test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,20 @@ describe("MPollBody", () => {
765765
expect(container).toMatchSnapshot();
766766
});
767767

768+
it("renders a warning message when poll has undecryptable relations", async () => {
769+
const votes = [
770+
responseEvent("@op:example.com", "pizza", 12),
771+
responseEvent("@op:example.com", [], 13),
772+
responseEvent("@op:example.com", "italian", 14),
773+
responseEvent("@me:example.com", "wings", 15),
774+
responseEvent("@qr:example.com", "italian", 16),
775+
];
776+
777+
jest.spyOn(votes[1], "isDecryptionFailure").mockReturnValue(true);
778+
const { getByText } = await newMPollBody(votes);
779+
expect(getByText("Due to decryption errors, some votes may not be counted")).toBeInTheDocument();
780+
});
781+
768782
it("renders a poll with local, non-local and invalid votes", async () => {
769783
const votes = [
770784
responseEvent("@a:example.com", "pizza", 12),

0 commit comments

Comments
 (0)