Mercurial > libervia-backend
diff src/core/xmpp.py @ 1427:1e833970b7f0
core (xmpp): update the cache for a contact group when a contact is removed from it
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 24 Apr 2015 14:57:09 +0200 |
parents | 614145ef6e60 |
children | 70abe871eac3 |
line wrap: on
line diff
--- a/src/core/xmpp.py Fri Apr 24 14:54:24 2015 +0200 +++ b/src/core/xmpp.py Fri Apr 24 14:57:09 2015 +0200 @@ -181,6 +181,7 @@ def rosterCb(self, roster): assert roster is not None # FIXME: must be managed with roster versioning + self._groups.clear() self._jids = roster for item in roster.itervalues(): if not item.subscriptionTo and not item.subscriptionFrom and not item.ask: @@ -239,6 +240,15 @@ def setReceived(self, request): #TODO: implement roster versioning (cf RFC 6121 ยง2.6) item = request.item + try: # update the cache for the groups the contact has been removed from + left_groups = set(self._jids[item.entity].groups).difference(item.groups) + for group in left_groups: + jids_set = self._groups[group] + jids_set.remove(item.entity) + if not jids_set: + del self._groups[group] + except KeyError: + pass # no previous item registration (or it's been cleared) self._jids[item.entity] = item self._registerItem(item) self.host.bridge.newContact(item.entity.full(), self.getAttributes(item), item.groups, self.parent.profile)