From fedbf9f02c73fef08074e3cf8b8e4f4bb9848850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= Date: Wed, 9 Jul 2014 00:24:42 +1000 Subject: [PATCH] Batch tournament joins and leaves --- js/client-chat-tournament.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/js/client-chat-tournament.js b/js/client-chat-tournament.js index 1c3924001..15764ef14 100644 --- a/js/client-chat-tournament.js +++ b/js/client-chat-tournament.js @@ -138,6 +138,10 @@ this.updates = {}; this.savedBracketPosition = {}; + this.$lastJoinLeaveMessage = null; + this.batchedJoins = []; + this.batchedLeaves = []; + this.bracketPopup = null; this.savedPopoutBracketPosition = {}; @@ -242,11 +246,27 @@ break; case 'join': - this.room.$chat.append("
" + Tools.escapeHTML(data[0]) + " has joined the tournament
"); - break; - case 'leave': - this.room.$chat.append("
" + Tools.escapeHTML(data[0]) + " has left the tournament
"); + if (this.$lastJoinLeaveMessage && !this.$lastJoinLeaveMessage.is(this.room.$chat.children().last())) { + this.$lastJoinLeaveMessage = null; + this.batchedJoins = []; + this.batchedLeaves = []; + } + if (!this.$lastJoinLeaveMessage) { + this.$lastJoinLeaveMessage = $('
'); + this.room.$chat.append(this.$lastJoinLeaveMessage); + } + + (cmd === 'join' ? this.batchedJoins : this.batchedLeaves).push(data[0]); + + var message = []; + var joins = this.batchedJoins.slice(0, 5); + var leaves = this.batchedLeaves.slice(0, 5); + if (this.batchedJoins.length > 5) joins.push((this.batchedJoins.length - 5) + " others"); + if (this.batchedLeaves.length > 5) leaves.push((this.batchedLeaves.length - 5) + " others"); + if (joins.length > 0) message.push(arrayToPhrase(joins) + " joined the tournament"); + if (leaves.length > 0) message.push(arrayToPhrase(leaves) + " left the tournament"); + this.$lastJoinLeaveMessage.text(message.join("; ") + "."); break; case 'start':