diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 9e3c5c9a0..304a3561c 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -1696,10 +1696,13 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, return None def delete_session(self, jid, thread_id): - del self.sessions[jid][thread_id] - - if not self.sessions[jid]: - del self.sessions[jid] + try: + del self.sessions[jid][thread_id] + + if not self.sessions[jid]: + del self.sessions[jid] + except KeyError + print "jid %s should have been in %s, but it wasn't. missing session?" % (repr(jid), repr(self.sessions.keys()) def move_session(self, original_jid, thread_id, to_resource): '''moves a session to another resource.''' @@ -1722,9 +1725,12 @@ returns the session that we last sent a message to.''' sessions_with_jid = self.sessions[jid].values() no_threadid_sessions = filter(lambda s: not s.received_thread_id, sessions_with_jid) - no_threadid_sessions.sort(key=lambda s: s.last_send) - return no_threadid_sessions[-1] + if no_threadid_sessions: + no_threadid_sessions.sort(key=lambda s: s.last_send) + return no_threadid_sessions[-1] + else: + return None def make_new_session(self, jid, thread_id = None, type = 'chat'): sess = EncryptedStanzaSession(self, common.xmpp.JID(jid), thread_id, type) diff --git a/src/message_control.py b/src/message_control.py index 4489599fb..2914f952b 100644 --- a/src/message_control.py +++ b/src/message_control.py @@ -117,7 +117,7 @@ class MessageControl: if self.session: print "starting a new session, dropping the old one!" - gajim.connections[self.account].delete_session(self.contact.get_full_jid(), self.session.thread_id) + gajim.connections[self.account].delete_session(self.session.jid, self.session.thread_id) self.session = session