From aeff9046abd8c5c612476406abe84663f9d073e0 Mon Sep 17 00:00:00 2001
From: Brendan Taylor <bct@diffeq.com>
Date: Sat, 13 Dec 2008 18:10:37 +0000
Subject: [PATCH] a fix for autonegotiation after esessions were disabled

---
 src/chat_control.py               |  2 ++
 src/common/connection_handlers.py |  4 ++--
 src/common/stanza_session.py      |  4 ++--
 src/gajim.py                      | 15 ++++++---------
 src/session.py                    |  5 ++---
 5 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/src/chat_control.py b/src/chat_control.py
index e7ad80d416..4d5f3c35db 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -1059,6 +1059,8 @@ class ChatControlBase(MessageControl):
 		self.msg_textview.set_sensitive(False)
 		self.msg_textview.set_editable(False)
 		self.conv_textview.tv.grab_focus()
+
+		self.no_autonegotiation = False
 		# FIXME: Set sensitivity for toolbar
 
 ################################################################################
diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index 2531d26708..4e5c21b0de 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -1294,11 +1294,11 @@ class ConnectionHandlersBase:
 		except KeyError:
 			return None
 
-	def terminate_sessions(self):
+	def terminate_sessions(self, send_termination = False):
 		'''send termination messages and delete all active sessions'''
 		for jid in self.sessions:
 			for thread_id in self.sessions[jid]:
-				self.sessions[jid][thread_id].terminate()
+				self.sessions[jid][thread_id].terminate(send_termination)
 
 		self.sessions = {}
 
diff --git a/src/common/stanza_session.py b/src/common/stanza_session.py
index 9f92c2f17f..d0b0f57fc4 100644
--- a/src/common/stanza_session.py
+++ b/src/common/stanza_session.py
@@ -133,10 +133,10 @@ class StanzaSession(object):
 		self.status = None
 		self.negotiated = {}
 
-	def terminate(self):
+	def terminate(self, send_termination = True):
 		# only send termination message if we've sent a message and think they
 		# have XEP-0201 support
-		if self.last_send > 0 and \
+		if send_termination and self.last_send > 0 and \
 		(self.received_thread_id or self.last_receive == 0):
 			msg = xmpp.Message()
 			feature = msg.NT.feature
diff --git a/src/gajim.py b/src/gajim.py
index cd4a9a3546..5190b8b06f 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -842,20 +842,17 @@ class Interface:
 				# lost they'll be not decryptable (note that
 				# this contradicts XEP-0201 - trying to get that
 				# in the XEP, though)
-				#
-				# FIXME: This *REALLY* are TOO many leves of
-				#	 indentation! We even need to introduce
-				#	 a temp var here to make it somehow fit!
+
+				# there won't be any sessions here if the contact terminated
+				# their sessions before going offline (which we do)
 				for sess in conn.get_sessions(ji):
 					if (ji+'/'+resource) != str(sess.jid):
 						continue
-					ctrl = sess.control
-					if ctrl:
-						ctrl.no_autonegotiation = False
+					if sess.control:
+						sess.control.no_autonegotiation = False
 					if sess.enable_encryption:
 						sess.terminate_e2e()
-						conn.delete_session(jid,
-						sess.thread_id)
+						conn.delete_session(jid, sess.thread_id)
 
 			self.roster.chg_contact_status(contact1, array[1], status_message,
 				account)
diff --git a/src/session.py b/src/session.py
index ed56aa3229..1e7fe91eb4 100644
--- a/src/session.py
+++ b/src/session.py
@@ -46,15 +46,14 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
 
 	def detach_from_control(self):
 		if self.control:
-			self.control.no_autonegotiation = False
 			self.control.set_session(None)
 
 	def acknowledge_termination(self):
 		self.detach_from_control()
 		stanza_session.EncryptedStanzaSession.acknowledge_termination(self)
 
-	def terminate(self):
-		stanza_session.EncryptedStanzaSession.terminate(self)
+	def terminate(self, send_termination = True):
+		stanza_session.EncryptedStanzaSession.terminate(self, send_termination)
 		self.detach_from_control()
 
 	def get_chatstate(self, msg, msgtxt):
-- 
GitLab