attach resource to sessions so that only the relevant sessions are terminated when a contact goes offline

This commit is contained in:
Brendan Taylor 2008-07-26 05:28:15 +00:00
parent 11b5ce1d04
commit abbdf8d5c9
5 changed files with 44 additions and 26 deletions

View File

@ -1062,6 +1062,9 @@ class Connection(ConnectionHandlers):
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.')

View File

@ -1226,13 +1226,27 @@ class ConnectionHandlersBase:
# 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'''
if not gajim.interface.is_pm_contact(jid, self.name):
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
if not gajim.interface.is_pm_contact(jid, self.name):
jid = fjid
if not gajim.interface.is_pm_contact(fjid, self.name):
pm = False
jid = gajim.get_jid_without_resource(jid)
jid = gajim.get_jid_without_resource(fjid)
session = self.find_session(jid, thread_id)
@ -1240,9 +1254,9 @@ class ConnectionHandlersBase:
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 @@ sent a message to.'''
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] = {}

View File

@ -769,10 +769,12 @@ class Interface:
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 @@ class Interface:
# 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)

View File

@ -160,6 +160,9 @@ class MessageControl:
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)

View File

@ -440,7 +440,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
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