]> code.delx.au - pymsnt/blobdiff - src/contact.py
New resources don't get spammed with presence from offline contacts.
[pymsnt] / src / contact.py
index 2e58902e7a410553eb5ce3c5f610086d0189e4e9..088f1c03a1242349cbf8ea7c5ad33b861e16bb12 100644 (file)
@@ -32,9 +32,9 @@ class Contact:
        def syncContactGrantedAuth(self):
                """ Since last using the transport the user has been granted authorisation by this contact.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
        def syncContactGrantedAuth(self):
                """ Since last using the transport the user has been granted authorisation by this contact.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
-               if(self.sub == "none"):
+               if self.sub == "none":
                        self.sub = "to"
                        self.sub = "to"
-               elif(self.sub == "from"):
+               elif self.sub == "from":
                        self.sub = "both"
                else:
                        return
                        self.sub = "both"
                else:
                        return
@@ -42,9 +42,9 @@ class Contact:
        def syncContactRemovedAuth(self):
                """ Since last using the transport the user has been blocked by this contact.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
        def syncContactRemovedAuth(self):
                """ Since last using the transport the user has been blocked by this contact.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
-               if(self.sub == "to"):
+               if self.sub == "to":
                        self.sub = "none"
                        self.sub = "none"
-               elif(self.sub == "both"):
+               elif self.sub == "both":
                        self.sub = "from"
                else:
                        return
                        self.sub = "from"
                else:
                        return
@@ -52,9 +52,9 @@ class Contact:
        def syncUserGrantedAuth(self):
                """ Since last using the transport the user has granted authorisation to this contact.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
        def syncUserGrantedAuth(self):
                """ Since last using the transport the user has granted authorisation to this contact.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
-               if(self.sub == "none"):
+               if self.sub == "none":
                        self.sub = "from"
                        self.sub = "from"
-               elif(self.sub == "to"):
+               elif self.sub == "to":
                        self.sub = "both"
                else:
                        return
                        self.sub = "both"
                else:
                        return
@@ -62,9 +62,9 @@ class Contact:
        def syncUserRemovedAuth(self):
                """ Since last using the transport the user has removed this contact's authorisation.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
        def syncUserRemovedAuth(self):
                """ Since last using the transport the user has removed this contact's authorisation.
                Call this to synchronise the user's Jabber list with their legacy list after logon. """
-               if(self.sub == "from"):
+               if self.sub == "from":
                        self.sub = "none"
                        self.sub = "none"
-               elif(self.sub == "both"):
+               elif self.sub == "both":
                        self.sub = "to"
                else:
                        return
                        self.sub = "to"
                else:
                        return
@@ -102,18 +102,18 @@ class Contact:
 
        def contactGrantsAuth(self):
                """ Live roster event """
 
        def contactGrantsAuth(self):
                """ Live roster event """
-               if(self.sub == "none"):
+               if self.sub == "none":
                        self.sub = "to"
                        self.sub = "to"
-               elif(self.sub == "from"):
+               elif self.sub == "from":
                        self.sub = "both"
                self.sendSub("subscribed")
                self.sendPresence()
        
        def contactRemovesAuth(self):
                """ Live roster event """
                        self.sub = "both"
                self.sendSub("subscribed")
                self.sendPresence()
        
        def contactRemovesAuth(self):
                """ Live roster event """
-               if(self.sub == "to"):
+               if self.sub == "to":
                        self.sub = "none"
                        self.sub = "none"
-               elif(self.sub == "both"):
+               elif self.sub == "both":
                        self.sub = "from"
                self.sendSub("unsubscribed")
        
                        self.sub = "from"
                self.sendSub("unsubscribed")
        
@@ -149,37 +149,39 @@ class Contact:
                                self.sub = "none"
                        self.contactList.legacyList.removeContact(self.jid)
 
                                self.sub = "none"
                        self.contactList.legacyList.removeContact(self.jid)
 
-               elif(subtype == "unsubscribed"):
-                       if(self.sub == "both"):
+               elif subtype == "unsubscribed":
+                       if self.sub == "both":
                                self.sub = "to"
                                self.sub = "to"
-                       if(self.sub == "from"):
+                       if self.sub == "from":
                                self.sub = "none"
                        self.contactList.legacyList.deauthContact(self.jid)
 
        def updateNickname(self, nickname, push=True):
                                self.sub = "none"
                        self.contactList.legacyList.deauthContact(self.jid)
 
        def updateNickname(self, nickname, push=True):
-               if(self.nickname != nickname):
+               if self.nickname != nickname:
                        self.nickname = nickname
                        self.nickname = nickname
-                       if(push): self.sendPresence()
+                       if push: self.sendPresence()
        
        def updatePresence(self, show, status, ptype, force=False):
                updateFlag = (self.show != show or self.status != status or self.ptype != ptype or force)
                self.show = show
                self.status = status
                self.ptype = ptype
        
        def updatePresence(self, show, status, ptype, force=False):
                updateFlag = (self.show != show or self.status != status or self.ptype != ptype or force)
                self.show = show
                self.status = status
                self.ptype = ptype
-               if(updateFlag):
+               if updateFlag:
                        self.sendPresence()
        
        def updateAvatar(self, avatar=None, push=True):
                        self.sendPresence()
        
        def updateAvatar(self, avatar=None, push=True):
-               if(self.avatar == avatar): return
+               if self.avatar == avatar:
+                       return
                self.avatar = avatar
                self.avatar = avatar
-               if(push): self.sendPresence()
+               if push:
+                       self.sendPresence()
        
        def sendSub(self, ptype):
                self.contactList.session.sendPresence(to=self.contactList.session.jabberID, fro=self.jid + "/" + legacy.id, ptype=ptype)
        
        def sendPresence(self, tojid=""):
                avatarHash = ""
        
        def sendSub(self, ptype):
                self.contactList.session.sendPresence(to=self.contactList.session.jabberID, fro=self.jid + "/" + legacy.id, ptype=ptype)
        
        def sendPresence(self, tojid=""):
                avatarHash = ""
-               if(self.avatar):
+               if self.avatar:
                        avatarHash = self.avatar.getImageHash()
                caps = Element((None, "c"))
                caps.attributes["xmlns"] = disco.CAPS
                        avatarHash = self.avatar.getImageHash()
                caps = Element((None, "c"))
                caps.attributes["xmlns"] = disco.CAPS
@@ -210,7 +212,7 @@ class ContactList:
        
        def resendLists(self, tojid=""):
                for jid in self.contacts:
        
        def resendLists(self, tojid=""):
                for jid in self.contacts:
-                       if(self.contacts[jid].status != "unavailable"):
+                       if self.contacts[jid].ptype != "unavailable" :
                                self.contacts[jid].sendPresence(tojid)
                LogEvent(INFO, self.session.jabberID)
        
                                self.contacts[jid].sendPresence(tojid)
                LogEvent(INFO, self.session.jabberID)
        
@@ -225,12 +227,12 @@ class ContactList:
        
        def getContact(self, jid):
                """ Finds the contact. If one doesn't exist then a new one is created, with sub set to "none" """
        
        def getContact(self, jid):
                """ Finds the contact. If one doesn't exist then a new one is created, with sub set to "none" """
-               if(not self.contacts.has_key(jid)):
+               if not self.contacts.has_key(jid):
                        self.contacts[jid] = Contact(jid, "none", self)
                return self.contacts[jid]
        
        def findContact(self, jid):
                        self.contacts[jid] = Contact(jid, "none", self)
                return self.contacts[jid]
        
        def findContact(self, jid):
-               if(self.contacts.has_key(jid)):
+               if self.contacts.has_key(jid):
                        return self.contacts[jid]
                return None
        
                        return self.contacts[jid]
                return None