plugin XEP-0277, group blog: rich text management for sending microblogs
This commit is contained in:
parent
e743df999e
commit
5981926b2b
1 changed files with 55 additions and 33 deletions
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
from logging import debug, info, warning, error
|
||||
from twisted.words.protocols.jabber import jid
|
||||
from twisted.internet import defer
|
||||
from sat.core import exceptions
|
||||
from sat.tools.xml_tools import ElementParser
|
||||
|
||||
|
|
@ -27,15 +28,17 @@ from feed import atom
|
|||
import uuid
|
||||
from time import time
|
||||
import urlparse
|
||||
from cgi import escape
|
||||
|
||||
NS_MICROBLOG = 'urn:xmpp:microblog:0'
|
||||
NS_XHTML = 'http://www.w3.org/1999/xhtml'
|
||||
|
||||
PLUGIN_INFO = {
|
||||
"name": "Microblogging over XMPP Plugin",
|
||||
"import_name": "XEP-0277",
|
||||
"type": "XEP",
|
||||
"protocols": [],
|
||||
"dependencies": ["XEP-0163", "XEP-0060"],
|
||||
"dependencies": ["XEP-0163", "XEP-0060", "TEXT-SYNTAXES"],
|
||||
"main": "XEP_0277",
|
||||
"handler": "no",
|
||||
"description": _("""Implementation of microblogging Protocol""")
|
||||
|
|
@ -130,15 +133,24 @@ class XEP_0277(object):
|
|||
microblog_data = self.item2mbdata(item)
|
||||
self.host.bridge.personalEvent(itemsEvent.sender.full(), "MICROBLOG", microblog_data, profile)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
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"""
|
||||
@return: deferred which fire domish.Element"""
|
||||
_uuid = unicode(uuid.uuid1())
|
||||
content = data['content']
|
||||
_entry = atom.Entry()
|
||||
#FIXME: need to escape html
|
||||
|
||||
if "rich" in data:
|
||||
synt = self.host.plugins["TEXT-SYNTAXES"]
|
||||
converted = yield synt.convert(data['rich'], synt.getCurrentSyntax(profile), "XHTML")
|
||||
content = u'<div xmlns="%s">%s</div>' % (NS_XHTML, converted)
|
||||
_entry.title.attrs['type'] = 'xhtml'
|
||||
else:
|
||||
content = escape(data['content'])
|
||||
_entry.title.attrs['type'] = 'text'
|
||||
_entry.title = unicode(content).encode('utf-8')
|
||||
|
||||
_entry.author = atom.Author()
|
||||
_entry.author.name = data.get('author', self.host.getJidNStream(profile)[0].userhost()).encode('utf-8')
|
||||
_entry.updated = float(data.get('timestamp', time()))
|
||||
|
|
@ -152,8 +164,9 @@ class XEP_0277(object):
|
|||
_entry_elt = ElementParser()(str(_entry).decode('utf-8'))
|
||||
item = pubsub.Item(payload=_entry_elt)
|
||||
item['id'] = _uuid
|
||||
return item
|
||||
defer.returnValue(item)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def sendMicroblog(self, data, profile):
|
||||
"""Send XEP-0277's microblog data
|
||||
@param data: must include content
|
||||
|
|
@ -165,8 +178,9 @@ class XEP_0277(object):
|
|||
if not content:
|
||||
error(_("Microblog data's content value must not be empty"))
|
||||
raise exceptions.DataError('empty content')
|
||||
item = self.data2entry(data, profile)
|
||||
return self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile)
|
||||
item = yield self.data2entry(data, profile)
|
||||
ret = yield self.host.plugins["XEP-0060"].publish(None, NS_MICROBLOG, [item], profile_key=profile)
|
||||
defer.returnValue(ret)
|
||||
|
||||
def getLastMicroblogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
|
||||
"""Get the last published microblogs
|
||||
|
|
|
|||
Loading…
Reference in a new issue