plugin XEP-0071: fixed rich and xhtml sending + add simple text body if not present
This commit is contained in:
parent
3337750def
commit
9bb6c74771
1 changed files with 24 additions and 8 deletions
|
|
@ -22,6 +22,7 @@ from sat.core.constants import Const as C
|
||||||
from sat.core import exceptions
|
from sat.core import exceptions
|
||||||
from sat.core.log import getLogger
|
from sat.core.log import getLogger
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
|
from sat.tools.common import data_format
|
||||||
|
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from wokkel import disco, iwokkel
|
from wokkel import disco, iwokkel
|
||||||
|
|
@ -109,6 +110,20 @@ class XEP_0071(object):
|
||||||
d_list.addCallback(lambda dummy: data)
|
d_list.addCallback(lambda dummy: data)
|
||||||
return d_list
|
return d_list
|
||||||
|
|
||||||
|
def _fill_body_text(self, text, data, lang):
|
||||||
|
data['message'][lang or ''] = text
|
||||||
|
message_elt = data['xml']
|
||||||
|
body_elt = message_elt.addElement("body", content=text)
|
||||||
|
if lang:
|
||||||
|
body_elt[(C.NS_XML, 'lang')] = lang
|
||||||
|
|
||||||
|
def _check_body_text(self, data, lang, markup, syntax, defers):
|
||||||
|
"""check if simple text message exists, and fill if needed"""
|
||||||
|
if not (lang or '') in data['message']:
|
||||||
|
d = self._s.convert(markup, syntax, self._s.SYNTAX_TEXT)
|
||||||
|
d.addCallback(self._fill_body_text, data, lang)
|
||||||
|
defers.append(d)
|
||||||
|
|
||||||
def _messageSendAddRich(self, data, client):
|
def _messageSendAddRich(self, data, client):
|
||||||
""" Construct XHTML-IM node and add it XML element
|
""" Construct XHTML-IM node and add it XML element
|
||||||
|
|
||||||
|
|
@ -130,20 +145,22 @@ class XEP_0071(object):
|
||||||
|
|
||||||
syntax = self._s.getCurrentSyntax(client.profile)
|
syntax = self._s.getCurrentSyntax(client.profile)
|
||||||
defers = []
|
defers = []
|
||||||
try:
|
if u'xhtml' in data['extra']:
|
||||||
rich = data['extra']['rich']
|
|
||||||
except KeyError:
|
|
||||||
# we have directly XHTML
|
# we have directly XHTML
|
||||||
for lang, xhtml in data['extra']['xhtml'].iteritems():
|
for lang, xhtml in data_format.getSubDict('xhtml', data['extra']):
|
||||||
|
self._check_body_text(data, lang, xhtml, self._s.SYNTAX_XHTML, defers)
|
||||||
d = self._s.convert(xhtml, self._s.SYNTAX_XHTML, self.SYNTAX_XHTML_IM)
|
d = self._s.convert(xhtml, self._s.SYNTAX_XHTML, self.SYNTAX_XHTML_IM)
|
||||||
d.addCallback(syntax_converted, lang)
|
d.addCallback(syntax_converted, lang)
|
||||||
defers.append(d)
|
defers.append(d)
|
||||||
else:
|
elif u'rich' in data['extra']:
|
||||||
# we have rich syntax to convert
|
# we have rich syntax to convert
|
||||||
for lang, rich_data in rich.iteritems():
|
for lang, rich_data in data_format.getSubDict('rich', data['extra']):
|
||||||
|
self._check_body_text(data, lang, rich_data, syntax, defers)
|
||||||
d = self._s.convert(rich_data, syntax, self.SYNTAX_XHTML_IM)
|
d = self._s.convert(rich_data, syntax, self.SYNTAX_XHTML_IM)
|
||||||
d.addCallback(syntax_converted, lang)
|
d.addCallback(syntax_converted, lang)
|
||||||
defers.append(d)
|
defers.append(d)
|
||||||
|
else:
|
||||||
|
exceptions.InternalError(u"xhtml or rich should be present at this point")
|
||||||
d_list = defer.DeferredList(defers)
|
d_list = defer.DeferredList(defers)
|
||||||
d_list.addCallback(lambda dummy: data)
|
d_list.addCallback(lambda dummy: data)
|
||||||
return d_list
|
return d_list
|
||||||
|
|
@ -162,8 +179,7 @@ class XEP_0071(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def messageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments):
|
def messageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments):
|
||||||
""" Check presence of rich text in extra
|
""" Check presence of rich text in extra """
|
||||||
"""
|
|
||||||
rich = {}
|
rich = {}
|
||||||
xhtml = {}
|
xhtml = {}
|
||||||
for key, value in data['extra'].iteritems():
|
for key, value in data['extra'].iteritems():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue