()
| 120 | } |
| 121 | |
| 122 | loadNames () { |
| 123 | // Only fetch the names for the userIDs we don't already have in @nameMap |
| 124 | let id, match, matches, session |
| 125 | let ids = [] |
| 126 | for (session of Array.from(this.sessions.models)) { |
| 127 | matches = this.statsFromSession(session).matches || [] |
| 128 | for (match of Array.from(matches)) { |
| 129 | id = match.opponents[0].userID |
| 130 | if (!id) { |
| 131 | console.error('Found bad opponent ID in malformed match:', match, 'from session', session) |
| 132 | continue |
| 133 | } |
| 134 | if (!this.nameMap[id]) { ids.push(id) } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | ids = _.uniq(ids) |
| 139 | if (!ids.length) { |
| 140 | if (this.renderedOnce) { this.render() } |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | const success = nameMap => { |
| 145 | if (this.destroyed) { return } |
| 146 | for (session of Array.from(this.sessions.models)) { |
| 147 | matches = this.statsFromSession(session).matches || [] |
| 148 | for (match of Array.from(matches)) { |
| 149 | const opponent = match.opponents[0] |
| 150 | if (this.nameMap[opponent.userID]) { continue } |
| 151 | const opponentUser = nameMap[opponent.userID] |
| 152 | let name = opponentUser != null ? opponentUser.fullName : undefined |
| 153 | if (name) { name = name.replace(/^Anonymous/, $.i18n.t('play.anonymous')) } |
| 154 | if (!name) { |
| 155 | ({ |
| 156 | name |
| 157 | } = opponent) |
| 158 | } |
| 159 | if (!name) { name = '<bad match data>' } |
| 160 | name = name.replace(/^AIAlgorithm_(.+)_$/, '$1') |
| 161 | name = name.replace(/^AIYouth_(.+)_$/, '$1') |
| 162 | if (name.length > 21) { |
| 163 | name = name.substr(0, 18) + '...' |
| 164 | } |
| 165 | this.nameMap[opponent.userID] = name |
| 166 | } |
| 167 | } |
| 168 | if (this.supermodel.finished() && this.renderedOnce) { return this.render() } |
| 169 | } |
| 170 | |
| 171 | const data = { ids } |
| 172 | if (this.options.league) { |
| 173 | data.leagueId = this.options.league.id |
| 174 | } |
| 175 | const userNamesRequest = this.supermodel.addRequestResource('user_names', { |
| 176 | url: '/db/user/-/getFullNames', |
| 177 | data, |
| 178 | method: 'POST', |
| 179 | success |
no test coverage detected