From fab79a636a1a71363ed62cf543bba095a22f65e8 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Mon, 14 Dec 2015 17:22:41 -0500 Subject: [PATCH] Fix poll display Polls now correctly display to connections, not users. --- chat-plugins/poll.js | 39 +++++++++++++++++++++++++-------------- rooms.js | 2 +- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/chat-plugins/poll.js b/chat-plugins/poll.js index 94ce5c74a2..4519ffd21f 100644 --- a/chat-plugins/poll.js +++ b/chat-plugins/poll.js @@ -106,7 +106,7 @@ class Poll { } } - display(user, broadcast) { + display() { let votes = this.generateVotes(); let results = []; @@ -115,16 +115,8 @@ class Poll { results.push(this.generateResults(false, i)); } - let target = {}; - - if (broadcast) { - target = this.room.users; - } else { - target[0] = user; - } - - for (let i in target) { - let thisUser = target[i]; + for (let i in this.room.users) { + let thisUser = this.room.users[i]; if (thisUser.userid in this.voters) { thisUser.sendTo(this.room, '|uhtml|poll' + this.room.pollNumber + '|' + results[this.voters[thisUser.userid]]); } else if (thisUser.latestIp in this.voterIps) { @@ -135,6 +127,21 @@ class Poll { } } + displayTo(user, connection) { + if (!connection) connection = user; + if (user.userid in this.voters) { + connection.sendTo(this.room, '|uhtml|poll' + this.room.pollNumber + '|' + this.generateResults(false, this.voters[user.userid])); + } else if (user.latestIp in this.voterIps) { + connection.sendTo(this.room, '|uhtml|poll' + this.room.pollNumber + '|' + this.generateResults(false, this.voterIps[user.latestIp])); + } else { + connection.sendTo(this.room, '|uhtml|poll' + this.room.pollNumber + '|' + this.generateVotes()); + } + } + + onConnect(user, connection) { + this.displayTo(user, connection); + } + end() { let results = this.generateResults(true); @@ -167,7 +174,7 @@ exports.commands = { } room.poll = new Poll(room, params[0], options); - room.poll.display(user, true); + room.poll.display(); this.logEntry("" + user.name + " used " + message); return this.privateModCommand("(A poll was started by " + user.name + ".)"); @@ -247,12 +254,16 @@ exports.commands = { endhelp: ["/poll end - Ends a poll and displays the results. Requires: % @ # & ~"], show: 'display', - display: function (target, room, user) { + display: function (target, room, user, connection) { if (!room.poll) return this.errorReply("There is no poll running in this room."); if (!this.canBroadcast()) return; room.update(); - room.poll.display(user, this.broadcasting); + if (this.broadcasting) { + room.poll.display(); + } else { + room.poll.displayTo(user, connection); + } }, displayhelp: ["/poll display - Displays the poll"], diff --git a/rooms.js b/rooms.js index a69ed78b22..e862077b0f 100644 --- a/rooms.js +++ b/rooms.js @@ -1613,7 +1613,7 @@ let ChatRoom = (function () { ChatRoom.prototype.onConnect = function (user, connection) { let userList = this.userList ? this.userList : this.getUserList(); this.sendUser(connection, '|init|chat\n|title|' + this.title + '\n' + userList + '\n' + this.getLogSlice(-100).join('\n') + this.getIntroMessage(user)); - if (this.poll) this.poll.display(user, false); + if (this.poll) this.poll.onConnect(user, connection); if (this.game && this.game.onConnect) this.game.onConnect(user, connection); }; ChatRoom.prototype.onJoin = function (user, connection) {