Mercurial > libervia-backend
changeset 306:169e7386650a
plugin xep-0277: bridge data is now converted in pubsub item in a separate function
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 07 Apr 2011 22:22:41 +0200 |
parents | 15a12bf2bb62 |
children | 1e4575e12581 |
files | src/plugins/plugin_xep_0277.py |
diffstat | 1 files changed, 23 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py Thu Apr 07 22:21:16 2011 +0200 +++ b/src/plugins/plugin_xep_0277.py Thu Apr 07 22:22:41 2011 +0200 @@ -107,18 +107,12 @@ microblog_data = self._item2mbdata(item) self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile) - def sendMicroblog(self, data, profile): - """Send XEP-0277's microblog data - @param data: must include content - @param profile: profile which send the mood""" - if not data.has_key('content'): - error(_("Microblog data must contain at least 'content' key")) - return 3 + 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""" + _uuid = unicode(uuid.uuid1()) content = data['content'] - if not content: - error(_("Microblog data's content value must not be empty")) - return 3 - _uuid = unicode(uuid.uuid1()) _entry = Entry() #FIXME: need to escape html _entry.title = unicode(content).encode('utf-8') @@ -129,6 +123,20 @@ _entry_elt = ElementParser()(str(_entry).decode('utf-8')) item = pubsub.Item(payload=_entry_elt) item['id'] = _uuid + return item + + def sendMicroblog(self, data, profile): + """Send XEP-0277's microblog data + @param data: must include content + @param profile: profile which send the mood""" + if not data.has_key('content'): + error(_("Microblog data must contain at least 'content' key")) + return 3 + content = data['content'] + if not content.has_key("content"): + error(_("Microblog data's content value must not be empty")) + return 3 + item = self.data2entry(data, profile) self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key = profile) return 0 @@ -150,7 +158,7 @@ @param access: Node access model, according to xep-0060 #4.5 @param profile_key: profile key""" - jid, xmlstream = self.host.getJidNStream(profile_key) + _jid, xmlstream = self.host.getJidNStream(profile_key) _options = {NS_ACCESS_MODEL:access, NS_PERSIST_ITEMS:1, NS_MAX_ITEMS:-1} def cb(result): #Node is created with right permission @@ -164,17 +172,17 @@ #If the node already exists, the condition is "conflict", #else we have an unmanaged error if s_error.value.condition=='conflict': - #d = self.host.plugins["XEP-0060"].deleteNode(jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key) + #d = self.host.plugins["XEP-0060"].deleteNode(_jid.userhostJID(), NS_MICROBLOG, profile_key=profile_key) #d.addCallback(lambda x: create_node().addCallback(cb).addErrback(fatal_err)) change_node_options().addCallback(cb).addErrback(fatal_err) else: fatal_err(s_error) def create_node(): - return self.host.plugins["XEP-0060"].createNode(jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key) + return self.host.plugins["XEP-0060"].createNode(_jid.userhostJID(), NS_MICROBLOG, _options, profile_key=profile_key) def change_node_options(): - return self.host.plugins["XEP-0060"].setOptions(jid.userhostJID(), NS_MICROBLOG, jid.userhostJID(), _options, profile_key=profile_key) + return self.host.plugins["XEP-0060"].setOptions(_jid.userhostJID(), NS_MICROBLOG, _jid.userhostJID(), _options, profile_key=profile_key) create_node().addCallback(cb).addErrback(err_cb)