plugin XEP-0277: added a trigger on data2entry and comments management

This commit is contained in:
Goffi 2015-11-24 16:21:18 +01:00
commit 9498114b61

View file

@ -317,7 +317,7 @@ class XEP_0277(object):
defer.returnValue(microblog_data)
@defer.inlineCallbacks
def data2entry(self, data, item_id=None, profile_key=C.PROF_KEY_NONE):
def data2entry(self, data, item_id=None, profile=C.PROF_KEY_NONE):
"""Convert a data dict to en entry usable to create an item
@param data: data dict as given by bridge method.
@ -327,7 +327,7 @@ class XEP_0277(object):
"""
if item_id is None:
item_id = unicode(uuid.uuid4())
client = self.host.getClient(profile_key)
client = self.host.getClient(profile)
entry_elt = domish.Element((NS_ATOM, 'entry'))
## content and title ##
@ -340,7 +340,7 @@ class XEP_0277(object):
elem = entry_elt.addElement(elem_name)
if type_:
if type_ == '_rich': # convert input from current syntax to XHTML
converted = yield synt.convert(data[attr], synt.getCurrentSyntax(profile_key), "XHTML")
converted = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML")
if '{}_xhtml'.format(elem_name) in data:
raise failure.Failure(exceptions.DataError(_("Can't have xhtml and rich content at the same time")))
else: # clean the XHTML input
@ -412,6 +412,11 @@ class XEP_0277(object):
## final item building ##
item_elt = pubsub.Item(id=item_id, payload=entry_elt)
## the trigger ##
# if other plugins have things to add or change
yield self.host.trigger.point("XEP-0277_data2entry", client, data, entry_elt, item_elt)
defer.returnValue(item_elt)
## publish ##
@ -440,11 +445,16 @@ class XEP_0277(object):
self._p.OPT_PUBLISH_MODEL: "subscribers", # TODO: should be open if *both* node and item access_model are open (public node and item)
}
# if other plugins need to change the options
yield self.host.trigger.point("XEP-0277_comments", client, mb_data, options)
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):