comparison src/core/xmpp.py @ 1398:f8ecce11a0bc

core (xmmp): keep the roster groups cache synchronised + fixes a log.warning
author souliane <souliane@mailoo.org>
date Wed, 01 Apr 2015 23:56:32 +0200
parents 069ad98b360d
children 3265a2639182
comparison
equal deleted inserted replaced
1397:96dd0ae1a850 1398:f8ecce11a0bc
180 self._jids = None # map from jids to RosterItem: key=jid value=RosterItem 180 self._jids = None # map from jids to RosterItem: key=jid value=RosterItem
181 181
182 def rosterCb(self, roster): 182 def rosterCb(self, roster):
183 assert roster is not None # FIXME: must be managed with roster versioning 183 assert roster is not None # FIXME: must be managed with roster versioning
184 self._jids = roster 184 self._jids = roster
185 for roster_item in roster.itervalues(): 185 for item in roster.itervalues():
186 self._registerItem(roster_item) 186 if not item.subscriptionTo and not item.subscriptionFrom and not item.ask:
187 #XXX: current behaviour: we don't want contact in our roster list
188 # if there is no presence subscription
189 # may change in the future
190 self.removeItem(item.jid) # FIXME: to be checked
191 else:
192 self._registerItem(item)
187 193
188 def _registerItem(self, item): 194 def _registerItem(self, item):
189 """Register item in local cache 195 """Register item in local cache
190 196
191 item must be already registered in self._jids before this method is called 197 item must be already registered in self._jids before this method is called
192 @param item (RosterIem): item added 198 @param item (RosterIem): item added
193 """ 199 """
194 log.debug(u"registering item: {}".format(item.jid.full())) 200 log.debug(u"registering item: {}".format(item.jid.full()))
195 if item.entity.resource: 201 if item.entity.resource:
196 log.warning(u"Received a roster item with a resource, this is not common but not restricted by RFC 6121, this case may be not well tested.") 202 log.warning(u"Received a roster item with a resource, this is not common but not restricted by RFC 6121, this case may be not well tested.")
197 if not item.subscriptionTo and not item.subscriptionFrom and not item.ask:
198 #XXX: current behaviour: we don't want contact in our roster list
199 # if there is no presence subscription
200 # may change in the future
201 self.removeItem(item.jid) # FIXME: to be checked
202 return
203 if not item.subscriptionTo: 203 if not item.subscriptionTo:
204 if not item.subscriptionFrom: 204 if not item.subscriptionFrom:
205 log.info(_(u"There's no subscription between you and [{}]!").format(item.jid.full())) 205 log.info(_(u"There's no subscription between you and [{}]!").format(item.jid.full()))
206 else: 206 else:
207 log.info(_(u"You are not subscribed to [{}]!").format(item.jid.full())) 207 log.info(_(u"You are not subscribed to [{}]!").format(item.jid.full()))
238 238
239 def setReceived(self, request): 239 def setReceived(self, request):
240 #TODO: implement roster versioning (cf RFC 6121 §2.6) 240 #TODO: implement roster versioning (cf RFC 6121 §2.6)
241 item = request.item 241 item = request.item
242 self._jids[item.entity] = item 242 self._jids[item.entity] = item
243 self._registerItem(item)
243 self.host.bridge.newContact(item.jid.full(), self.getAttributes(item), item.groups, self.parent.profile) 244 self.host.bridge.newContact(item.jid.full(), self.getAttributes(item), item.groups, self.parent.profile)
244 245
245 def removeReceived(self, request): 246 def removeReceived(self, request):
246 entity = request.item.entity 247 entity = request.item.entity
247 log.info(u"removing %s from roster list" % entity.full()) 248 log.info(u"removing %s from roster list" % entity.full())
257 jids_set = self._groups[group] 258 jids_set = self._groups[group]
258 jids_set.remove(entity) 259 jids_set.remove(entity)
259 if not jids_set: 260 if not jids_set:
260 del self._groups[group] 261 del self._groups[group]
261 except KeyError: 262 except KeyError:
262 log.warning("there is not cache for the group [%(groups)s] of the removed roster item [%(jid)s]" % 263 log.warning("there is no cache for the group [%(group)s] of the removed roster item [%(jid)s]" %
263 {"group": group, "jid": entity}) 264 {"group": group, "jid": entity})
264 265
265 # then we send the bridge signal 266 # then we send the bridge signal
266 self.host.bridge.contactDeleted(entity.full(), self.parent.profile) 267 self.host.bridge.contactDeleted(entity.full(), self.parent.profile)
267 268
268 def getGroups(self): 269 def getGroups(self):