FIX: Show every voter only once. (#6746)

Each voter is represented by an object and Set does not properly check for equality.
This commit is contained in:
Bianca Nenciu 2018-12-11 15:00:28 +02:00 committed by Régis Hanol
parent 2ee2e5c981
commit 285ff3bfbd
2 changed files with 9 additions and 2 deletions

View File

@ -117,7 +117,14 @@ createWidget("discourse-poll-voters", {
attrs.pollType === "number"
? result.voters
: result.voters[attrs.optionId];
state.voters = [...new Set([...state.voters, ...newVoters])];
const existingVoters = new Set(state.voters.map(voter => voter.username));
newVoters.forEach(voter => {
if (!existingVoters.has(voter.username)) {
existingVoters.add(voter.username);
state.voters.push(voter);
}
});
this.scheduleRerender();
});

View File

@ -1344,7 +1344,7 @@ test("Public poll", async assert => {
assert.equal(
find(".poll-voters:first li").length,
50,
26,
"it should display the right number of voters"
);
});