From c0f53629e5ccb9a993172682fdeb08fc1290f979 Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 25 Nov 2015 23:19:36 +0100 Subject: [PATCH] core: avoid to send presence unavailable signal when it's not necessary --- src/core/xmpp.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/xmpp.py b/src/core/xmpp.py index 357e02f6..1ebfd84c 100644 --- a/src/core/xmpp.py +++ b/src/core/xmpp.py @@ -392,10 +392,18 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol): if not self.host.trigger.point("presenceReceived", entity, "unavailable", 0, statuses, self.parent.profile): return - self.host.memory.setPresenceStatus(entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile) - # now it's time to notify frontends - self.host.bridge.presenceUpdate(entity.full(), "unavailable", 0, statuses, self.parent.profile) + # if the entity is not known yet in this session or is already unavailable, there is no need to send an unavailable signal + try: + presence = self.host.memory.getEntityDatum(entity, "presence", self.parent.profile) + except KeyError: + # the entity has not been seen yet in this session + pass + else: + if presence.show != C.PRESENCE_UNAVAILABLE: + self.host.bridge.presenceUpdate(entity.full(), C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile) + + self.host.memory.setPresenceStatus(entity, C.PRESENCE_UNAVAILABLE, 0, statuses, self.parent.profile) def available(self, entity=None, show=None, statuses=None, priority=None): """Set a presence and statuses.