diff src/plugins/plugin_xep_0060.py @ 2389:5675af905725

plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict.
author Goffi <goffi@goffi.org>
date Fri, 20 Oct 2017 08:44:09 +0200
parents 72cbb6478f97
children 8ed4ac10cb5e
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py	Fri Oct 20 08:40:54 2017 +0200
+++ b/src/plugins/plugin_xep_0060.py	Fri Oct 20 08:44:09 2017 +0200
@@ -447,6 +447,17 @@
         """
         return client.pubsub_client.createNode(service, nodeIdentifier, options)
 
+    @defer.inlineCallbacks
+    def createIfNewNode(self, client, service, nodeIdentifier, options=None):
+        """Helper method similar to createNode, but will not fail in case of conflict"""
+        try:
+            yield self.createNode(client, service, nodeIdentifier, options)
+        except error.StanzaError as e:
+            if e.condition == 'conflict':
+                pass
+            else:
+                raise e
+
     def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key):
         client = self.host.getClient(profile_key)
         d = self.getConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier)