plugin xep-0115: caps optimisation
This commit is contained in:
parent
c6884f14d5
commit
e488c674a9
2 changed files with 20 additions and 3 deletions
|
|
@ -286,7 +286,7 @@ class SatPresenceProtocol(xmppim.PresenceClientProtocol):
|
|||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ except ImportError:
|
|||
|
||||
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 @@ class XEP_0115(object):
|
|||
|
||||
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 @@ class XEP_0115(object):
|
|||
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 @@ class XEP_0115_handler(XMPPHandler):
|
|||
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 []
|
||||
|
|
|
|||
Loading…
Reference in a new issue