def sync(self): if self.__isBWRosterReceived and self.client().isConnected(): g_logOutput.debug(CLIENT_LOG_AREA.SYNC, 'Syncing XMPP rosters from BW') domain = g_settings.server.XMPP.domain contacts = set() for user in self.usersStorage.getList(_BWRosterFindCriteria()): jid = ContactBareJID() jid.setNode(user.getID()) jid.setDomain(domain) contacts.add(jid) if user.isCurrentPlayer(): self.xmppRoster[jid].name = user.getName() continue groups = self.__getBWRosterGroups(user) if self.xmppRoster.hasItem(jid): if GROUPS_SYNC_ENABLED and groups ^ self.xmppRoster[jid].groups: self.__setContactToXmppRoster(jid, user.getName(), groups) if self.xmppRoster[jid].subscriptionTo == SUBSCRIPTION.OFF: self.__setSubscribeTo(jid) else: self.__addContactToXmppRoster(jid, user.getName(), groups) toRemove = set(self.xmppRoster.keys()).difference(contacts) for jid in toRemove: contact = self.xmppRoster[jid] if contact.subscriptionFrom != SUBSCRIPTION.OFF: if contact.subscriptionTo == SUBSCRIPTION.ON: self.__removeSubscribeTo(jid) else: self.__removeContactFromXmppRoster(jid)
def __me_onRosterUpdate(self, actionIdx, user): groups = self.__getBWRosterGroups(user) databaseID = user.getID() g_logOutput.debug(CLIENT_LOG_AREA.SYNC, 'BW roster update', groups, user) jid = ContactBareJID() jid.setNode(databaseID) jid.setDomain(g_settings.server.XMPP.domain) hasItem = self.xmppRoster.hasItem(jid) if len(groups): if hasItem: if GROUPS_SYNC_ENABLED and groups ^ self.xmppRoster[jid].groups: self.__setContactToXmppRoster(jid, user.getName(), groups) self.__setSubscribeTo(jid) else: self.__addContactToXmppRoster(jid, user.getName(), groups) elif hasItem: self.__removeSubscribeTo(jid) if actionIdx == USER_ROSTER_ACTION.RemoveFromFriend and g_settings.server.useToShowOnline(PROTO_TYPE.XMPP) and not self.usersStorage.isClanMember(databaseID): user.update(isOnline=False)