changeset 2801:ae127e14b040

plugin XEP-0060: added purgeNode/psNodePurge method to remove all items from a node
author Goffi <goffi@goffi.org>
date Fri, 15 Feb 2019 22:13:43 +0100
parents 3b68293a60d4
children f61a50790fae
files sat/plugins/plugin_xep_0060.py
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0060.py	Fri Feb 15 22:13:20 2019 +0100
+++ b/sat/plugins/plugin_xep_0060.py	Fri Feb 15 22:13:43 2019 +0100
@@ -144,6 +144,14 @@
             async=True,
         )
         host.bridge.addMethod(
+            "psNodePurge",
+            ".plugin",
+            in_sign="sss",
+            out_sign="",
+            method=self._purgeNode,
+            async=True,
+        )
+        host.bridge.addMethod(
             "psNodeDelete",
             ".plugin",
             in_sign="sss",
@@ -905,6 +913,15 @@
         d = request.send(client.xmlstream)
         return d
 
+    def _purgeNode(self, service_s, nodeIdentifier, profile_key):
+        client = self.host.getClient(profile_key)
+        return self.purgeNode(
+            client, jid.JID(service_s) if service_s else None, nodeIdentifier
+        )
+
+    def purgeNode(self, client, service, nodeIdentifier):
+        return client.pubsub_client.purgeNode(service, nodeIdentifier)
+
     def _deleteNode(self, service_s, nodeIdentifier, profile_key):
         client = self.host.getClient(profile_key)
         return self.deleteNode(
@@ -1443,6 +1460,19 @@
 
         return d.addCallback(cb)
 
+    def purgeNode(self, service, nodeIdentifier):
+        """Purge a node (i.e. delete all items from it)
+
+        @param service(jid.JID, None): service to send the item to
+            None to use PEP
+        @param NodeIdentifier(unicode): PubSub node to use
+        """
+        # TODO: propose this upstream and remove it once merged
+        request = pubsub.PubSubRequest('purge')
+        request.recipient = service
+        request.nodeIdentifier = nodeIdentifier
+        return request.send(self.xmlstream)
+
     def getDiscoInfo(self, requestor, service, nodeIdentifier=""):
         disco_info = []
         self.host.trigger.point("PubSub Disco Info", disco_info, self.parent.profile)