changeset 2543:60758de1c227

plugin XEP-0115: fixed caps initial check
author Goffi <goffi@goffi.org>
date Fri, 30 Mar 2018 17:51:32 +0200
parents 100563768196
children a64887289931
files src/core/xmpp.py src/plugins/plugin_xep_0115.py
diffstat 2 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/xmpp.py	Thu Mar 29 09:09:33 2018 +0200
+++ b/src/core/xmpp.py	Fri Mar 30 17:51:32 2018 +0200
@@ -190,7 +190,7 @@
         self._connected.addCallback(self._disconnectionCb)
         self._connected.addErrback(self._disconnectionEb)
 
-        log.info(_("********** [%s] CONNECTED **********") % self.profile)
+        log.info(_(u"********** [{profile}] CONNECTED **********").format(profile=self.profile))
         self.streamInitialized()
         self.host_app.bridge.connected(self.profile, unicode(self.jid))  # we send the signal to the clients
 
@@ -234,7 +234,7 @@
             self.host_app.bridge.disconnected(self.profile)  # we send the signal to the clients
             self._connected.callback(None)
             self.host_app.purgeEntity(self.profile)  # and we remove references to this client
-            log.info(_("********** [%s] DISCONNECTED **********") % self.profile)
+            log.info(_(u"********** [{profile}] DISCONNECTED **********").format(profile=self.profile))
         if not self.conn_deferred.called:
             # FIXME: real error is not gotten here (e.g. if jid is not know by Prosody,
             #        we should have the real error)
@@ -968,9 +968,10 @@
         self.host = host
 
     def send(self, obj):
-        if not self.host.trigger.point("Presence send", self.parent, obj):
+        presence_d = defer.succeed(None)
+        if not self.host.trigger.point("Presence send", self.parent, obj, presence_d):
             return
-        super(SatPresenceProtocol, self).send(obj)
+        presence_d.addCallback(lambda __: super(SatPresenceProtocol, self).send(obj))
 
     def availableReceived(self, entity, show=None, statuses=None, priority=0):
         log.debug(_(u"presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity': entity, C.PRESENCE_SHOW: show, C.PRESENCE_STATUSES: statuses, C.PRESENCE_PRIORITY: priority})
--- a/src/plugins/plugin_xep_0115.py	Thu Mar 29 09:09:33 2018 +0200
+++ b/src/plugins/plugin_xep_0115.py	Fri Mar 30 17:51:32 2018 +0200
@@ -56,14 +56,13 @@
     def __init__(self, host):
         log.info(_("Plugin XEP_0115 initialization"))
         self.host = host
-        host.trigger.add("Disco handled", self._checkHash)
         host.trigger.add("Presence send", self._presenceTrigger)
 
     def getHandler(self, client):
         return XEP_0115_handler(self, client.profile)
 
     @defer.inlineCallbacks
-    def profileConnected(self, client):
+    def _prepareCaps(self, client):
         # we have to calculate hash for client
         # because disco infos/identities may change between clients
 
@@ -96,12 +95,18 @@
             self.host.memory.disco.hashes[cap_hash] = disco_infos
             self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile)
 
-    def _presenceTrigger(self, client, obj):
+    def _presenceAddElt(self, client, obj):
         if client._caps_optimize:
             if client._caps_sent:
-                return True
+                return
             client.caps_sent = True
         obj.addChild(client._caps_elt)
+
+    def _presenceTrigger(self, client, obj, presence_d):
+        if not hasattr(client, "_caps_optimize"):
+            presence_d.addCallback(lambda __: self._prepareCaps(client))
+
+        presence_d.addCallback(lambda __: self._presenceAddElt(client, obj))
         return True