comparison 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
comparison
equal deleted inserted replaced
1710:7226280e70da 1711:e5b569d0c2e7
476 # if other plugins need to change the options 476 # if other plugins need to change the options
477 yield self.host.trigger.point("XEP-0277_comments", client, mb_data, options) 477 yield self.host.trigger.point("XEP-0277_comments", client, mb_data, options)
478 478
479 comments_node_base = u"{}{}".format(NS_COMMENT_PREFIX, item_id) 479 comments_node_base = u"{}{}".format(NS_COMMENT_PREFIX, item_id)
480 comments_node = comments_node_base 480 comments_node = comments_node_base
481
482 suffix = None
483 comments_service = client.pubsub_service if client.pubsub_service is not None else service 481 comments_service = client.pubsub_service if client.pubsub_service is not None else service
484 482
485 # we try to create the comment nodes # 483 try:
486 max_tries = 3 484 yield self._p.createNode(comments_service, comments_node, options, profile_key=profile)
487 485 break
488 for i in xrange(max_tries+1): 486 except error.StanzaError as e:
489 try: 487 if e.condition == 'conflict':
490 yield self._p.createNode(comments_service, comments_node, options, profile_key=profile) 488 log.info(u"node {} already exists on service {}".format(comments_node, comments_service))
491 break 489 else:
492 except error.StanzaError as e: 490 raise e
493 if e.condition == 'conflict' and i<max_tries:
494 log.warning(u"node {} already exists on service {}".format(comments_node, comments_service))
495 suffix = 0 if suffix is None else suffix + 1
496 comments_node = u"{}_{}".format(comments_node_base, suffix)
497 else:
498 raise e
499 491
500 if comments_service is None: 492 if comments_service is None:
501 comments_service = client.jid.userhostJID() 493 comments_service = client.jid.userhostJID()
502 494
503 mb_data['comments'] = "xmpp:%(service)s?%(query)s" % { 495 mb_data['comments'] = "xmpp:%(service)s?%(query)s" % {