From 9351b96cdb0b30874e96cddcaa47b73b139bfff5 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 28 Oct 2012 17:59:24 +0100 Subject: [PATCH] primitivus: fixed info messages timestamp --- frontends/src/primitivus/chat.py | 24 +++++++++++++--------- frontends/src/quick_frontend/quick_chat.py | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/frontends/src/primitivus/chat.py b/frontends/src/primitivus/chat.py index c13b7f77..7b95bf84 100644 --- a/frontends/src/primitivus/chat.py +++ b/frontends/src/primitivus/chat.py @@ -32,13 +32,14 @@ from sat.tools.jid import JID class ChatText(urwid.FlowWidget): """Manage the printing of chat message""" - def __init__(self, parent, timestamp, nick, my_mess, message, align='left'): + def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False): self.parent = parent self.timestamp = time.localtime(timestamp) self.nick = nick self.my_mess = my_mess self.message = unicode(message) self.align = align + self.is_info = is_info def selectable(self): return True @@ -61,13 +62,14 @@ class ChatText(urwid.FlowWidget): def display_widget(self, size, focus): render_txt = [] - if self.parent.show_timestamp: - time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" #if the message was sent before today, we print the full date - render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) - if self.parent.show_short_nick: - render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*")) - else: - render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick)) + if not self.is_info: + if self.parent.show_timestamp: + time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" #if the message was sent before today, we print the full date + render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) + if self.parent.show_short_nick: + render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*")) + else: + render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick)) render_txt.append(self.message) return urwid.Text(render_txt, align=self.align) @@ -272,14 +274,16 @@ class Chat(urwid.WidgetWrap, QuickChat): elif self.getUserNick().lower() in msg.lower(): self.host.x_notify.sendNotification(_("Primitivus: Somebody pinged your name in %s room") % self.target) - def printInfo(self, msg, type='normal'): + def printInfo(self, msg, type='normal', timestamp=""): """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" """ - self.content.append(sat_widgets.ClickableText(msg)) + #FIXME: duplicated code, this must be refactored + _widget = ChatText(self, timestamp or None, None, False, msg, is_info=True) + self.content.append(_widget) if self.text_list.get_focus()[1] == len(self.content)-2: #we don't change focus if user is not at the bottom #as that mean that he is probably watching discussion history diff --git a/frontends/src/quick_frontend/quick_chat.py b/frontends/src/quick_frontend/quick_chat.py index 5bebcd07..cb17f833 100644 --- a/frontends/src/quick_frontend/quick_chat.py +++ b/frontends/src/quick_frontend/quick_chat.py @@ -130,7 +130,7 @@ class QuickChat(): nick = self._get_nick(jid) mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user if msg.startswith('/me '): - self.printInfo('* %s %s' % (nick, msg[4:]),type='me') + self.printInfo('* %s %s' % (nick, msg[4:]),type='me', timestamp=timestamp) return return jid, nick, mymess