Don't send a poll response event if you are voting for your current c… (#7326)
This commit is contained in:
parent
a727961c43
commit
5554d7fdc1
2 changed files with 27 additions and 2 deletions
|
@ -223,10 +223,13 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
private selectOption(answerId: string) {
|
private selectOption(answerId: string) {
|
||||||
if (answerId === this.state.selected) {
|
if (this.isEnded()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.isEnded()) {
|
const userVotes = this.collectUserVotes();
|
||||||
|
const userId = this.context.getUserId();
|
||||||
|
const myVote = userVotes.get(userId)?.answers[0];
|
||||||
|
if (answerId === myVote) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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", () => {
|
it("sends several events when I click different options", () => {
|
||||||
const receivedEvents = [];
|
const receivedEvents = [];
|
||||||
MatrixClientPeg.matrixClient.sendEvent = (
|
MatrixClientPeg.matrixClient.sendEvent = (
|
||||||
|
|
Loading…
Reference in a new issue