changeset 1223:802b7e6bf098

frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''
author souliane <souliane@mailoo.org>
date Sat, 04 Oct 2014 10:23:13 +0200
parents e6e0ea4dc835
children f0c9b149ed99
files frontends/src/primitivus/chat.py frontends/src/quick_frontend/quick_app.py frontends/src/quick_frontend/quick_chat.py frontends/src/wix/chat.py
diffstat 4 files changed, 15 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py	Wed Sep 24 13:49:43 2014 +0200
+++ b/frontends/src/primitivus/chat.py	Sat Oct 04 10:23:13 2014 +0200
@@ -290,14 +290,14 @@
             self.text_list.focus_position = len(self.content) - 1  # scroll down
         self.host.redraw()
 
-    def printMessage(self, from_jid, msg, profile, timestamp=""):
+    def printMessage(self, from_jid, msg, profile, timestamp=None):
         assert isinstance(from_jid, JID)
         try:
             jid, nick, mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp)
         except TypeError:
             return
 
-        new_text = ChatText(self, timestamp or None, nick, mymess, msg)
+        new_text = ChatText(self, timestamp, nick, mymess, msg)
 
         if timestamp and self.content:
             for idx in range(len(self.content) - 1, -1, -1):
@@ -307,6 +307,7 @@
                     continue  # the new message is older, we need to insert it upper
 
                 #we discard double messages, to avoid backlog / history conflict
+                # FIXME: messages that have been sent several times will be displayed only once
                 if ((idx and self.content[idx - 1].message == msg) or
                     (self.content[idx].message == msg) or
                     (idx < len(self.content) - 2 and self.content[idx + 1].message)):
@@ -322,14 +323,15 @@
             # all messages and not only with the messages coming from the history.
             self._notify(from_jid, msg)
 
-    def printInfo(self, msg, type_='normal', timestamp=""):
+    def printInfo(self, msg, type_='normal', timestamp=None):
         """Print general info
         @param msg: message to print
         @type_: one of:
             normal: general info like "toto has joined the room"
             me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
+        @param timestamp (float): number of seconds since epoch
         """
-        _widget = ChatText(self, timestamp or None, None, False, msg, is_info=True)
+        _widget = ChatText(self, timestamp, None, False, msg, is_info=True)
         self.content.append(_widget)
         self._notify(msg=msg)
 
--- a/frontends/src/quick_frontend/quick_app.py	Wed Sep 24 13:49:43 2014 +0200
+++ b/frontends/src/quick_frontend/quick_app.py	Sat Oct 04 10:23:13 2014 +0200
@@ -308,9 +308,9 @@
 
         timestamp = extra.get('archive')
         if type_ == C.MESS_TYPE_INFO:
-            self.chat_wins[win.bare].printInfo( msg, timestamp = float(timestamp) if timestamp else '')
+            self.chat_wins[win.bare].printInfo(msg, timestamp=float(timestamp) if timestamp else None)
         else:
-            self.chat_wins[win.bare].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '')
+            self.chat_wins[win.bare].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else None)
 
     def sendMessage(self, to_jid, message, subject='', mess_type="auto", extra={}, callback=None, errback=None, profile_key="@NONE@"):
         if to_jid.startswith(C.PRIVATE_PREFIX):
--- a/frontends/src/quick_frontend/quick_chat.py	Wed Sep 24 13:49:43 2014 +0200
+++ b/frontends/src/quick_frontend/quick_chat.py	Sat Oct 04 10:23:13 2014 +0200
@@ -134,9 +134,9 @@
                 return unescaped.resource
         return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node)
 
-    def printMessage(self, from_jid, msg, profile, timestamp = ''):
+    def printMessage(self, from_jid, msg, profile, timestamp=None):
         """Print message in chat window. Must be implemented by child class"""
-        jid=JID(from_jid)
+        jid = JID(from_jid)
         nick = self._get_nick(jid)
         mymess = (jid.resource == self.nick) if self.type == "group" else (jid.bare == self.host.profiles[profile]['whoami'].bare) #mymess = True if message comes from local user
         if msg.startswith('/me '):
@@ -144,12 +144,13 @@
             return
         return jid, nick, mymess
 
-    def printInfo(self, msg, type_='normal'):
+    def printInfo(self, msg, type_='normal', timestamp=None):
         """Print general info
         @param msg: message to print
         @type_: one of:
             normal: general info like "toto has joined the room"
             me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
+        @param timestamp (float): number of seconds since epoch
         """
         raise NotImplementedError
 
--- a/frontends/src/wix/chat.py	Wed Sep 24 13:49:43 2014 +0200
+++ b/frontends/src/wix/chat.py	Sat Oct 04 10:23:13 2014 +0200
@@ -217,7 +217,7 @@
         if not self.IsShown():
             self.Show()
 
-    def printMessage(self, from_jid, msg, profile, timestamp=""):
+    def printMessage(self, from_jid, msg, profile, timestamp=None):
         """Print the message with differents colors depending on where it comes from."""
         try:
             jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp)
@@ -238,12 +238,13 @@
         if not mymess:
             self.__blink()
 
-    def printInfo(self, msg, type_='normal', timestamp=""):
+    def printInfo(self, msg, type_='normal', timestamp=None):
         """Print general info
         @param msg: message to print
         @type_: one of:
             normal: general info like "toto has joined the room"
             me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
+        @param timestamp (float): number of seconds since epoch
         """
         _font_bold = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.BOLD)
         _font_normal = wx.Font(self.font["points"], self.font["family"], wx.NORMAL, wx.NORMAL)