changeset 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 373ce871b0f3
children 1ed269c5f295
files src/core/xmpp.py
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/xmpp.py	Wed Nov 25 21:41:15 2015 +0100
+++ b/src/core/xmpp.py	Wed Nov 25 23:19:36 2015 +0100
@@ -392,10 +392,18 @@
         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
+        # 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)
 
-        # now it's time to notify frontends
-        self.host.bridge.presenceUpdate(entity.full(), "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.