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

View file

@ -893,7 +893,7 @@ class Interface:
def handle_event_gc_msg(self, account, array): 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) jids = array[0].split('/', 1)
room_jid = jids[0] room_jid = jids[0]
gc_control = self.msg_win_mgr.get_control(room_jid, account) gc_control = self.msg_win_mgr.get_control(room_jid, account)
@ -905,7 +905,7 @@ class Interface:
else: else:
# message from someone # message from someone
nick = jids[1] 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: if self.remote_ctrl:
self.remote_ctrl.raise_signal('GCMessage', (account, array)) self.remote_ctrl.raise_signal('GCMessage', (account, array))

View file

@ -430,12 +430,15 @@ class GroupchatControl(ChatControlBase):
childs[3].set_sensitive(False) childs[3].set_sensitive(False)
return menu return menu
def on_message(self, nick, msg, tim): def on_message(self, nick, msg, tim, has_timestamp = False):
if not nick: if not nick:
# message from server # message from server
self.print_conversation(msg, tim = tim) self.print_conversation(msg, tim = tim)
else: else:
# message from someone # message from someone
if has_timestamp:
self.print_old_conversation(msg, nick, tim)
else:
self.print_conversation(msg, nick, tim) self.print_conversation(msg, nick, tim)
def on_private_message(self, nick, msg, tim): def on_private_message(self, nick, msg, tim):
@ -499,6 +502,21 @@ class GroupchatControl(ChatControlBase):
gc_count_nicknames_colors = 0 gc_count_nicknames_colors = 0
gc_custom_colors = {} 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): def print_conversation(self, text, contact = '', tim = None):
'''Print a line in the conversation: '''Print a line in the conversation:
if contact is set: it's a message from someone or an info message (contact if contact is set: it's a message from someone or an info message (contact