Fix poll display

Polls now correctly display to connections, not users.
This commit is contained in:
Guangcong Luo 2015-12-14 17:22:41 -05:00
parent 13b2ba1622
commit fab79a636a
2 changed files with 26 additions and 15 deletions

View File

@ -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"],

View File

@ -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) {