]> code.delx.au - pymsnt/blobdiff - src/legacy/glue.py
Fixed exception with adding contacts before the session was ready.
[pymsnt] / src / legacy / glue.py
index d9dbdd17432f821fc8115ef98b3ce6492f2fff21..c27807919b6f7be07f775b0413b3591a97f42703 100644 (file)
@@ -3,7 +3,7 @@
 
 import os.path
 import utils
 
 import os.path
 import utils
-from twisted.internet import task
+from twisted.internet import task, error
 from tlib.xmlw import Element
 from tlib import msn
 from debug import LogEvent, INFO, WARN, ERROR
 from tlib.xmlw import Element
 from tlib import msn
 from debug import LogEvent, INFO, WARN, ERROR
@@ -18,7 +18,7 @@ import lang
 
 
 url = "http://msn-transport.jabberstudio.org"
 
 
 url = "http://msn-transport.jabberstudio.org"
-version = "0.11-dev"         # The transport version
+version = "0.11.2-dev"       # The transport version
 mangle = True            # XDB '@' -> '%' mangling
 id = "msn"               # The transport identifier
 
 mangle = True            # XDB '@' -> '%' mangling
 id = "msn"               # The transport identifier
 
@@ -36,6 +36,7 @@ defaultAvatar = avatar.AvatarCache().setAvatar(defaultAvatarData)
 
 def reloadConfig():
        msn.MSNConnection.GETALLAVATARS = config.getAllAvatars
 
 def reloadConfig():
        msn.MSNConnection.GETALLAVATARS = config.getAllAvatars
+       msn.setDebug(config._debugLevel >= 4)
 
 def isGroupJID(jid):
        """ Returns True if the JID passed is a valid groupchat JID (for MSN, does not contain '%') """
 
 def isGroupJID(jid):
        """ Returns True if the JID passed is a valid groupchat JID (for MSN, does not contain '%') """
@@ -108,10 +109,10 @@ def msn2jid(msnid, withResource):
        else:
                if msnid.startswith("tel:+"):
                        msnid = msnid.replace("tel:+", "") + "%tel"
        else:
                if msnid.startswith("tel:+"):
                        msnid = msnid.replace("tel:+", "") + "%tel"
-               jid = msnid.replace('@', '%') + "@" + config.jid + (withResource and "/msn" or "")
+               jid = msnid.replace('@', '%') + "@" + config.jid
                msn2jid_cache[msnid] = jid
                jid2msn_cache[jid] = msnid
                msn2jid_cache[msnid] = jid
                jid2msn_cache[jid] = msnid
-               return jid
+               return msn2jid(msnid, withResource)
 
 # Marks this as the function to be used in jabber:iq:gateway (Service ID Translation)
 def translateAccount(msnid):
 
 # Marks this as the function to be used in jabber:iq:gateway (Service ID Translation)
 def translateAccount(msnid):
@@ -127,7 +128,7 @@ def jid2msn(jid):
                msnid = jid2msn_cache[jid]
                return msnid
        else:
                msnid = jid2msn_cache[jid]
                return msnid
        else:
-               if jid.index("%tel@") > 0:
+               if jid.find("%tel@") > 0:
                        jid = "tel:+" + jid.replace("%tel@", "@")
                msnid = unicode(jid[:jid.find('@')].replace('%', '@')).split("/")[0]
                jid2msn_cache[jid] = msnid
                        jid = "tel:+" + jid.replace("%tel@", "@")
                msnid = unicode(jid[:jid.find('@')].replace('%', '@')).split("/")[0]
                jid2msn_cache[jid] = msnid
@@ -378,8 +379,9 @@ class LegacyConnection(msn.MSNConnection):
        
        def connectionLost(self, reason):
                LogEvent(INFO, self.jabberID)
        
        def connectionLost(self, reason):
                LogEvent(INFO, self.jabberID)
-               text = lang.get(self.session.lang).msnDisconnected % reason
-               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
+               if reason.type != error.ConnectionDone:
+                       text = lang.get(self.session.lang).msnDisconnected % reason
+                       self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
                self.session.removeMe() # Tear down the session
 
        def multipleLogin(self):
                self.session.removeMe() # Tear down the session
 
        def multipleLogin(self):
@@ -403,13 +405,13 @@ class LegacyConnection(msn.MSNConnection):
        
        def loggedIn(self):
                LogEvent(INFO, self.jabberID)
        
        def loggedIn(self):
                LogEvent(INFO, self.jabberID)
-               self.session.ready = True
        
        def listSynchronized(self):
                LogEvent(INFO, self.jabberID)
                self.session.sendPresence(to=self.jabberID, fro=config.jid)
                self.legacyList.syncJabberLegacyLists()
                self.listSynced = True
        
        def listSynchronized(self):
                LogEvent(INFO, self.jabberID)
                self.session.sendPresence(to=self.jabberID, fro=config.jid)
                self.legacyList.syncJabberLegacyLists()
                self.listSynced = True
+               self.session.ready = True
                #self.legacyList.flushSubscriptionBuffer()
        
        def ourStatusChanged(self, statusCode, screenName, personal):
                #self.legacyList.flushSubscriptionBuffer()
        
        def ourStatusChanged(self, statusCode, screenName, personal):
@@ -550,16 +552,20 @@ class LegacyList:
        def __init__(self, session):
                self.jabberID = session.jabberID
                self.session = session
        def __init__(self, session):
                self.jabberID = session.jabberID
                self.session = session
-               self.subscriptionBuffer = []
        
        def removeMe(self):
        
        def removeMe(self):
-               self.subscriptionBuffer = None
                self.session = None
 
        def addContact(self, jid):
                LogEvent(INFO, self.jabberID)
                userHandle = jid2msn(jid)
                self.session.legacycon.addContact(msn.FORWARD_LIST, userHandle)
                self.session = None
 
        def addContact(self, jid):
                LogEvent(INFO, self.jabberID)
                userHandle = jid2msn(jid)
                self.session.legacycon.addContact(msn.FORWARD_LIST, userHandle)
+
+               # Handle adding a contact that has previously been removed
+               msnContact = self.session.legacycon.getContacts().getContact(userHandle)
+               if msnContact and msnContact.lists & msn.REVERSE_LIST:
+                       self.session.legacycon.contactAddedMe(userHandle)
+               self.authContact(jid)
                self.session.contactList.getContact(jid).contactGrantsAuth()
        
        def removeContact(self, jid):
                self.session.contactList.getContact(jid).contactGrantsAuth()
        
        def removeContact(self, jid):
@@ -570,12 +576,12 @@ class LegacyList:
        
        def authContact(self, jid):
                LogEvent(INFO, self.jabberID)
        
        def authContact(self, jid):
                LogEvent(INFO, self.jabberID)
-               jid = jid2msn(jid)
-               d = self.session.legacycon.remContact(msn.PENDING_LIST, jid)
+               userHandle = jid2msn(jid)
+               d = self.session.legacycon.remContact(msn.PENDING_LIST, userHandle)
                if d:
                if d:
-                       self.session.legacycon.addContact(msn.REVERSE_LIST, jid)
-               self.session.legacycon.remContact(msn.BLOCK_LIST, jid)
-               self.session.legacycon.addContact(msn.ALLOW_LIST, jid)
+                       self.session.legacycon.addContact(msn.REVERSE_LIST, userHandle)
+               self.session.legacycon.remContact(msn.BLOCK_LIST, userHandle)
+               self.session.legacycon.addContact(msn.ALLOW_LIST, userHandle)
        
        def deauthContact(self, jid):
                LogEvent(INFO, self.jabberID)
        
        def deauthContact(self, jid):
                LogEvent(INFO, self.jabberID)