From c56d3fc7591cacecab56817879faf107c7af4e9a Mon Sep 17 00:00:00 2001 From: Goffi Date: Wed, 5 Jul 2017 15:04:43 +0200 Subject: [PATCH] plugin XEP-0060: addManagedNode callbacks now use client syntax instead of profile --- src/core/constants.py | 2 +- src/plugins/plugin_xep_0060.py | 8 ++++---- src/plugins/plugin_xep_0163.py | 7 +++---- src/plugins/plugin_xep_0277.py | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core/constants.py b/src/core/constants.py index 8c0495cc..eb949e59 100644 --- a/src/core/constants.py +++ b/src/core/constants.py @@ -217,7 +217,7 @@ class Const(object): # PubSub PS_PUBLISH = "publish" PS_RETRACT = "retract" # used for items - PS_DELETE = "delete" #used for nodes + PS_DELETE = "delete" # used for nodes PS_ITEM = "item" PS_ITEMS = "items" # Can contain publish and retract items PS_EVENTS = (PS_ITEMS, PS_DELETE) diff --git a/src/plugins/plugin_xep_0060.py b/src/plugins/plugin_xep_0060.py index 7b337c4a..d1455ee8 100755 --- a/src/plugins/plugin_xep_0060.py +++ b/src/plugins/plugin_xep_0060.py @@ -188,9 +188,9 @@ class XEP_0060(object): @param node(unicode): node to monitor all node *prefixed* with this one will be triggered @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" - 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 kwargs @@ -792,12 +792,12 @@ class SatPubSubClient(rsm.PubSubClient): def itemsReceived(self, event): log.debug(u"Pubsub items received") for callback in self._getNodeCallbacks(event.nodeIdentifier, C.PS_ITEMS): - callback(event, self.parent.profile) + callback(self.parent, event) def deleteReceived(self, event): log.debug((u"Publish node deleted")) 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): """Return the list of subscriptions to the given service and node. diff --git a/src/plugins/plugin_xep_0163.py b/src/plugins/plugin_xep_0163.py index 8950c3a7..d0e34bf8 100755 --- a/src/plugins/plugin_xep_0163.py +++ b/src/plugins/plugin_xep_0163.py @@ -78,16 +78,15 @@ class XEP_0163(object): self.pep_events.add(node) if 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) @param itemsEvent(pubsub.ItemsEvent): pubsub event - @param profile(unicode): %(doc_profile)s """ 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 - in_callback(itemsEvent, profile) + in_callback(itemsEvent, client.profile) self.host.plugins["XEP-0060"].addManagedNode(node, items_cb=filterPEPEvent) diff --git a/src/plugins/plugin_xep_0277.py b/src/plugins/plugin_xep_0277.py index 80424a25..574868f9 100755 --- a/src/plugins/plugin_xep_0277.py +++ b/src/plugins/plugin_xep_0277.py @@ -112,10 +112,10 @@ class XEP_0277(object): ## plugin management methods ## - def _itemsReceived(self, itemsEvent, profile): + def _itemsReceived(self, client, itemsEvent): """Callback which manage items notifications (publish + retract)""" 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: if item.name == C.PS_ITEM: