plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile
This commit is contained in:
parent
359b3a1b43
commit
c56d3fc759
4 changed files with 10 additions and 11 deletions
|
|
@ -217,7 +217,7 @@ class Const(object):
|
||||||
# PubSub
|
# PubSub
|
||||||
PS_PUBLISH = "publish"
|
PS_PUBLISH = "publish"
|
||||||
PS_RETRACT = "retract" # used for items
|
PS_RETRACT = "retract" # used for items
|
||||||
PS_DELETE = "delete" #used for nodes
|
PS_DELETE = "delete" # used for nodes
|
||||||
PS_ITEM = "item"
|
PS_ITEM = "item"
|
||||||
PS_ITEMS = "items" # Can contain publish and retract items
|
PS_ITEMS = "items" # Can contain publish and retract items
|
||||||
PS_EVENTS = (PS_ITEMS, PS_DELETE)
|
PS_EVENTS = (PS_ITEMS, PS_DELETE)
|
||||||
|
|
|
||||||
|
|
@ -188,9 +188,9 @@ class XEP_0060(object):
|
||||||
@param node(unicode): node to monitor
|
@param node(unicode): node to monitor
|
||||||
all node *prefixed* with this one will be triggered
|
all node *prefixed* with this one will be triggered
|
||||||
@param **kwargs: method(s) to call when the node is found
|
@param **kwargs: method(s) to call when the node is found
|
||||||
the methode must be named after PubSub constants in lower case
|
the method must be named after PubSub constants in lower case
|
||||||
and suffixed with "_cb"
|
and suffixed with "_cb"
|
||||||
e.g.: "publish_cb" for C.PS_PUBLISH, "delete_cb" for C.PS_DELETE
|
e.g.: "items_cb" for C.PS_ITEMS, "delete_cb" for C.PS_DELETE
|
||||||
"""
|
"""
|
||||||
assert node is not None
|
assert node is not None
|
||||||
assert kwargs
|
assert kwargs
|
||||||
|
|
@ -792,12 +792,12 @@ class SatPubSubClient(rsm.PubSubClient):
|
||||||
def itemsReceived(self, event):
|
def itemsReceived(self, event):
|
||||||
log.debug(u"Pubsub items received")
|
log.debug(u"Pubsub items received")
|
||||||
for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS):
|
for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS):
|
||||||
callback(event, self.parent.profile)
|
callback(self.parent, event)
|
||||||
|
|
||||||
def deleteReceived(self, event):
|
def deleteReceived(self, event):
|
||||||
log.debug((u"Publish node deleted"))
|
log.debug((u"Publish node deleted"))
|
||||||
for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE):
|
for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_DELETE):
|
||||||
callback(event, self.parent.profile)
|
callback(self.parent, event)
|
||||||
|
|
||||||
def subscriptions(self, service, nodeIdentifier, sender=None):
|
def subscriptions(self, service, nodeIdentifier, sender=None):
|
||||||
"""Return the list of subscriptions to the given service and node.
|
"""Return the list of subscriptions to the given service and node.
|
||||||
|
|
|
||||||
|
|
@ -78,16 +78,15 @@ class XEP_0163(object):
|
||||||
self.pep_events.add(node)
|
self.pep_events.add(node)
|
||||||
if notify:
|
if notify:
|
||||||
self.pep_events.add(node + "+notify")
|
self.pep_events.add(node + "+notify")
|
||||||
def filterPEPEvent(itemsEvent, profile):
|
def filterPEPEvent(client, itemsEvent):
|
||||||
"""Ignore messages which are not coming from PEP (i.e. main server)
|
"""Ignore messages which are not coming from PEP (i.e. main server)
|
||||||
|
|
||||||
@param itemsEvent(pubsub.ItemsEvent): pubsub event
|
@param itemsEvent(pubsub.ItemsEvent): pubsub event
|
||||||
@param profile(unicode): %(doc_profile)s
|
|
||||||
"""
|
"""
|
||||||
if itemsEvent.sender.user or itemsEvent.sender.resource:
|
if itemsEvent.sender.user or itemsEvent.sender.resource:
|
||||||
log.debug("ignoring non PEP event from {} (profile={})".format(itemsEvent.sender.full(), profile))
|
log.debug("ignoring non PEP event from {} (profile={})".format(itemsEvent.sender.full(), client.profile))
|
||||||
return
|
return
|
||||||
in_callback(itemsEvent, profile)
|
in_callback(itemsEvent, client.profile)
|
||||||
|
|
||||||
self.host.plugins["XEP-0060"].addManagedNode(node, items_cb=filterPEPEvent)
|
self.host.plugins["XEP-0060"].addManagedNode(node, items_cb=filterPEPEvent)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,10 +112,10 @@ class XEP_0277(object):
|
||||||
|
|
||||||
## plugin management methods ##
|
## plugin management methods ##
|
||||||
|
|
||||||
def _itemsReceived(self, itemsEvent, profile):
|
def _itemsReceived(self, client, itemsEvent):
|
||||||
"""Callback which manage items notifications (publish + retract)"""
|
"""Callback which manage items notifications (publish + retract)"""
|
||||||
def manageItem(data, event):
|
def manageItem(data, event):
|
||||||
self.host.bridge.psEvent(C.PS_MICROBLOG, itemsEvent.sender.full(), itemsEvent.nodeIdentifier, event, data, profile)
|
self.host.bridge.psEvent(C.PS_MICROBLOG, itemsEvent.sender.full(), itemsEvent.nodeIdentifier, event, data, client.profile)
|
||||||
|
|
||||||
for item in itemsEvent.items:
|
for item in itemsEvent.items:
|
||||||
if item.name == C.PS_ITEM:
|
if item.name == C.PS_ITEM:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue