diff --git a/src/plugins/plugin_misc_groupblog.py b/src/plugins/plugin_misc_groupblog.py index 7237720f..77615ebf 100755 --- a/src/plugins/plugin_misc_groupblog.py +++ b/src/plugins/plugin_misc_groupblog.py @@ -250,9 +250,12 @@ class GroupBlog(object): @param message: message to publish @param extra: dict which option name as key, which can be: - allow_comments: True to accept comments, False else (default: False) + - rich: if present, contain rich text in currently selected syntax """ node_name = self.getNodeName(client.jid) mblog_data = {'content': message} + if 'rich' in extra: + mblog_data['rich'] = extra['rich'] P = self.host.plugins["XEP-0060"] access_model_value = ACCESS_TYPE_MAP[access_type] @@ -275,29 +278,33 @@ class GroupBlog(object): # node owned by somebody else) defer_blog = self.host.plugins["XEP-0060"].createNode(service, comments_node, _options, profile_key=client.profile) - mblog_item = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile) - form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG) + def itemCreated(mblog_item): + form = data_form.Form('submit', formNamespace=NS_PUBSUB_ITEM_CONFIG) - if access_type == "PUBLIC": - if access_list: - raise BadAccessListError("access_list must be empty for PUBLIC access") - access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value) - form.addField(access) - elif access_type == "GROUP": - access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value) - allowed = data_form.Field(None, P.OPT_ROSTER_GROUPS_ALLOWED, values=access_list) - form.addField(access) - form.addField(allowed) - mblog_item.addChild(form.toElement()) - elif access_type == "JID": - raise NotImplementedError - else: - error(_("Unknown access_type")) - raise BadAccessTypeError + if access_type == "PUBLIC": + if access_list: + raise BadAccessListError("access_list must be empty for PUBLIC access") + access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value) + form.addField(access) + elif access_type == "GROUP": + access = data_form.Field(None, P.OPT_ACCESS_MODEL, value=access_model_value) + allowed = data_form.Field(None, P.OPT_ROSTER_GROUPS_ALLOWED, values=access_list) + form.addField(access) + form.addField(allowed) + mblog_item.addChild(form.toElement()) + elif access_type == "JID": + raise NotImplementedError + else: + error(_("Unknown access_type")) + raise BadAccessTypeError - defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile) - defer_blog.addErrback(self._mblogPublicationFailed) - return defer_blog + defer_blog = self.host.plugins["XEP-0060"].publish(service, node_name, items=[mblog_item], profile_key=client.profile) + defer_blog.addErrback(self._mblogPublicationFailed) + return defer_blog + + entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, client.profile) + entry_d.addCallback(itemCreated) + return entry_d def _mblogPublicationFailed(self, failure): #TODO @@ -311,6 +318,7 @@ class GroupBlog(object): @param message: microblog @param extra: dict which option name as key, which can be: - allow_comments: True to accept comments, False else (default: False) + - rich: if present, contain rich text in currently selected syntax @profile_key: %(doc_profile)s """ @@ -347,9 +355,9 @@ class GroupBlog(object): service, node = self.host.plugins["XEP-0277"].parseCommentUrl(node_url) mblog_data = {'content': message} - mblog_item = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile) - - return self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile) + entry_d = self.host.plugins["XEP-0277"].data2entry(mblog_data, profile) + entry_d.addCallback(lambda mblog_item: self.host.plugins["XEP-0060"].publish(service, node, items=[mblog_item], profile_key=profile)) + return entry_d def _itemsConstruction(self, items, pub_jid, client): """ Transforms items to group blog data and manage comments node diff --git a/src/plugins/plugin_xep_0277.py b/src/plugins/plugin_xep_0277.py index 03d0f069..3212f0f1 100755 --- a/src/plugins/plugin_xep_0277.py +++ b/src/plugins/plugin_xep_0277.py @@ -19,6 +19,7 @@ from logging import debug, info, warning, error from twisted.words.protocols.jabber import jid +from twisted.internet import defer from sat.core import exceptions from sat.tools.xml_tools import ElementParser @@ -27,15 +28,17 @@ from feed import atom import uuid from time import time import urlparse +from cgi import escape NS_MICROBLOG = 'urn:xmpp:microblog:0' +NS_XHTML = 'http://www.w3.org/1999/xhtml' PLUGIN_INFO = { "name": "Microblogging over XMPP Plugin", "import_name": "XEP-0277", "type": "XEP", "protocols": [], - "dependencies": ["XEP-0163", "XEP-0060"], + "dependencies": ["XEP-0163", "XEP-0060", "TEXT-SYNTAXES"], "main": "XEP_0277", "handler": "no", "description": _("""Implementation of microblogging Protocol""") @@ -130,15 +133,24 @@ class XEP_0277(object): microblog_data = self.item2mbdata(item) self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile) + @defer.inlineCallbacks def data2entry(self, data, profile): """Convert a data dict to en entry usable to create an item @param data: data dict as given by bridge method - @return: domish.Element""" + @return: deferred which fire domish.Element""" _uuid = unicode(uuid.uuid1()) - content = data['content'] _entry = atom.Entry() - #FIXME: need to escape html + + if "rich" in data: + synt = self.host.plugins["TEXT-SYNTAXES"] + converted = yield synt.convert(data['rich'], synt.getCurrentSyntax(profile), "XHTML") + content = u'