comparison sat/plugins/plugin_xep_0060.py @ 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 0b7ce5daee9b
comparison
equal deleted inserted replaced
2800:3b68293a60d4 2801:ae127e14b040
139 "psNodeSubscriptionsSet", 139 "psNodeSubscriptionsSet",
140 ".plugin", 140 ".plugin",
141 in_sign="ssa{ss}s", 141 in_sign="ssa{ss}s",
142 out_sign="", 142 out_sign="",
143 method=self._setNodeSubscriptions, 143 method=self._setNodeSubscriptions,
144 async=True,
145 )
146 host.bridge.addMethod(
147 "psNodePurge",
148 ".plugin",
149 in_sign="sss",
150 out_sign="",
151 method=self._purgeNode,
144 async=True, 152 async=True,
145 ) 153 )
146 host.bridge.addMethod( 154 host.bridge.addMethod(
147 "psNodeDelete", 155 "psNodeDelete",
148 ".plugin", 156 ".plugin",
903 request.nodeIdentifier = nodeIdentifier 911 request.nodeIdentifier = nodeIdentifier
904 request.affiliations = affiliations 912 request.affiliations = affiliations
905 d = request.send(client.xmlstream) 913 d = request.send(client.xmlstream)
906 return d 914 return d
907 915
916 def _purgeNode(self, service_s, nodeIdentifier, profile_key):
917 client = self.host.getClient(profile_key)
918 return self.purgeNode(
919 client, jid.JID(service_s) if service_s else None, nodeIdentifier
920 )
921
922 def purgeNode(self, client, service, nodeIdentifier):
923 return client.pubsub_client.purgeNode(service, nodeIdentifier)
924
908 def _deleteNode(self, service_s, nodeIdentifier, profile_key): 925 def _deleteNode(self, service_s, nodeIdentifier, profile_key):
909 client = self.host.getClient(profile_key) 926 client = self.host.getClient(profile_key)
910 return self.deleteNode( 927 return self.deleteNode(
911 client, jid.JID(service_s) if service_s else None, nodeIdentifier 928 client, jid.JID(service_s) if service_s else None, nodeIdentifier
912 ) 929 )
1441 subs.append(subscription) 1458 subs.append(subscription)
1442 return subs 1459 return subs
1443 1460
1444 return d.addCallback(cb) 1461 return d.addCallback(cb)
1445 1462
1463 def purgeNode(self, service, nodeIdentifier):
1464 """Purge a node (i.e. delete all items from it)
1465
1466 @param service(jid.JID, None): service to send the item to
1467 None to use PEP
1468 @param NodeIdentifier(unicode): PubSub node to use
1469 """
1470 # TODO: propose this upstream and remove it once merged
1471 request = pubsub.PubSubRequest('purge')
1472 request.recipient = service
1473 request.nodeIdentifier = nodeIdentifier
1474 return request.send(self.xmlstream)
1475
1446 def getDiscoInfo(self, requestor, service, nodeIdentifier=""): 1476 def getDiscoInfo(self, requestor, service, nodeIdentifier=""):
1447 disco_info = [] 1477 disco_info = []
1448 self.host.trigger.point("PubSub Disco Info", disco_info, self.parent.profile) 1478 self.host.trigger.point("PubSub Disco Info", disco_info, self.parent.profile)
1449 return disco_info 1479 return disco_info
1450 1480