From 90e55618605387bf679d93b1469f43fd6b089473 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Sat, 1 Apr 2006 18:16:06 +0000
Subject: [PATCH] JEP 0091 support: timestamp in presences. Fixes #1675

---
 src/common/connection_handlers.py | 16 +++++++++++-----
 src/gajim.py                      |  8 ++++++--
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index c11526655d..fe09dc5ef0 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -1299,6 +1299,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
 		if ptype == 'available':
 			ptype = None
 		gajim.log.debug('PresenceCB: %s' % ptype)
+		timestamp = None
 		is_gc = False # is it a GC presence ?
 		sigTag = None
 		avatar_sha = None
@@ -1310,6 +1311,11 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
 				sigTag = x
 			if x.getNamespace() == common.xmpp.NS_VCARD_UPDATE:
 				avatar_sha = x.getTagData('photo')
+			if x.getNamespace() == common.xmpp.NS_DELAY:
+				# JEP-0091
+				tim = prs.getTimestamp()
+				tim = time.strptime(tim, '%Y%m%dT%H:%M:%S')
+				timstamp = time.localtime(timegm(tim))
 
 		who = helpers.get_full_jid_from_iq(prs)
 		jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who)
@@ -1340,7 +1346,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
 				errcode = prs.getErrorCode()
 				if errcode == '502': # Internal Timeout:
 					self.dispatch('NOTIFY', (jid_stripped, 'error', errmsg, resource,
-						prio, keyID))
+						prio, keyID, timestamp))
 				elif errcode == '401': # password required to join
 					self.dispatch('ERROR', (_('Unable to join room'),
 						_('A password is required to join this room.')))
@@ -1389,8 +1395,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
 					p = self.add_sha(p)
 					self.connection.send(p)
 				if who.find("@") <= 0:
-					self.dispatch('NOTIFY',
-						(jid_stripped, 'offline', 'offline', resource, prio, keyID))
+					self.dispatch('NOTIFY', (jid_stripped, 'offline', 'offline',
+						resource, prio, keyID, timestamp))
 			else:
 				if not status:
 					status = _('I would like to add you to my roster.')
@@ -1409,7 +1415,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
 			errcode = prs.getErrorCode()
 			if errcode == '502': # Internal Timeout:
 				self.dispatch('NOTIFY', (jid_stripped, 'error', errmsg, resource,
-					prio, keyID))
+					prio, keyID, timestamp))
 			else:	# print in the window the error
 				self.dispatch('ERROR_ANSWER', ('', jid_stripped,
 					errmsg, errcode))
@@ -1426,7 +1432,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
 				not in no_log_for and jid_stripped not in no_log_for:
 				gajim.logger.write('status', jid_stripped, status, show)
 			self.dispatch('NOTIFY', (jid_stripped, show, status, resource, prio,
-				keyID))
+				keyID, timestamp))
 	# END presenceCB
 	def _StanzaArrivedCB(self, con, obj):
 		self.last_io = gajim.idlequeue.current_time()
diff --git a/src/gajim.py b/src/gajim.py
index 4a6dc4b43c..f61a56869a 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -302,7 +302,7 @@ class Interface:
 	
 	def handle_event_notify(self, account, array):
 		# 'NOTIFY' (account, (jid, status, status message, resource, priority,
-		# keyID))
+		# keyID, timestamp))
 		# if we're here it means contact changed show
 		statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
 			'invisible']
@@ -374,7 +374,11 @@ class Interface:
 			contact1.status = status_message
 			contact1.priority = priority
 			contact1.keyID = keyID
-			if contact1.jid not in gajim.newly_added[account]:
+			timestamp = array[6]
+			if timestamp:
+				contact1.last_status_time = timestamp
+			elif not gajim.block_signed_in_notifications[account]:
+				# We're connected since more that 30 seconds
 				contact1.last_status_time = time.localtime()
 		if gajim.jid_is_transport(jid):
 			# It must be an agent
-- 
GitLab