diff src/plugins/plugin_xep_0277.py @ 1711:e5b569d0c2e7

plugin XEP-0277: don't try to create a new comments node if it already exists
author souliane <souliane@mailoo.org>
date Tue, 01 Dec 2015 23:09:50 +0100
parents c47ba491a85a
children 96b722a5e263
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py	Tue Dec 01 17:17:09 2015 +0100
+++ b/src/plugins/plugin_xep_0277.py	Tue Dec 01 23:09:50 2015 +0100
@@ -478,24 +478,16 @@
 
         comments_node_base = u"{}{}".format(NS_COMMENT_PREFIX, item_id)
         comments_node = comments_node_base
-
-        suffix = None
         comments_service = client.pubsub_service if client.pubsub_service is not None else service
 
-        # we try to create the comment nodes #
-        max_tries = 3
-
-        for i in xrange(max_tries+1):
-            try:
-                yield self._p.createNode(comments_service, comments_node, options, profile_key=profile)
-                break
-            except error.StanzaError as e:
-                if e.condition == 'conflict' and i<max_tries:
-                    log.warning(u"node {} already exists on service {}".format(comments_node, comments_service))
-                    suffix = 0 if suffix is None else suffix + 1
-                    comments_node = u"{}_{}".format(comments_node_base, suffix)
-                else:
-                    raise e
+        try:
+            yield self._p.createNode(comments_service, comments_node, options, profile_key=profile)
+            break
+        except error.StanzaError as e:
+            if e.condition == 'conflict':
+                log.info(u"node {} already exists on service {}".format(comments_node, comments_service))
+            else:
+                raise e
 
         if comments_service is None:
             comments_service = client.jid.userhostJID()