# HG changeset patch # User Goffi # Date 1396261460 -7200 # Node ID 4a577b170809885ee23a2818e9722936e6ecb59c # Parent 91836a647515f4eb60c780a2fd08dd19b7b52e96 plugin xep-0115: caps optimisation diff -r 91836a647515 -r 4a577b170809 src/core/xmpp.py --- a/src/core/xmpp.py Mon Mar 31 12:23:13 2014 +0200 +++ b/src/core/xmpp.py Mon Mar 31 12:24:20 2014 +0200 @@ -286,7 +286,7 @@ self.host = host def send(self, obj): - if not self.host.trigger.point("Presence send", obj): + if not self.host.trigger.point("Presence send", self.parent, obj): return super(SatPresenceProtocol, self).send(obj) diff -r 91836a647515 -r 4a577b170809 src/plugins/plugin_xep_0115.py --- a/src/plugins/plugin_xep_0115.py Mon Mar 31 12:23:13 2014 +0200 +++ b/src/plugins/plugin_xep_0115.py Mon Mar 31 12:24:20 2014 +0200 @@ -33,6 +33,7 @@ PRESENCE = '/presence' NS_ENTITY_CAPABILITY = 'http://jabber.org/protocol/caps' +NS_CAPS_OPTIMIZE = 'http://jabber.org/protocol/caps#optimize' CAPABILITY_UPDATE = PRESENCE + '/c[@xmlns="' + NS_ENTITY_CAPABILITY + '"]' PLUGIN_INFO = { @@ -61,11 +62,25 @@ def _checkHash(self, disco_d, profile): if XEP_0115.cap_hash is None: + disco_d.addCallback(lambda dummy: self.host.hasFeature(NS_CAPS_OPTIMIZE, profile_key=profile)) + def updateOptimize(optimize): + client = self.host.getClient(profile) + client.caps_optimize = optimize + if optimize: + info(_("Caps optimisation enabled")) + client.caps_sent = False + else: + warning(_("Caps optimisation not available")) + disco_d.addCallback(updateOptimize) disco_d.addCallback(lambda dummy: self.recalculateHash(profile)) return True - def _presenceTrigger(self, obj): + def _presenceTrigger(self, client, obj): if XEP_0115.cap_hash is not None: + if client.caps_optimize: + if client.caps_sent: + return True + client.caps_sent = True obj.addChild(XEP_0115.c_elt) return True @@ -82,6 +97,8 @@ c_elt['ver'] = cap_hash XEP_0115.cap_hash = cap_hash XEP_0115.c_elt = c_elt + if client.caps_optimize: + client.caps_sent = False if cap_hash not in self.host.memory.disco.hashes: self.host.memory.disco.hashes[cap_hash] = disco_infos self.host.memory.updateEntityData(client.jid, C.ENTITY_CAP_HASH, cap_hash, profile) @@ -99,7 +116,7 @@ self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update) def getDiscoInfo(self, requestor, target, nodeIdentifier=''): - return [disco.DiscoFeature(NS_ENTITY_CAPABILITY)] + return [disco.DiscoFeature(NS_ENTITY_CAPABILITY), disco.DiscoFeature(NS_CAPS_OPTIMIZE)] def getDiscoItems(self, requestor, target, nodeIdentifier=''): return []