From 5406f8b49c57e1034ff96d15bba08042dbbbcb06 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Fri, 2 Oct 2009 16:47:42 +0200
Subject: [PATCH] improve connection time to muc.

---
 src/common/connection.py | 42 ++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/common/connection.py b/src/common/connection.py
index 6485cd8254..2df4f7a213 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -1754,6 +1754,25 @@ class Connection(ConnectionHandlers):
 		if show == 'invisible':
 			# Never join a room when invisible
 			return
+
+		# last date/time in history to avoid duplicate
+		if room_jid not in self.last_history_time:
+			# Not in memory, get it from DB
+			last_log = None
+			# Do not check if we are not logging for this room
+			if gajim.config.should_log(self.name, room_jid):
+				# Check time first in the FAST table
+				last_log = gajim.logger.get_room_last_message_time(room_jid)
+				if last_log is None:
+					# Not in special table, get it from messages DB
+					last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
+						is_room=True)
+			# Create self.last_history_time[room_jid] even if not logging,
+			# could be used in connection_handlers
+			if last_log is None:
+				last_log = 0
+			self.last_history_time[room_jid] = last_log
+
 		p = common.xmpp.Presence(to = '%s/%s' % (room_jid, nick),
 			show = show, status = self.status)
 		if gajim.config.get('send_sha_in_gc_presence'):
@@ -1761,9 +1780,8 @@ class Connection(ConnectionHandlers):
 		self.add_lang(p)
 		if not change_nick:
 			t = p.setTag(common.xmpp.NS_MUC + ' x')
-			last_date = gajim.logger.get_last_date_that_has_logs(room_jid,
-				self.name, is_room=True)
-			if last_date is None:
+			last_date = self.last_history_time[room_jid]
+			if last_date = 0:
 				last_date = time.time() - gajim.config.get(
 					'muc_restore_timeout') * 60
 			else:
@@ -1776,24 +1794,6 @@ class Connection(ConnectionHandlers):
 				t.setTagData('password', password)
 		self.connection.send(p)
 
-		# last date/time in history to avoid duplicate
-		if room_jid not in self.last_history_time:
-			# Not in memory, get it from DB
-			last_log = None
-			# Do not check if we are not logging for this room
-			if gajim.config.should_log(self.name, room_jid):
-				# Check time first in the FAST table
-				last_log = gajim.logger.get_room_last_message_time(room_jid)
-				if last_log is None:
-					# Not in special table, get it from messages DB
-					last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
-						is_room = True)
-			# Create self.last_history_time[room_jid] even if not logging,
-			# could be used in connection_handlers
-			if last_log is None:
-				last_log = 0
-			self.last_history_time[room_jid]= last_log
-
 	def send_gc_message(self, jid, msg, xhtml = None):
 		if not self.connection:
 			return
-- 
GitLab