changeset 0a69089d0236 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=0a69089d0236
description: better session handling:
         - when a new contact with higher prio connect, detach session from 
chat control. Fixes #5021
         - don't re-use a session that was for another sessin

        Tests are more than welcome!

diffstat:

 src/chat_control.py               |  14 ++++++--------
 src/common/connection_handlers.py |  38 ++++++++++++++++++++++----------------
 src/common/stanza_session.py      |   2 +-
 src/gajim.py                      |   4 ++--
 src/message_control.py            |   7 ++++++-
 src/session.py                    |   5 +++--
 6 files changed, 40 insertions(+), 30 deletions(-)

diffs (171 lines):

diff -r d52c4a77b55b -r 0a69089d0236 src/chat_control.py
--- a/src/chat_control.py       Tue Oct 06 11:41:32 2009 +0200
+++ b/src/chat_control.py       Tue Oct 06 17:35:25 2009 +0200
@@ -1287,14 +1287,12 @@
                self.handlers[id_] = widget
 
                if not session:
-                       session = gajim.connections[self.account]. \
-                               find_controlless_session(self.contact.jid)
-                       if session:
-                               # Don't use previous session if we want to a 
specific resource
-                               # and it's not the same
-                               r = 
gajim.get_room_and_nick_from_fjid(str(session.jid))[1]
-                               if resource and resource != r:
-                                       session = None
+                       # Don't use previous session if we want to a specific 
resource
+                       # and it's not the same
+                       if not resource:
+                               resource = contact.resource
+                       session = 
gajim.connections[self.account].find_controlless_session(
+                               self.contact.jid, resource)
 
                if session:
                        session.control = self
diff -r d52c4a77b55b -r 0a69089d0236 src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Tue Oct 06 11:41:32 2009 +0200
+++ b/src/common/connection_handlers.py Tue Oct 06 17:35:25 2009 +0200
@@ -1408,12 +1408,11 @@
 
                if chat_sessions:
                        # return the session that we last sent a message in
-                       return sorted(chat_sessions,
-                               key=operator.attrgetter("last_send"))[-1]
+                       return sorted(chat_sessions, 
key=operator.attrgetter("last_send"))[-1]
                else:
                        return None
 
-       def find_controlless_session(self, jid):
+       def find_controlless_session(self, jid, resource=None):
                '''find an active session that doesn't have a control 
attached'''
 
                try:
@@ -1425,6 +1424,9 @@
 
                        orphaned = [s for s in chat_sessions if not s.control]
 
+                       if resource:
+                               orphaned = [s for s in orphaned if s.resource 
== resource]
+
                        return orphaned[0]
                except (KeyError, IndexError):
                        return None
@@ -2184,7 +2186,8 @@
                ptype = prs.getType()
                if ptype == 'available':
                        ptype = None
-               rfc_types = ('unavailable', 'error', 'subscribe', 'subscribed', 
'unsubscribe', 'unsubscribed')
+               rfc_types = ('unavailable', 'error', 'subscribe', 'subscribed',
+                       'unsubscribe', 'unsubscribed')
                if ptype and not ptype in rfc_types:
                        ptype = None
                log.debug('PresenceCB: %s' % ptype)
@@ -2432,19 +2435,22 @@
                                self.dispatch('NOTIFY', (jid_stripped, 'error', 
errmsg, resource,
                                        prio, keyID, timestamp, None))
 
-               if ptype == 'unavailable' and jid_stripped in self.sessions:
-                       # automatically terminate sessions that they haven't 
sent a thread ID
-                       # in, only if other part support thread ID
-                       for sess in self.sessions[jid_stripped].values():
-                               if not sess.received_thread_id:
-                                       contact = 
gajim.contacts.get_contact(self.name, jid_stripped)
+               if ptype == 'unavailable':
+                       for jid in [jid_stripped, who]:
+                               if jid not in self.sessions:
+                                       continue
+                               # automatically terminate sessions that they 
haven't sent a thread
+                               # ID in, only if other part support thread ID
+                               for sess in self.sessions[jid].values():
+                                       if not sess.received_thread_id:
+                                               contact = 
gajim.contacts.get_contact(self.name, jid)
 
-                                       session_supported = 
gajim.capscache.is_supported(contact,
-                                               common.xmpp.NS_SSN) or 
gajim.capscache.is_supported(contact,
-                                               common.xmpp.NS_ESESSION)
-                                       if session_supported:
-                                               sess.terminate()
-                                               del 
self.sessions[jid_stripped][sess.thread_id]
+                                               session_supported = 
gajim.capscache.is_supported(contact,
+                                                       common.xmpp.NS_SSN) or 
gajim.capscache.is_supported(
+                                                       contact, 
common.xmpp.NS_ESESSION)
+                                               if session_supported:
+                                                       sess.terminate()
+                                                       del 
self.sessions[jid][sess.thread_id]
 
                if avatar_sha is not None and ptype != 'error':
                        if jid_stripped not in self.vcard_shas:
diff -r d52c4a77b55b -r 0a69089d0236 src/common/stanza_session.py
--- a/src/common/stanza_session.py      Tue Oct 06 11:41:32 2009 +0200
+++ b/src/common/stanza_session.py      Tue Oct 06 17:35:25 2009 +0200
@@ -79,7 +79,7 @@
 
        def get_to(self):
                to = str(self.jid)
-               if self.resource:
+               if self.resource and not to.endswith(self.resource):
                        to += '/' + self.resource
                return to
 
diff -r d52c4a77b55b -r 0a69089d0236 src/gajim.py
--- a/src/gajim.py      Tue Oct 06 11:41:32 2009 +0200
+++ b/src/gajim.py      Tue Oct 06 17:35:25 2009 +0200
@@ -746,9 +746,9 @@
                                        lcontact.append(contact1)
                                elif contact1.show in statuss:
                                        old_show = statuss.index(contact1.show)
-                               # FIXME: What am I?
                                if (resources != [''] and (len(lcontact) != 1 
or \
                                lcontact[0].show != 'offline')) and 
jid.find('@') > 0:
+                                       # Another resource of an existing 
contact connected
                                        old_show = 0
                                        contact1 = 
gajim.contacts.copy_contact(contact1)
                                        lcontact.append(contact1)
@@ -883,6 +883,7 @@
                        ctrl = self.msg_win_mgr.get_control(jid, account)
 
                        if ctrl:
+                               ctrl.no_autonegotiation = False
                                ctrl.set_session(None)
                                ctrl.contact = highest
 
@@ -2945,7 +2946,6 @@
 
        def on_open_chat_window(self, widget, contact, account, resource=None,
        session=None):
-
                # Get the window containing the chat
                fjid = contact.jid
 
diff -r d52c4a77b55b -r 0a69089d0236 src/message_control.py
--- a/src/message_control.py    Tue Oct 06 11:41:32 2009 +0200
+++ b/src/message_control.py    Tue Oct 06 17:35:25 2009 +0200
@@ -182,7 +182,12 @@
                conn = gajim.connections[self.account]
 
                if not self.session:
-                       sess = conn.find_controlless_session(jid)
+                       if not resource:
+                               if self.resource:
+                                       resource = self.resource
+                               else:
+                                       resource = self.contact.resource
+                       sess = conn.find_controlless_session(jid, 
resource=resource)
 
                        if self.resource:
                                jid += '/' + self.resource
diff -r d52c4a77b55b -r 0a69089d0236 src/session.py
--- a/src/session.py    Tue Oct 06 11:41:32 2009 +0200
+++ b/src/session.py    Tue Oct 06 17:35:25 2009 +0200
@@ -86,8 +86,9 @@
                '''dispatch a received <message> stanza'''
                msg_type = msg.getType()
                subject = msg.getSubject()
-               if self.jid != full_jid_with_resource:
-                       self.resource = 
gajim.get_nick_from_fjid(full_jid_with_resource)
+               resource = gajim.get_nick_from_fjid(full_jid_with_resource)
+               if self.resource != resource:
+                       self.resource = resource
                        if self.control and self.control.resource:
                                self.control.change_resource(self.resource)
 
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to