summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2011-03-29 20:36:02 +0200
committerFlorent Le Coz <louiz@louiz.org>2011-03-29 20:36:02 +0200
commitba02b51554e2125d54de4b748838b9b0495df1e4 (patch)
treeb8ae8f53c89898abbd3220c8aaeb2f74a89b4802 /src
parenta0248d4324faec7fd3d3ef0bee1f9cf86a33c08e (diff)
downloadpoezio-ba02b51554e2125d54de4b748838b9b0495df1e4.tar.gz
poezio-ba02b51554e2125d54de4b748838b9b0495df1e4.tar.bz2
poezio-ba02b51554e2125d54de4b748838b9b0495df1e4.tar.xz
poezio-ba02b51554e2125d54de4b748838b9b0495df1e4.zip
Convert html markup received in xhtml_im elements to poezio colors
and use that as the body
Diffstat (limited to 'src')
-rw-r--r--src/connection.py3
-rw-r--r--src/core.py7
-rw-r--r--src/tabs.py1
-rw-r--r--src/xhtml.py21
4 files changed, 28 insertions, 4 deletions
diff --git a/src/connection.py b/src/connection.py
index 089c43b8..8bef6eb2 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -54,8 +54,9 @@ class Connection(sleekxmpp.ClientXMPP):
self.auto_reconnect = False
self.auto_authorize = None
self.register_plugin('xep_0030')
- self.register_plugin('xep_0045')
self.register_plugin('xep_0004')
+ self.register_plugin('xep_0045')
+ self.register_plugin('xep_0071')
self.register_plugin('xep_0085')
if config.get('send_poezio_info', 'true') == 'true':
info = {'name':'poezio',
diff --git a/src/core.py b/src/core.py
index c6b2942b..83ab0683 100644
--- a/src/core.py
+++ b/src/core.py
@@ -38,6 +38,7 @@ log = logging.getLogger(__name__)
import multiuserchat as muc
import tabs
+import xhtml
import windows
import connection
@@ -457,7 +458,7 @@ class Core(object):
room = self.open_private_window(room_from, nick_from, False)
if not room:
return
- body = message['body']
+ body = xhtml.get_body_from_message_stanza(message)
room.add_message(body, time=None, nickname=nick_from,
forced_user=self.get_room_by_name(room_from).get_user_by_name(nick_from))
conversation = self.get_tab_by_name(jid.full, tabs.PrivateTab)
@@ -499,7 +500,7 @@ class Core(object):
When receiving "normal" messages (from someone in our roster)
"""
jid = message['from']
- body = message['body']
+ body = xhtml.get_body_from_message_stanza(message)
if not body:
return
conversation = self.get_tab_of_conversation_with_jid(jid, create=True)
@@ -878,7 +879,7 @@ class Core(object):
if not room:
self.information(_("message received for a non-existing room: %s") % (room_from))
return
- body = message['body']
+ body = xhtml.get_body_from_message_stanza(message)
if body:
date = date if delayed == True else None
self.add_message_to_text_buffer(room, body, date, nick_from)
diff --git a/src/tabs.py b/src/tabs.py
index b7624c2b..e3bea971 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -557,6 +557,7 @@ class MucTab(ChatTab):
msg = self.core.xmpp.make_message(self.get_name())
msg['type'] = 'groupchat'
msg['body'] = line
+ msg['xhtml_im'] = "<body><p>coucou</p></body>"
if config.get('send_chat_states', 'true') == 'true' and self.remote_wants_chatstates is not False:
msg['chat_state'] = 'active'
msg.send()
diff --git a/src/xhtml.py b/src/xhtml.py
index 71a3ad3e..5f0e9927 100644
--- a/src/xhtml.py
+++ b/src/xhtml.py
@@ -26,8 +26,29 @@ poezio colors to xhtml code
import re
import subprocess
+import logging
+
+log = logging.getLogger(__name__)
+
+
shell_colors_re = re.compile(r'(\[(?:\d+;)*(?:\d+m))')
+def get_body_from_message_stanza(message):
+ """
+ Returns a string with xhtml markups converted to
+ poezio colors if there's an xhtml_im element, or
+ the body (without any color) otherwise
+ """
+ xhtml_body = message['xhtml_im']
+ if xhtml_body:
+ try:
+ shell_body = xhtml_code_to_shell_colors(xhtml_body)
+ except OSError:
+ log.error('html parsing failed')
+ else:
+ return shell_colors_to_poezio_colors(shell_body)
+ return message['body']
+
def shell_colors_to_poezio_colors(string):
"""
'shell colors' means something like: