attach resource to sessions so that only the relevant sessions are terminated when a contact goes offline
This commit is contained in:
parent
11b5ce1d04
commit
abbdf8d5c9
5 changed files with 44 additions and 26 deletions
|
@ -1062,6 +1062,9 @@ class Connection(ConnectionHandlers):
|
||||||
msgtxt = msg
|
msgtxt = msg
|
||||||
msgenc = ''
|
msgenc = ''
|
||||||
|
|
||||||
|
if session:
|
||||||
|
fjid = str(session.jid)
|
||||||
|
|
||||||
if keyID and self.USE_GPG:
|
if keyID and self.USE_GPG:
|
||||||
if keyID == 'UNKNOWN':
|
if keyID == 'UNKNOWN':
|
||||||
error = _('Neither the remote presence is signed, nor a key was assigned.')
|
error = _('Neither the remote presence is signed, nor a key was assigned.')
|
||||||
|
|
|
@ -1226,13 +1226,27 @@ class ConnectionHandlersBase:
|
||||||
# keep track of sessions this connection has with other JIDs
|
# keep track of sessions this connection has with other JIDs
|
||||||
self.sessions = {}
|
self.sessions = {}
|
||||||
|
|
||||||
def get_or_create_session(self, jid, thread_id):
|
def get_sessions(self, jid):
|
||||||
'''returns an existing session between this connection and 'jid', returns a new one if none exist.'''
|
'''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
|
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
|
pm = False
|
||||||
jid = gajim.get_jid_without_resource(jid)
|
jid = gajim.get_jid_without_resource(fjid)
|
||||||
|
|
||||||
session = self.find_session(jid, thread_id)
|
session = self.find_session(jid, thread_id)
|
||||||
|
|
||||||
|
@ -1240,9 +1254,9 @@ class ConnectionHandlersBase:
|
||||||
return session
|
return session
|
||||||
|
|
||||||
if pm:
|
if pm:
|
||||||
return self.make_new_session(jid, thread_id, type = 'pm')
|
return self.make_new_session(fjid, thread_id, type='pm')
|
||||||
else:
|
else:
|
||||||
return self.make_new_session(jid, thread_id)
|
return self.make_new_session(fjid, thread_id)
|
||||||
|
|
||||||
def find_session(self, jid, thread_id):
|
def find_session(self, jid, thread_id):
|
||||||
try:
|
try:
|
||||||
|
@ -1311,13 +1325,13 @@ sent a message to.'''
|
||||||
if not cls:
|
if not cls:
|
||||||
cls = gajim.default_session_type
|
cls = gajim.default_session_type
|
||||||
|
|
||||||
|
sess = cls(self, common.xmpp.JID(jid), thread_id, type)
|
||||||
|
|
||||||
# determine if this session is a pm session
|
# 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':
|
if not type == 'pm':
|
||||||
jid = gajim.get_jid_without_resource(jid)
|
jid = gajim.get_jid_without_resource(jid)
|
||||||
|
|
||||||
sess = cls(self, common.xmpp.JID(jid), thread_id, type)
|
|
||||||
|
|
||||||
if not jid in self.sessions:
|
if not jid in self.sessions:
|
||||||
self.sessions[jid] = {}
|
self.sessions[jid] = {}
|
||||||
|
|
||||||
|
|
30
src/gajim.py
30
src/gajim.py
|
@ -769,10 +769,12 @@ class Interface:
|
||||||
if array[1] in ('offline', 'error'):
|
if array[1] in ('offline', 'error'):
|
||||||
contact1.our_chatstate = contact1.chatstate = \
|
contact1.our_chatstate = contact1.chatstate = \
|
||||||
contact1.composing_xep = None
|
contact1.composing_xep = None
|
||||||
|
|
||||||
|
conn = gajim.connections[account]
|
||||||
|
|
||||||
# TODO: This causes problems when another
|
# TODO: This causes problems when another
|
||||||
# resource signs off!
|
# resource signs off!
|
||||||
gajim.connections[account]. \
|
conn.remove_transfers_for_contact(contact1)
|
||||||
remove_transfers_for_contact(contact1)
|
|
||||||
|
|
||||||
# disable encryption, since if any messages are
|
# disable encryption, since if any messages are
|
||||||
# lost they'll be not decryptable (note that
|
# lost they'll be not decryptable (note that
|
||||||
|
@ -782,20 +784,16 @@ class Interface:
|
||||||
# FIXME: This *REALLY* are TOO many leves of
|
# FIXME: This *REALLY* are TOO many leves of
|
||||||
# indentation! We even need to introduce
|
# indentation! We even need to introduce
|
||||||
# a temp var here to make it somehow fit!
|
# a temp var here to make it somehow fit!
|
||||||
if gajim.connections[account].sessions. \
|
for sess in conn.get_sessions(ji):
|
||||||
has_key(ji):
|
if (ji+'/'+resource) != str(sess.jid):
|
||||||
for sess in gajim.connections \
|
continue
|
||||||
[account]. sessions[ji].values():
|
ctrl = sess.control
|
||||||
ctrl = sess.control
|
if ctrl:
|
||||||
if ctrl:
|
ctrl.no_autonegotiation = False
|
||||||
ctrl.no_autonegotiation\
|
if sess.enable_encryption:
|
||||||
= False
|
sess.terminate_e2e()
|
||||||
if sess.enable_encryption:
|
conn.delete_session(jid,
|
||||||
sess.terminate_e2e()
|
sess.thread_id)
|
||||||
gajim.connections \
|
|
||||||
[account]. \
|
|
||||||
delete_session(jid,
|
|
||||||
sess.thread_id)
|
|
||||||
|
|
||||||
self.roster.chg_contact_status(contact1, array[1],
|
self.roster.chg_contact_status(contact1, array[1],
|
||||||
status_message, account)
|
status_message, account)
|
||||||
|
|
|
@ -160,6 +160,9 @@ class MessageControl:
|
||||||
if not self.session:
|
if not self.session:
|
||||||
sess = conn.find_controlless_session(jid)
|
sess = conn.find_controlless_session(jid)
|
||||||
|
|
||||||
|
if self.resource:
|
||||||
|
jid += '/' + self.resource
|
||||||
|
|
||||||
if not sess:
|
if not sess:
|
||||||
sess = conn.make_new_session(jid)
|
sess = conn.make_new_session(jid)
|
||||||
|
|
||||||
|
|
|
@ -440,7 +440,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
|
||||||
form.getField('terminate').getValue() in ('1', 'true'):
|
form.getField('terminate').getValue() in ('1', 'true'):
|
||||||
self.acknowledge_termination()
|
self.acknowledge_termination()
|
||||||
|
|
||||||
self.conn.delete_session(self.jid, self.thread_id)
|
self.conn.delete_session(str(self.jid), self.thread_id)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue