Mercurial > libervia-backend
diff src/plugins/plugin_xep_0277.py @ 1661:96ee986dab3c
plugin XEP-0277: added a trigger on data2entry and comments management
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Nov 2015 16:21:18 +0100 |
parents | 069abd15354f |
children | 5d0ff155be1a |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py Tue Nov 24 16:21:18 2015 +0100 +++ b/src/plugins/plugin_xep_0277.py Tue Nov 24 16:21:18 2015 +0100 @@ -317,7 +317,7 @@ 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 @@ """ 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 @@ 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 @@ ## 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 @@ 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):