Author: bct
Date: 2008-07-26 07:28:15 +0200 (Sat, 26 Jul 2008)
New Revision: 10035
Modified:
trunk/src/common/connection.py
trunk/src/common/connection_handlers.py
trunk/src/gajim.py
trunk/src/message_control.py
trunk/src/session.py
Log:
attach resource to sessions so that only the relevant sessions are terminated when a contact goes offline
Modified: trunk/src/common/connection.py
===================================================================
--- trunk/src/common/connection.py 2008-07-26 01:58:30 UTC (rev 10034)
+++ trunk/src/common/connection.py 2008-07-26 05:28:15 UTC (rev 10035)
@@ -1062,6 +1062,9 @@
msgtxt = msg
msgenc = ''
+ if session:
+ fjid = str(session.jid)
+
if keyID and self.USE_GPG:
if keyID == 'UNKNOWN':
error = _('Neither the remote presence is signed, nor a key was assigned.')
Modified: trunk/src/common/connection_handlers.py
===================================================================
--- trunk/src/common/connection_handlers.py 2008-07-26 01:58:30 UTC (rev 10034)
+++ trunk/src/common/connection_handlers.py 2008-07-26 05:28:15 UTC (rev 10035)
@@ -1226,23 +1226,37 @@
# keep track of sessions this connection has with other JIDs
self.sessions = {}
- def get_or_create_session(self, jid, thread_id):
- '''returns an existing session between this connection and 'jid', returns a new one if none exist.'''
+ def get_sessions(self, jid):
+ '''get all sessions for the given full jid'''
- pm = True
if not gajim.interface.is_pm_contact(jid, self.name):
- pm = False
jid = gajim.get_jid_without_resource(jid)
+ try:
+ return self.sessions[jid].values()
+ except KeyError:
+ return []
+
+ def get_or_create_session(self, fjid, thread_id):
+ '''returns an existing session between this connection and 'jid', returns a
+ new one if none exist.'''
+
+ pm = True
+ jid = fjid
+
+ if not gajim.interface.is_pm_contact(fjid, self.name):
+ pm = False
+ jid = gajim.get_jid_without_resource(fjid)
+
session = self.find_session(jid, thread_id)
if session:
return session
if pm:
- return self.make_new_session(jid, thread_id, type = 'pm')
+ return self.make_new_session(fjid, thread_id, type='pm')
else:
- return self.make_new_session(jid, thread_id)
+ return self.make_new_session(fjid, thread_id)
def find_session(self, jid, thread_id):
try:
@@ -1311,13 +1325,13 @@
if not cls:
cls = gajim.default_session_type
+ sess = cls(self, common.xmpp.JID(jid), thread_id, type)
+
# determine if this session is a pm session
- # if not, discard the resource
+ # if not, discard the resource so that all sessions are stored bare
if not type == 'pm':
jid = gajim.get_jid_without_resource(jid)
- sess = cls(self, common.xmpp.JID(jid), thread_id, type)
-
if not jid in self.sessions:
self.sessions[jid] = {}
Modified: trunk/src/gajim.py
===================================================================
--- trunk/src/gajim.py 2008-07-26 01:58:30 UTC (rev 10034)
+++ trunk/src/gajim.py 2008-07-26 05:28:15 UTC (rev 10035)
@@ -769,10 +769,12 @@
if array[1] in ('offline', 'error'):
contact1.our_chatstate = contact1.chatstate = \
contact1.composing_xep = None
+
+ conn = gajim.connections[account]
+
# TODO: This causes problems when another
# resource signs off!
- gajim.connections[account]. \
- remove_transfers_for_contact(contact1)
+ conn.remove_transfers_for_contact(contact1)
# disable encryption, since if any messages are
# lost they'll be not decryptable (note that
@@ -782,20 +784,16 @@
# FIXME: This *REALLY* are TOO many leves of
# indentation! We even need to introduce
# a temp var here to make it somehow fit!
- if gajim.connections[account].sessions. \
- has_key(ji):
- for sess in gajim.connections \
- [account]. sessions[ji].values():
- ctrl = sess.control
- if ctrl:
- ctrl.no_autonegotiation\
- = False
- if sess.enable_encryption:
- sess.terminate_e2e()
- gajim.connections \
- [account]. \
- delete_session(jid,
- sess.thread_id)
+ 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.enable_encryption:
+ sess.terminate_e2e()
+ conn.delete_session(jid,
+ sess.thread_id)
self.roster.chg_contact_status(contact1, array[1],
status_message, account)
Modified: trunk/src/message_control.py
===================================================================
--- trunk/src/message_control.py 2008-07-26 01:58:30 UTC (rev 10034)
+++ trunk/src/message_control.py 2008-07-26 05:28:15 UTC (rev 10035)
@@ -160,6 +160,9 @@
if not self.session:
sess = conn.find_controlless_session(jid)
+ if self.resource:
+ jid += '/' + self.resource
+
if not sess:
sess = conn.make_new_session(jid)
Modified: trunk/src/session.py
===================================================================
--- trunk/src/session.py 2008-07-26 01:58:30 UTC (rev 10034)
+++ trunk/src/session.py 2008-07-26 05:28:15 UTC (rev 10035)
@@ -440,7 +440,7 @@
form.getField('terminate').getValue() in ('1', 'true'):
self.acknowledge_termination()
- self.conn.delete_session(self.jid, self.thread_id)
+ self.conn.delete_session(str(self.jid), self.thread_id)
return