comparison src/core/xmpp.py @ 1685:43a127b6a4f2

core: avoid to send presence unavailable signal when it's not necessary
author Goffi <goffi@goffi.org>
date Wed, 25 Nov 2015 23:19:36 +0100
parents 5b24d6bf5d15
children 772c8edd1057
comparison
equal deleted inserted replaced
1684:373ce871b0f3 1685:43a127b6a4f2
390 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None) 390 statuses[C.PRESENCE_STATUSES_DEFAULT] = statuses.pop(None)
391 391
392 if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile): 392 if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile):
393 return 393 return
394 394
395 # now it's time to notify frontends
396 # if the entity is not known yet in this session or is already unavailable, there is no need to send an unavailable signal
397 try:
398 presence = self.host.memory.getEntityDatum(entity, "presence", self.parent.profile)
399 except KeyError:
400 # the entity has not been seen yet in this session
401 pass
402 else:
403 if presence.show != C.PRESENCE_UNAVAILABLE:
404 self.host.bridge.presenceUpdate(entity.full(), C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile)
405
395 self.host.memory.setPresenceStatus(entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile) 406 self.host.memory.setPresenceStatus(entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile)
396
397 # now it's time to notify frontends
398 self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile)
399 407
400 def available(self, entity=None, show=None, statuses=None, priority=None): 408 def available(self, entity=None, show=None, statuses=None, priority=None):
401 """Set a presence and statuses. 409 """Set a presence and statuses.
402 410
403 @param entity (jid.JID): entity 411 @param entity (jid.JID): entity