]> code.delx.au - pymsnt/blobdiff - src/tlib/msn/msn.py
Hurrah for unit testing
[pymsnt] / src / tlib / msn / msn.py
index a328a604d6c72a117b314b6e1f3309be1e32ee46..62d645b06927943a5efd50e46ca91a125ba1a912 100644 (file)
@@ -109,7 +109,10 @@ from twisted.internet.defer import Deferred
 from twisted.internet.protocol import ClientFactory
 from twisted.internet.ssl import ClientContextFactory
 from twisted.python import failure, log
-from twisted.xish.domish import unescapeFromXml, SuxElementStream
+from twisted.xish.domish import unescapeFromXml
+
+# Compat stuff
+from tlib import xmlw
 
 # System imports
 import types, operator, os, sys, base64, random
@@ -496,6 +499,7 @@ class MSNContactList:
         self.groups = {}
         self.autoAdd = 0
         self.privacy = 0
+        self.version = 0
 
     def _getContactsFromList(self, listType):
         """
@@ -856,7 +860,7 @@ class NotificationClient(MSNEventBase):
         self.gotRealtimeEmailNotification(mailfrom, fromaddr, subject)
 
     def _gotMSNAlert(self, message):
-        notification = utils.parseText(message.message, beExtremelyLenient=True)
+        notification = xmlw.parseText(message.message, beExtremelyLenient=True)
         siteurl = notification.getAttribute("siteurl")
         notid = notification.getAttribute("id")
 
@@ -962,7 +966,7 @@ class NotificationClient(MSNEventBase):
     def handle_CHG(self, params):
         id = int(params[0])
         if not self._fireCallback(id, params[1]):
-            self.factory.status = statusCode
+            self.factory.status = params[1]
             self.statusChanged(params[1])
 
     def handle_ILN(self, params):
@@ -973,7 +977,7 @@ class NotificationClient(MSNEventBase):
         msnContact.screenName = unquote(params[3])
         if len(params) > 4: msnContact.caps = int(params[4])
         if len(params) > 5: self.handleAvatarHelper(msnContact, params[5])
-        self.contactStatusChanged(params[1], params[2], unquote(params[3]))
+        self.gotContactStatus(params[1], params[2], unquote(params[3]))
 
     def handleAvatarHelper(self, msnContact, msnobjStr):
         s = unquote(msnobjStr)
@@ -1006,7 +1010,7 @@ class NotificationClient(MSNEventBase):
 
     def handle_FLN(self, params):
         checkParamLen(len(params), 1, 'FLN')
-        msnContact = self.factory.contacts.getContact(userHandle)
+        msnContact = self.factory.contacts.getContact(params[0])
         if msnContact:
             msnContact.status = STATUS_OFFLINE
         self.contactOffline(params[0])
@@ -1022,7 +1026,7 @@ class NotificationClient(MSNEventBase):
             if p[0] == 'N':
                 userHandle = getVal(p)
             elif p[0] == 'F':
-                screenName = getVal(p)
+                screenName = unquote(getVal(p))
             elif p[0] == 'C':
                 userGuid = getVal(p)
             elif p.isdigit():
@@ -1110,8 +1114,10 @@ class NotificationClient(MSNEventBase):
         if numParams == 2: # part of a syn
             self._getStateData('last_contact').setPhone(params[0], unquote(params[1]))
         elif numParams == 4:
+            self.factory.contacts.version = int(params[0])
+            userHandle, phoneType, number = params[1], params[2], unquote(params[3])
             self.factory.contacts.getContact(userHandle).setPhone(phoneType, number)
-            self.gotPhoneNumber(params[1], params[2], unquote(params[3]))
+            self.gotPhoneNumber(userHandle, phoneType, number)
 
 
     def handle_ADG(self, params):
@@ -1307,11 +1313,19 @@ class NotificationClient(MSNEventBase):
         """
         pass
 
+    def gotContactStatus(self, statusCode, userHandle, screenName):
+        """
+        Called when we receive a list of statuses upon login.
+
+        @param statusCode: 3-letter status code
+        @param userHandle: the contact's user handle (passport)
+        @param screenName: the contact's screen name
+        """
+        pass
+
     def contactStatusChanged(self, statusCode, userHandle, screenName):
         """
         Called when we're notified that a contact's status has changed.
-        By default we will update the status attribute and screenName 
-        of the contact stored on the factory.
 
         @param statusCode: 3-letter status code
         @param userHandle: the contact's user handle (passport)