From 5554d7fdc1ed6ee42b2748f9dac692560d7c4f1d Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Fri, 10 Dec 2021 12:36:53 +0000 Subject: [PATCH] =?UTF-8?q?Don't=20send=20a=20poll=20response=20event=20if?= =?UTF-8?q?=20you=20are=20voting=20for=20your=20current=20c=E2=80=A6=20(#7?= =?UTF-8?q?326)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/views/messages/MPollBody.tsx | 7 ++++-- .../views/messages/MPollBody-test.tsx | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/components/views/messages/MPollBody.tsx b/src/components/views/messages/MPollBody.tsx index 55c4b672bd..10f43938ed 100644 --- a/src/components/views/messages/MPollBody.tsx +++ b/src/components/views/messages/MPollBody.tsx @@ -223,10 +223,13 @@ export default class MPollBody extends React.Component { }; private selectOption(answerId: string) { - if (answerId === this.state.selected) { + if (this.isEnded()) { return; } - if (this.isEnded()) { + const userVotes = this.collectUserVotes(); + const userId = this.context.getUserId(); + const myVote = userVotes.get(userId)?.answers[0]; + if (answerId === myVote) { return; } diff --git a/test/components/views/messages/MPollBody-test.tsx b/test/components/views/messages/MPollBody-test.tsx index d57137c566..ff62c26c71 100644 --- a/test/components/views/messages/MPollBody-test.tsx +++ b/test/components/views/messages/MPollBody-test.tsx @@ -497,6 +497,28 @@ describe("MPollBody", () => { ]); }); + it("sends no vote event when I click what I already chose", () => { + const receivedEvents = []; + MatrixClientPeg.matrixClient.sendEvent = ( + roomId: string, + eventType: string, + content: IContent, + txnId?: string, + callback?: Callback, + ): Promise => { + receivedEvents.push( { roomId, eventType, content, txnId, callback } ); + return Promise.resolve({ "event_id": "fake_tracked_send_id" }); + }; + + const votes = [responseEvent("@me:example.com", "wings")]; + const body = newMPollBody(votes); + clickRadio(body, "wings"); + clickRadio(body, "wings"); + clickRadio(body, "wings"); + clickRadio(body, "wings"); + expect(receivedEvents).toEqual([]); + }); + it("sends several events when I click different options", () => { const receivedEvents = []; MatrixClientPeg.matrixClient.sendEvent = (