primitivus: fixed info messages timestamp
This commit is contained in:
parent
58c9328742
commit
9351b96cdb
2 changed files with 15 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue