changeset 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 d4e73d9140af
children 9b078380dacf
files browser_side/panels.py libervia.py libervia.tac
diffstat 3 files changed, 10 insertions(+), 10 deletions(-) [+]
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):
--- a/libervia.py	Thu Oct 31 17:54:10 2013 +0100
+++ b/libervia.py	Thu Nov 07 15:22:00 2013 +0100
@@ -507,13 +507,13 @@
             lib_wid.refresh()
         return lib_wid
 
-    def _newMessageCb(self, from_jid, msg, msg_type, to_jid):
+    def _newMessageCb(self, from_jid, msg, msg_type, to_jid, extra):
         _from = JID(from_jid)
         _to = JID(to_jid)
         other = _to if _from.bare == self.whoami.bare else _from
         lib_wid = self.getLiberviaWidget(panels.ChatPanel, other, ignoreOtherTabs=False)
         if lib_wid is not None:
-            lib_wid.printMessage(_from, msg)
+            lib_wid.printMessage(_from, msg, extra)
         else:
             # The message has not been showed, we must indicate it
             self.contact_panel.setContactMessageWaiting(other.bare, True)
--- a/libervia.tac	Thu Oct 31 17:54:10 2013 +0100
+++ b/libervia.tac	Thu Nov 07 15:22:00 2013 +0100
@@ -309,8 +309,8 @@
             for line in result_dbus:
                 #XXX: we have to do this stupid thing because Python D-Bus use its own types instead of standard types
                 #     and txJsonRPC doesn't accept D-Bus types, resulting in a empty query
-                timestamp, from_jid, to_jid, message, mess_type = line
-                result.append((float(timestamp), unicode(from_jid), unicode(to_jid), unicode(message), unicode(mess_type)))
+                timestamp, from_jid, to_jid, message, mess_type, extra = line
+                result.append((float(timestamp), unicode(from_jid), unicode(to_jid), unicode(message), unicode(mess_type), dict(extra)))
             return result
         d.addCallback(show)
         return d