From 7f8d5e9dce22080f6ec92beafca70bff6ad25180 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 17 Feb 2023 11:51:27 +1300 Subject: [PATCH 1/4] add decryption error message to MPollBody --- src/components/views/messages/MPollBody.tsx | 6 +++++- src/i18n/strings/en_EN.json | 1 + src/utils/poll/countPollDecryptionFailures.ts | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/utils/poll/countPollDecryptionFailures.ts diff --git a/src/components/views/messages/MPollBody.tsx b/src/components/views/messages/MPollBody.tsx index c65a0de418e..d266281ad5b 100644 --- a/src/components/views/messages/MPollBody.tsx +++ b/src/components/views/messages/MPollBody.tsx @@ -182,12 +182,14 @@ export default class MPollBody extends React.Component { private addListeners(): void { this.state.poll?.on(PollEvent.Responses, this.onResponsesChange); this.state.poll?.on(PollEvent.End, this.onRelationsChange); + this.state.poll?.on(PollEvent.UndecryptableRelations, this.render.bind(this)); } private removeListeners(): void { if (this.state.poll) { this.state.poll.off(PollEvent.Responses, this.onResponsesChange); 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 { const showResults = poll.isEnded || (disclosed && myVote !== undefined); 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 }); } else if (!disclosed) { totalText = _t("Results will be visible when the poll is ended"); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 8cdb69d5852..ae0ac846cf5 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2412,6 +2412,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.", "Vote not registered": "Vote not registered", "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|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", diff --git a/src/utils/poll/countPollDecryptionFailures.ts b/src/utils/poll/countPollDecryptionFailures.ts new file mode 100644 index 00000000000..1dd0c656a50 --- /dev/null +++ b/src/utils/poll/countPollDecryptionFailures.ts @@ -0,0 +1,20 @@ +/* +Copyright 2023 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { Relations } from "matrix-js-sdk/src/models/relations"; + +export const countPollDecryptionFailures = (responseRelations: Relations): number => + responseRelations.getRelations().filter((relationEvent) => relationEvent.isDecryptionFailure()).length; From cf2a57638f5a5500baa6389b3404aeead5df9b3f Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 17 Feb 2023 13:36:22 +1300 Subject: [PATCH 2/4] test poll undecryptable message --- test/components/views/messages/MPollBody-test.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/components/views/messages/MPollBody-test.tsx b/test/components/views/messages/MPollBody-test.tsx index 33e6e1c062c..91f43d6c140 100644 --- a/test/components/views/messages/MPollBody-test.tsx +++ b/test/components/views/messages/MPollBody-test.tsx @@ -770,6 +770,20 @@ describe("MPollBody", () => { 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 () => { const votes = [ responseEvent("@a:example.com", "pizza", 12), From 50f8ee5fa858c3b5adff562182b69a34c2e02f40 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Fri, 17 Feb 2023 13:46:52 +1300 Subject: [PATCH 3/4] tidy + ling --- test/components/views/messages/MPollBody-test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/components/views/messages/MPollBody-test.tsx b/test/components/views/messages/MPollBody-test.tsx index 91f43d6c140..7f1d7e08958 100644 --- a/test/components/views/messages/MPollBody-test.tsx +++ b/test/components/views/messages/MPollBody-test.tsx @@ -779,7 +779,7 @@ describe("MPollBody", () => { responseEvent("@qr:example.com", "italian", 16), ]; - jest.spyOn(votes[1], 'isDecryptionFailure').mockReturnValue(true); + 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(); }); From 659ac5d4abee05c64aea6fb93bef9eaf4f9850a3 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 20 Feb 2023 10:39:55 +1300 Subject: [PATCH 4/4] remove unused file --- src/utils/poll/countPollDecryptionFailures.ts | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/utils/poll/countPollDecryptionFailures.ts diff --git a/src/utils/poll/countPollDecryptionFailures.ts b/src/utils/poll/countPollDecryptionFailures.ts deleted file mode 100644 index 1dd0c656a50..00000000000 --- a/src/utils/poll/countPollDecryptionFailures.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2023 The Matrix.org Foundation C.I.C. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -import { Relations } from "matrix-js-sdk/src/models/relations"; - -export const countPollDecryptionFailures = (responseRelations: Relations): number => - responseRelations.getRelations().filter((relationEvent) => relationEvent.isDecryptionFailure()).length;