Mercurial > libervia-backend
changeset 297:c5554e2939dd
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
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 18 Feb 2011 22:32:02 +0100 |
parents | d1cc69161f3f |
children | 15c8916317d0 |
files | src/plugins/plugin_xep_0277.py |
diffstat | 1 files changed, 19 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0277.py Fri Feb 18 22:23:09 2011 +0100 +++ b/src/plugins/plugin_xep_0277.py Fri Feb 18 22:32:02 2011 +0100 @@ -28,7 +28,7 @@ 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 @@ 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 @@ 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)