login: even more cleanup

This commit is contained in:
John Cote 2019-11-30 21:14:42 -05:00
parent 058f66948d
commit b0acb2701d

View file

@ -242,11 +242,13 @@ class GetAvatarsOperation(AvatarOperation):
self.pendingAvatars = None
self.avatarFields = None
def start(self):
self.setCallback(self.__handleQueryAvatars)
def start(self, setCallback=True):
if setCallback:
self.setCallback(self._handleQueryAvatars)
AvatarOperation.start(self)
def __handleQueryAvatars(self):
def _handleQueryAvatars(self):
self.pendingAvatars = set()
self.avatarFields = {}
for avId in self.avList:
@ -535,32 +537,16 @@ class AcknowledgeNameOperation(AvatarOperation):
del self.loginManager.account2operation[self.sender]
class RemoveAvatarOperation:
class RemoveAvatarOperation(GetAvatarsOperation):
def __init__(self, loginManager, sender):
self.loginManager = loginManager
self.sender = sender
self.account = None
self.avList = []
self.pendingAvatars = None
self.avatarFields = None
GetAvatarsOperation.__init__(self, loginManager, sender)
self.avId = None
def start(self, avId):
self.avId = avId
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.sender,
self.__handleAccountRetrieved)
def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# TODO: Kill the connection
return
self.account = fields
self.avList = self.account['ACCOUNT_AV_SET']
self.avList = self.avList[:6]
self.avList += [0] * (6 - len(self.avList))
self.__handleRemoveAvatar()
self.setCallback(self.__handleRemoveAvatar)
GetAvatarsOperation.start(self, False)
def __handleRemoveAvatar(self):
if self.avId not in self.avList:
@ -591,83 +577,19 @@ class RemoveAvatarOperation:
# TODO: Kill the connection
return
self.__handleQueryAvatars()
def __handleQueryAvatars(self):
self.pendingAvatars = set()
self.avatarFields = {}
for avId in self.avList:
if avId:
self.pendingAvatars.add(avId)
def response(dclass, fields, avId=avId):
if dclass != self.loginManager.air.dclassesByName['DistributedToonUD']:
# TODO: Kill the connection
return
self.avatarFields[avId] = fields
self.pendingAvatars.remove(avId)
if not self.pendingAvatars:
self.__handleSendAvatars()
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, avId, response)
if not self.pendingAvatars:
self.__handleSendAvatars()
def __handleSendAvatars(self):
potentialAvatars = []
for avId, fields in self.avatarFields.items():
index = self.avList.index(avId)
wishNameState = fields.get('WishNameState', [''])[0]
name = fields['setName'][0]
nameState = 0
if wishNameState == 'OPEN':
nameState = 1
elif wishNameState == 'PENDING':
nameState = 2
elif wishNameState == 'APPROVED':
nameState = 3
name = fields['WishName'][0]
elif wishNameState == 'REJECTED':
nameState = 4
elif wishNameState == 'LOCKED':
nameState = 0
else:
# unknown name state.
nameState = 0
potentialAvatars.append([avId, name, fields['setDNAString'][0], index, nameState])
self.loginManager.sendUpdateToAccountId(self.sender, 'avatarListResponse', [potentialAvatars])
del self.loginManager.account2operation[self.sender]
self._handleQueryAvatars()
class LoadAvatarOperation:
class LoadAvatarOperation(AvatarOperation):
def __init__(self, loginManager, sender):
self.loginManager = loginManager
self.sender = sender
AvatarOperation.__init__(self, loginManager, sender)
self.avId = None
def start(self, avId):
self.avId = avId
self.__handleRetrieveAccount()
def __handleRetrieveAccount(self):
self.loginManager.air.dbInterface.queryObject(self.loginManager.air.dbId, self.sender,
self.__handleAccountRetrieved)
def __handleAccountRetrieved(self, dclass, fields):
if dclass != self.loginManager.air.dclassesByName['AstronAccountUD']:
# TODO: Kill the connection
return
self.account = fields
self.avList = self.account['ACCOUNT_AV_SET']
self.avList = self.avList[:6]
self.avList += [0] * (6 - len(self.avList))
self.__handleGetTargetAvatar()
self.setCallback(self.__handleGetTargetAvatar)
AvatarOperation.start(self)
def __handleGetTargetAvatar(self):
if self.avId not in self.avList: