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

Don't send a poll response event if you are voting for your current c… #7326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/components/views/messages/MPollBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
};

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;
}

Expand Down
22 changes: 22 additions & 0 deletions test/components/views/messages/MPollBody-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISendEventResponse> => {
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 = (
Expand Down