+ 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)
+
+ # 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):
+ LogEvent(INFO, self.jabberID)
+ jid = jid2msn(jid)
+ self.session.legacycon.remContact(msn.FORWARD_LIST, jid)
+
+
+ def authContact(self, jid):
+ LogEvent(INFO, self.jabberID)
+ userHandle = jid2msn(jid)
+ d = self.session.legacycon.remContact(msn.PENDING_LIST, userHandle)
+ if d:
+ 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)
+ jid = jid2msn(jid)
+ self.session.legacycon.remContact(msn.ALLOW_LIST, jid)
+ self.session.legacycon.remContact(msn.PENDING_LIST, jid)
+ self.session.legacycon.addContact(msn.BLOCK_LIST, jid)
+
+
+
+ def syncJabberLegacyLists(self):
+ """ Synchronises the MSN contact list on server with the Jabber contact list """
+
+ global defaultAvatar
+
+ # We have to make an MSNContactList from the XDB data, then compare it with the one the server sent
+ # Any subscription changes must be sent to the client, as well as changed in the XDB
+ LogEvent(INFO, self.jabberID, "Start.")
+ result = self.session.pytrans.xdb.request(self.jabberID, disco.IQROSTER)
+ oldContactList = msn.MSNContactList()
+ if result:
+ for item in result.elements():
+ user = item.getAttribute("jid")
+ sub = item.getAttribute("subscription")
+ lists = item.getAttribute("lists")
+ if not lists:
+ lists = jabsub2msnlist(sub) # Backwards compatible
+ lists = int(lists)
+ contact = msn.MSNContact(userHandle=user, screenName="", lists=lists)
+ oldContactList.addContact(contact)
+
+ newXDB = Element((None, "query"))
+ newXDB.attributes["xmlns"] = disco.IQROSTER
+
+ contactList = self.session.legacycon.getContacts()
+
+
+ # Convienence functions
+ def addedToList(num):
+ return (not (oldLists & num) and (lists & num))
+ def removedFromList(num):
+ return ((oldLists & num) and not (lists & num))
+
+ for contact in contactList.contacts.values():
+ # Compare with the XDB <item/> entry
+ oldContact = oldContactList.getContact(contact.userHandle)
+ if oldContact == None:
+ oldLists = 0
+ else:
+ oldLists = oldContact.lists
+ lists = contact.lists
+
+ # Create the Jabber representation of the
+ # contact base on the old list data and then
+ # sync it with current
+ jabContact = self.session.contactList.createContact(msn2jid(contact.userHandle, False), msnlist2jabsub(oldLists))
+ jabContact.updateAvatar(defaultAvatar, push=False)
+
+ if addedToList(msn.FORWARD_LIST):
+ jabContact.syncGroups(getGroupNames(contact, contactList), push=False)
+ jabContact.syncContactGrantedAuth()
+
+ if removedFromList(msn.FORWARD_LIST):
+ jabContact.syncContactRemovedAuth()
+
+ if addedToList(msn.ALLOW_LIST):
+ jabContact.syncUserGrantedAuth()
+
+ if addedToList(msn.BLOCK_LIST) or removedFromList(msn.ALLOW_LIST):
+ jabContact.syncUserRemovedAuth()
+
+ if (not (lists & msn.ALLOW_LIST) and not (lists & msn.BLOCK_LIST) and (lists & msn.REVERSE_LIST)) or (lists & msn.PENDING_LIST):
+ jabContact.contactRequestsAuth()
+
+ if removedFromList(msn.REVERSE_LIST):
+ jabContact.contactDerequestsAuth()
+
+ jabContact.syncRoster()
+
+ item = newXDB.addElement("item")
+ item.attributes["jid"] = contact.userHandle
+ item.attributes["subscription"] = msnlist2jabsub(lists)
+ item.attributes["lists"] = str(lists)
+
+ # Update the XDB
+ self.session.pytrans.xdb.set(self.jabberID, disco.IQROSTER, newXDB)
+ LogEvent(INFO, self.jabberID, "End.")