diff browser_side/panels.py @ 235:b304cdf13a3b

browser and server side: XHTML handling, first draft: - added the extra parameter for getHistory and newMessage to manage xhtml - if present, XHTML is shown instead of regular text message
author Goffi <goffi@goffi.org>
date Thu, 07 Nov 2013 15:22:00 +0100
parents 0ed09cc0566f
children b911f2b43fd4
line wrap: on
line diff
--- a/browser_side/panels.py	Thu Oct 31 17:54:10 2013 +0100
+++ b/browser_side/panels.py	Thu Nov 07 15:22:00 2013 +0100
@@ -599,7 +599,7 @@
 
 class ChatText(HTMLPanel):
 
-    def __init__(self, timestamp, nick, mymess, msg):
+    def __init__(self, timestamp, nick, mymess, msg, xhtml = None):
         _date = datetime.fromtimestamp(float(timestamp or time()))
         _msg_class = ["chat_text_msg"]
         if mymess:
@@ -608,7 +608,7 @@
                            {"timestamp": _date.strftime("%H:%M"),
                             "nick": "[%s]" % html_sanitize(nick),
                             "msg_class": ' '.join(_msg_class),
-                            "msg": addURLToText(html_sanitize(msg))}
+                            "msg": addURLToText(html_sanitize(msg)) if not xhtml else xhtml} #FIXME: images and external links must be removed according to preferences
                            )
         self.setStyleName('chatText')
 
@@ -767,12 +767,12 @@
             day_format = "%A, %d %b %Y"
             previous_day = datetime.now().strftime(day_format)
             for line in history:
-                timestamp, from_jid, to_jid, message, mess_type = line
+                timestamp, from_jid, to_jid, message, mess_type, extra = line
                 message_day = datetime.fromtimestamp(float(timestamp or time())).strftime(day_format)
                 if previous_day != message_day:
                     self.printInfo("* " + message_day)
                     previous_day = message_day
-                self.printMessage(from_jid, message, timestamp)
+                self.printMessage(from_jid, message, extra, timestamp)
         self.host.bridge.call('getHistory', getHistoryCB, self.host.whoami.bare, self.target.bare, size, True)
 
     def printInfo(self, msg, type='normal'):
@@ -791,7 +791,7 @@
             _wid.setStyleName('chatTextInfo')
         self.content.add(_wid)
 
-    def printMessage(self, from_jid, msg, timestamp=None):
+    def printMessage(self, from_jid, msg, extra, timestamp=None):
         """Print message in chat window. Must be implemented by child class"""
         _jid = JID(from_jid)
         nick = _jid.node if self.type == 'one2one' else _jid.resource
@@ -799,7 +799,7 @@
         if msg.startswith('/me '):
             self.printInfo('* %s %s' % (nick, msg[4:]), type='me')
             return
-        self.content.add(ChatText(timestamp, nick, mymess, msg))
+        self.content.add(ChatText(timestamp, nick, mymess, msg, extra.get('xhtml')))
         self.content_scroll.scrollToBottom()
 
     def startGame(self, game_type, referee, players):