From 285ff3bfbdc0d96a3ac7cf6c635cb26ee7dfbb80 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Tue, 11 Dec 2018 15:00:28 +0200 Subject: [PATCH] FIX: Show every voter only once. (#6746) Each voter is represented by an object and Set does not properly check for equality. --- .../assets/javascripts/widgets/discourse-poll.js.es6 | 9 ++++++++- .../poll/test/javascripts/acceptance/polls-test.js.es6 | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 index d84ba4b21af..88195905657 100644 --- a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 +++ b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 @@ -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(); }); diff --git a/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 b/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 index 4ae448bc0aa..1f4dbf4f5b1 100644 --- a/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 +++ b/plugins/poll/test/javascripts/acceptance/polls-test.js.es6 @@ -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" ); });