plugin XEP-0277: don't try to create a new comments node if it already exists

This commit is contained in:
souliane 2015-12-01 23:09:50 +01:00
commit 8b9075e1f0

View file

@ -478,24 +478,16 @@ class XEP_0277(object):
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()