detect and print old gc messages as restored messages. Fixes #2253

This commit is contained in:
Yann Leboulanger 2006-09-14 13:31:14 +00:00
parent e18e1079a9
commit 15b44f5eec
3 changed files with 27 additions and 6 deletions

View file

@ -1387,7 +1387,10 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
# Ignore message from room in which we are not
if not self.last_history_line.has_key(jid):
return
self.dispatch('GC_MSG', (frm, msgtxt, tim))
has_timestamp = False
if msg.timestamp:
has_timestamp = True
self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp))
if self.name not in no_log_for and not int(float(time.mktime(tim))) <= \
self.last_history_line[jid] and msgtxt:
gajim.logger.write('gc_msg', frm, msgtxt, tim = tim)
@ -1431,7 +1434,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
who = str(prs.getFrom())
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
self.dispatch('GC_MSG', (jid_stripped, _('Nickname not allowed: %s') % \
resource, None))
resource, None, False))
return
jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
timestamp = None

View file

@ -893,7 +893,7 @@ class Interface:
def handle_event_gc_msg(self, account, array):
# ('GC_MSG', account, (jid, msg, time))
# ('GC_MSG', account, (jid, msg, time, has_timestamp))
jids = array[0].split('/', 1)
room_jid = jids[0]
gc_control = self.msg_win_mgr.get_control(room_jid, account)
@ -905,7 +905,7 @@ class Interface:
else:
# message from someone
nick = jids[1]
gc_control.on_message(nick, array[1], array[2])
gc_control.on_message(nick, array[1], array[2], array[3])
if self.remote_ctrl:
self.remote_ctrl.raise_signal('GCMessage', (account, array))

View file

@ -430,13 +430,16 @@ class GroupchatControl(ChatControlBase):
childs[3].set_sensitive(False)
return menu
def on_message(self, nick, msg, tim):
def on_message(self, nick, msg, tim, has_timestamp = False):
if not nick:
# message from server
self.print_conversation(msg, tim = tim)
else:
# message from someone
self.print_conversation(msg, nick, tim)
if has_timestamp:
self.print_old_conversation(msg, nick, tim)
else:
self.print_conversation(msg, nick, tim)
def on_private_message(self, nick, msg, tim):
# Do we have a queue?
@ -499,6 +502,21 @@ class GroupchatControl(ChatControlBase):
gc_count_nicknames_colors = 0
gc_custom_colors = {}
def print_old_conversation(self, text, contact, tim = None):
if isinstance(text, str):
text = unicode(text, 'utf-8')
if contact == self.nick: # it's us
kind = 'outgoing'
else:
kind = 'incoming'
if gajim.config.get('restored_messages_small'):
small_attr = ['small']
else:
small_attr = []
ChatControlBase.print_conversation_line(self, text, kind, contact, tim,
small_attr, small_attr + ['restored_message'],
small_attr + ['restored_message'])
def print_conversation(self, text, contact = '', tim = None):
'''Print a line in the conversation:
if contact is set: it's a message from someone or an info message (contact