plugin XEP-0277, groupblog: rich text management for receiving microblogs
This commit is contained in:
parent
5981926b2b
commit
d6e7ec0055
2 changed files with 63 additions and 21 deletions
|
|
@ -83,6 +83,7 @@ class XEP_0277(object):
|
|||
|
||||
return (service, node)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def item2mbdata(self, item):
|
||||
"""Convert an XML Item to microblog data used in bridge API
|
||||
@param item: domish.Element of microblog item
|
||||
|
|
@ -91,11 +92,20 @@ class XEP_0277(object):
|
|||
entry_elt = [child for child in item.elements() if child.name == "entry"][0]
|
||||
except IndexError:
|
||||
warning(_('No entry element in microblog item'))
|
||||
return
|
||||
raise exceptions.DataError('no entry found')
|
||||
_entry = atom.Entry().import_xml(entry_elt.toXml().encode('utf-8'))
|
||||
microblog_data = {}
|
||||
try:
|
||||
microblog_data['content'] = _entry.title.text
|
||||
try:
|
||||
content_type =_entry.title.attrs['type'].lower()
|
||||
except KeyError:
|
||||
content_type = 'text'
|
||||
if content_type == 'xhtml':
|
||||
# TODO: proper check of body namespace
|
||||
microblog_data['xhtml'] = yield self.host.plugins["TEXT-SYNTAXES"].clean_xhtml(_entry.title.text)
|
||||
microblog_data['content'] = _entry.title.text # FIXME: must use text version of the microblog, or convert XHTML to text if not available
|
||||
else:
|
||||
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))
|
||||
|
|
@ -114,7 +124,7 @@ class XEP_0277(object):
|
|||
|
||||
except (AttributeError, KeyError):
|
||||
error(_('Error while parsing atom entry for microblogging event'))
|
||||
return {}
|
||||
raise exceptions.DataError
|
||||
|
||||
##XXX: workaround for Jappix behaviour
|
||||
if not 'author' in microblog_data:
|
||||
|
|
@ -126,13 +136,22 @@ class XEP_0277(object):
|
|||
except:
|
||||
error(_('Cannot find author'))
|
||||
##end workaround Jappix
|
||||
return microblog_data
|
||||
|
||||
defer.returnValue(microblog_data)
|
||||
|
||||
def microblogCB(self, itemsEvent, profile):
|
||||
for item in itemsEvent.items:
|
||||
microblog_data = self.item2mbdata(item)
|
||||
d = defer.Deferred()
|
||||
|
||||
def manageItem(microblog_data):
|
||||
self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile)
|
||||
|
||||
for item in itemsEvent.items:
|
||||
d.addCallback(lambda ignore: self.item2mbdata(item))
|
||||
d.addCallback(manageItem)
|
||||
|
||||
d.callback(None)
|
||||
return d
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def data2entry(self, data, profile):
|
||||
"""Convert a data dict to en entry usable to create an item
|
||||
|
|
@ -188,8 +207,19 @@ class XEP_0277(object):
|
|||
@param max_items: how many microblogs we want to get
|
||||
@param profile_key: profile key
|
||||
"""
|
||||
def resultToArray(result):
|
||||
ret = []
|
||||
for (success, value) in result:
|
||||
if success:
|
||||
ret.append(value)
|
||||
else:
|
||||
error('Error while getting last microblog')
|
||||
return ret
|
||||
|
||||
d = self.host.plugins["XEP-0060"].getItems(jid.JID(pub_jid), NS_MICROBLOG, max_items=max_items, profile_key=profile_key)
|
||||
d.addCallback(lambda items: map(self.item2mbdata, items))
|
||||
d.addCallback(lambda items: defer.DeferredList(map(self.item2mbdata, items)))
|
||||
d.addCallback(resultToArray)
|
||||
return d
|
||||
|
||||
def setMicroblogAccess(self, access="presence", profile_key='@DEFAULT@'):
|
||||
"""Create a microblog node on PEP with given access
|
||||
|
|
|
|||
Loading…
Reference in a new issue