Fixed . Much less fragile naming of opponents on My Matches tab.

This commit is contained in:
Nick Winter 2015-02-12 08:50:45 -08:00
parent 3188ba15b8
commit a2a4303a83
3 changed files with 14 additions and 4 deletions

View file

@ -38,7 +38,17 @@ module.exports = class MyMatchesTabView extends CocoView
for session in @sessions.models
for match in session.get('matches') or []
opponent = match.opponents[0]
@nameMap[opponent.userID] ?= nameMap[opponent.userID]?.name ? '<bad match data>'
continue if @nameMap[opponent.userID]
opponentUser = nameMap[opponent.userID]
name = opponentUser?.name
name ||= opponentUser.firstName + ' ' + opponentUser.lastName if opponentUser?.firstName
name ||= "Anonymous #{opponent.userID.substr(18)}" if opponentUser
unless name
console.log 'found', nameMap[opponent.userID], 'for', opponent.userID, "http://codecombat.com/db/user/#{opponent.userID}"
name ||= '<bad match data>'
if name.length > 21
name = name.substr(0, 18) + '...'
@nameMap[opponent.userID] = name
@render() if @supermodel.finished()
userNamesRequest = @supermodel.addRequestResource 'user_names', {

View file

@ -232,9 +232,9 @@ module.exports = class Handler
ids = ids.split(',') if _.isString ids
ids = _.uniq ids
# HACK: levels loading thang types need the components returned as well
# Hack: levels loading thang types need the components returned as well.
# Need a way to specify a projection for a query.
project = {name:1, original:1, kind:1, components: 1}
project = {name: 1, original: 1, kind: 1, components: 1}
sort = {'version.major':-1, 'version.minor':-1}
makeFunc = (id) =>

View file

@ -159,7 +159,7 @@ UserHandler = class UserHandler extends Handler
getNamesByIDs: (req, res) ->
ids = req.query.ids or req.body.ids
returnWizard = req.query.wizard or req.body.wizard
properties = if returnWizard then 'name wizard' else 'name'
properties = if returnWizard then 'name wizard firstName lastName' else 'name firstName lastName'
@getPropertiesFromMultipleDocuments res, User, properties, ids
nameToID: (req, res, name) ->