def __onRosterReceived(self, chatAction): self.__isRosterReceivedOnce = True if self.__replayCtrl is None: import BattleReplay self.__replayCtrl = BattleReplay.g_replayCtrl if self.__replayCtrl.isRecording: self.__replayCtrl.cancelSaveCurrMessage() data = dict(chatAction) result = data.get('data', []) flags = data.get('flags', 0) if not flags: self.usersStorage.removeTags({_TAG.FRIEND, _TAG.IGNORED, _TAG.MUTED}, ProtoFindCriteria(PROTO_TYPE.BW)) getter = self.usersStorage.getUser setter = self.usersStorage.setUser for userData in result: dbID, name, roster = userData[:3] user = getter(dbID, PROTO_TYPE.BW) tags = _getTagsByRoster(roster) if user: user.addTags(tags) else: setter(entities.BWUserEntity(dbID, name=name, tags=tags)) g_messengerEvents.users.onUsersListReceived({_TAG.FRIEND, _TAG.IGNORED, _TAG.MUTED}) return
def __onUserRosterChange(self, chatAction, actionID, include, exclude = None): userData = [-1, 'Unknown', 0] if chatAction.has_key('data'): userData = list(chatAction['data']) dbID, name = userData[:2] user = self.usersStorage.getUser(dbID, PROTO_TYPE.BW) if user: tags = user.getTags() tags = tags.union(include) if exclude: tags = tags.difference(exclude) user.update(tags=tags) else: user = entities.BWUserEntity(dbID, name=name, tags=include) self.usersStorage.setUser(user) g_messengerEvents.users.onUserActionReceived(actionID, user)
def __onRosterReceived(self, chatAction): self.__isRosterReceivedOnce = True data = dict(chatAction) result = data.get('data', []) flags = data.get('flags', 0) if not flags: self.usersStorage.removeTags({_TAG.FRIEND, _TAG.IGNORED, _TAG.MUTED}, ProtoFindCriteria(PROTO_TYPE.BW)) getter = self.usersStorage.getUser setter = self.usersStorage.setUser for userData in result: dbID, name, roster = userData[:3] user = getter(dbID, PROTO_TYPE.BW) tags = _getTagsByRoster(roster) if user: user.addTags(tags) setter(entities.BWUserEntity(dbID, name=name, tags=tags)) g_messengerEvents.users.onUsersListReceived({_TAG.FRIEND, _TAG.IGNORED, _TAG.MUTED})
def __onRequestUsersRoster(self, chatAction): if self.__replayCtrl is None: import BattleReplay self.__replayCtrl = BattleReplay.g_replayCtrl if self.__replayCtrl.isRecording: self.__replayCtrl.cancelSaveCurrMessage() data = dict(chatAction) result = data.get('data', []) flags = data.get('flags', 0) if not flags: self.usersStorage._clearRosters() for userData in result: dbID, name, roster = userData[:3] user = self.usersStorage.getUser(dbID) if user: user.update(name=name, roster=roster) else: self.usersStorage.addUser( entities.BWUserEntity(dbID, name=name, roster=roster)) g_messengerEvents.users.onUsersRosterReceived() return
def __onFindUsers(self, chatAction): chatActionDict = dict(chatAction) result = chatActionDict.get('data', []) requestID = chatActionDict.get('requestID', []) users = [] for userData in result: name, dbID, isOnline, clanAbbrev = userData[:4] dbID = long(dbID) if not len(name): continue received = entities.BWUserEntity(dbID, name=name, isOnline=isOnline, clanAbbrev=clanAbbrev) user = self.usersStorage.getUser(dbID) if user: if user.isCurrentPlayer(): received = user else: received.update(roster=user.getRoster()) users.append(received) self.onFindUsersComplete(requestID, users)
def __onUserRosterChange(self, chatAction, actionIdx, include, exclude=None): userData = [-1, 'Unknown', 0] if chatAction.has_key('data'): userData = list(chatAction['data']) dbID, name = userData[:2] roster = include user = self.usersStorage.getUser(dbID) if user is not None: roster = user.getRoster() if roster & include is 0: roster |= include if exclude and roster & exclude is not 0: roster ^= exclude user.update(roster=roster) else: user = entities.BWUserEntity(dbID, name=name, roster=roster) self.usersStorage.addUser(user) g_messengerEvents.users.onUserRosterChanged(actionIdx, user) return