comparison frontends/src/primitivus/chat.py @ 1389:eb907923dce9

quick_frontend, primivitus: revert changes made in rev 1386 (1f3513cfb246) concerning ChatText.nick: was mixing MUC occupant nick and roster contact nick/node
author souliane <souliane@mailoo.org>
date Wed, 25 Mar 2015 09:42:05 +0100
parents a025242bebe7
children 337be5318177
comparison
equal deleted inserted replaced
1388:a025242bebe7 1389:eb907923dce9
35 35
36 36
37 class ChatText(urwid.FlowWidget): 37 class ChatText(urwid.FlowWidget):
38 """Manage the printing of chat message""" 38 """Manage the printing of chat message"""
39 39
40 def __init__(self, parent, timestamp, my_mess, message, align='left', is_info=False): 40 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False):
41 self.parent = parent 41 self.parent = parent
42 self.timestamp = time.localtime(timestamp) 42 self.timestamp = time.localtime(timestamp)
43 self.nick = nick
43 self.my_mess = my_mess 44 self.my_mess = my_mess
44 self.message = unicode(message) 45 self.message = unicode(message)
45 self.align = align 46 self.align = align
46 self.is_info = is_info 47 self.is_info = is_info
47 48
70 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 71 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
71 render_txt.append(('date', "[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) 72 render_txt.append(('date', "[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8')))
72 if self.parent.show_short_nick: 73 if self.parent.show_short_nick:
73 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "**" if self.my_mess else "*")) 74 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "**" if self.my_mess else "*"))
74 else: 75 else:
75 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "[%s] " % self.parent.nick)) 76 render_txt.append(('my_nick' if self.my_mess else 'other_nick', "[%s] " % self.nick))
76 render_txt.append(self.message) 77 render_txt.append(self.message)
77 txt_widget = urwid.Text(render_txt, align=self.align) 78 txt_widget = urwid.Text(render_txt, align=self.align)
78 if self.is_info: 79 if self.is_info:
79 return urwid.AttrMap(txt_widget, 'info_msg') 80 return urwid.AttrMap(txt_widget, 'info_msg')
80 return txt_widget 81 return txt_widget
297 try: 298 try:
298 nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile) 299 nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile)
299 except TypeError: 300 except TypeError:
300 # None is returned, the message is managed 301 # None is returned, the message is managed
301 return 302 return
302 new_text = ChatText(self, timestamp, mymess, msg) 303 new_text = ChatText(self, timestamp, nick, mymess, msg)
303 304
304 if timestamp and self.content: 305 if timestamp and self.content:
305 for idx in range(len(self.content) - 1, -1, -1): 306 for idx in range(len(self.content) - 1, -1, -1):
306 current_text = self.content[idx] 307 current_text = self.content[idx]
307 older = new_text.timestamp < current_text.timestamp 308 older = new_text.timestamp < current_text.timestamp
337 extra = {} 338 extra = {}
338 try: 339 try:
339 timestamp = float(extra['timestamp']) 340 timestamp = float(extra['timestamp'])
340 except KeyError: 341 except KeyError:
341 timestamp = None 342 timestamp = None
342 _widget = ChatText(self, timestamp, False, msg, is_info=True) 343 _widget = ChatText(self, timestamp, None, False, msg, is_info=True)
343 self.content.append(_widget) 344 self.content.append(_widget)
344 self._notify(msg=msg) 345 self._notify(msg=msg)
345 346
346 def _notify(self, from_jid="somebody", msg=""): 347 def _notify(self, from_jid="somebody", msg=""):
347 """Notify the user of a new message if primitivus doesn't have the focus. 348 """Notify the user of a new message if primitivus doesn't have the focus.