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
This commit is contained in:
parent
b256b8fc5d
commit
83151b8b0e
1 changed files with 19 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue