From 83151b8b0e049f39c835561e9420172b255201ec Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 18 Feb 2011 22:32:02 +0100 Subject: [PATCH] plugin XEP 0277: author for in request + author, updated management for out request - a workaround is now used to parse "nick" tag (Jappix behaviour) - author and updated can now be used in data when sendind microblog. Is no author is given, user jid is used, if no updated is given, current timestamp is used --- src/plugins/plugin_xep_0277.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/plugins/plugin_xep_0277.py b/src/plugins/plugin_xep_0277.py index ed083c73..a51e4c08 100755 --- a/src/plugins/plugin_xep_0277.py +++ b/src/plugins/plugin_xep_0277.py @@ -28,7 +28,7 @@ from twisted.words.xish import domish from sat.tools.xml_tools import ElementParser from wokkel import disco,pubsub -from feed.atom import Entry +from feed.atom import Entry, Author import uuid from time import time @@ -64,11 +64,25 @@ class XEP_0277(): microblog_data={} try: microblog_data['content'] = _entry.title.text + if len(_entry.authors): + microblog_data['author'] = _entry.authors[0].name.text microblog_data['timestamp'] = str(int(_entry.updated.tf)) microblog_data['id'] = item['id'] except AttributeError, KeyError: error(_('Error while parsing atom entry for microblogging event')) return + + ##XXX: workaround for Jappix behaviour + if not 'author' in microblog_data: + from xe import NestElement + try: + author=NestElement('author') + author.import_xml(str(_entry)) + microblog_data['author'] = author.nick.text + except: + error(_('Cannot find author')) + ##end workaround Jappix + self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile) def sendMicroblog(self, data, profile): @@ -83,8 +97,11 @@ class XEP_0277(): error(_("Microblog data's content value must not be empty")) _uuid = unicode(uuid.uuid1()) _entry = Entry() + #FIXME: need to escape html _entry.title = content.encode('utf-8') - _entry.updated = time() + _entry.author = Author() + _entry.author.name = data.get('author',self.host.getJidNStream(profile)[0].userhost()).encode('utf-8') + _entry.updated = float(data.get('timestamp',time())) _entry.id = _uuid _entry_elt = ElementParser()(str(_entry)) item = pubsub.Item(payload=_entry_elt)