From 15b44f5eeceef9e001feb4ce87db5ccb5d897437 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 14 Sep 2006 13:31:14 +0000
Subject: [PATCH] detect and print old gc messages as restored messages. Fixes
 #2253

---
 src/common/connection_handlers.py |  7 +++++--
 src/gajim.py                      |  4 ++--
 src/groupchat_control.py          | 22 ++++++++++++++++++++--
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index cf80659739..dc15c9b8e1 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -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
diff --git a/src/gajim.py b/src/gajim.py
index 3730c7f65a..a673c7fbc3 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -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))
 
diff --git a/src/groupchat_control.py b/src/groupchat_control.py
index 0543278061..38e20e5bfe 100644
--- a/src/groupchat_control.py
+++ b/src/groupchat_control.py
@@ -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
-- 
GitLab