frontends: printInfo and printMessage timestamp attribute defaults to None instead of ''

This commit is contained in:
souliane 2014-10-04 10:23:13 +02:00
commit 7a344fcf5d
4 changed files with 15 additions and 11 deletions

View file

@ -290,14 +290,14 @@ class Chat(urwid.WidgetWrap, QuickChat):
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 @@ class Chat(urwid.WidgetWrap, QuickChat):
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 @@ class Chat(urwid.WidgetWrap, QuickChat):
# 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)

View file

@ -308,9 +308,9 @@ class QuickApp(object):
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):

View file

@ -134,9 +134,9 @@ class QuickChat(object):
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 @@ class QuickChat(object):
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

View file

@ -217,7 +217,7 @@ class Chat(wx.Frame, QuickChat):
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 @@ class Chat(wx.Frame, QuickChat):
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)