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

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

Each voter is represented by an object and Set does not properly check for equality.

From 285ff3bfbdc0d96a3ac7cf6c635cb26ee7dfbb80 Mon Sep 17 00:00:00 2001
From: Bianca Nenciu <nbianca@users.noreply.github.com>
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.

diff --git a/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6 b/plugins/poll/assets/javascripts/widgets/discourse-poll.js.es6
index d84ba4b..8819590 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 4ae448b..1f4dbf4 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"
   );
 });

GitHub