Mercurial > libervia-backend
changeset 953:4a577b170809
plugin xep-0115: caps optimisation
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Mar 2014 12:24:20 +0200 |
parents | 91836a647515 |
children | 5925c9ebfcd2 |
files | src/core/xmpp.py src/plugins/plugin_xep_0115.py |
diffstat | 2 files changed, 20 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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 []