]> code.delx.au - pymsnt/commitdiff
Updated roster-subsync code in 0.10.x and trunk to fix a critical bug (clients follow...
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Thu, 26 Jan 2006 05:30:29 +0000 (05:30 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Thu, 26 Jan 2006 05:30:29 +0000 (05:30 +0000)
git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@107 55fbd22a-6204-0410-b2f0-b6c764c7e90a

committer: jamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>

src/contact.py
src/disco.py
src/legacy/glue.py

index bab7bec1ad7ce6a80e0cdcf3e8525b9719db8586..30da03eb103cf8288b410d5b470875a147c39010 100644 (file)
@@ -19,6 +19,7 @@ class Contact:
                self.jid = jid
                self.contactList = contactList
                self.groups = []
+               self.origsub = sub
                self.sub = sub
                self.nickname = ""
                self.avatar = None
@@ -40,7 +41,6 @@ class Contact:
                        self.sub = "both"
                else:
                        return
-               self.updateRoster("subscribe")
 
        def syncContactRemovedAuth(self):
                """ Since last using the transport the user has been blocked by this contact.
@@ -51,7 +51,6 @@ class Contact:
                        self.sub = "from"
                else:
                        return
-               self.updateRoster("unsubscribed")
        
        def syncUserGrantedAuth(self):
                """ Since last using the transport the user has granted authorisation to this contact.
@@ -62,7 +61,6 @@ class Contact:
                        self.sub = "both"
                else:
                        return
-               self.updateRoster("subscribe")
        
        def syncUserRemovedAuth(self):
                """ Since last using the transport the user has removed this contact's authorisation.
@@ -73,14 +71,38 @@ class Contact:
                        self.sub = "to"
                else:
                        return
-               self.updateRoster("unsubscribe")
        
        def syncGroups(self, groups, push=True):
                """ Set the groups that this contact is in on the legacy service.
                By default this pushes the groups out with a presence subscribed packet. """
                self.groups = groups
-               if push: self.updateRoster("subscribed");
-       
+               if push: self.syncRoster(ptype="subscribed");
+       
+       syncChoice = {
+          ("none", "none") : "",              #
+          ("none", "to"  ) : "subscribe",     # User+ Contact
+          ("none", "from") : "subscribe",     # User  Contact+
+          ("none", "both") : "subscribe",     # User+ Contact+
+          ("to"  , "none") : "unsubscribed",  # User- Contact
+          ("to"  , "to"  ) : "",              #
+          ("to"  , "from") : "unsubscribe",   # User- Contact+      **
+          ("to"  , "both") : "subscribe",     # User  Contact+
+          ("from", "none") : "unsubscribe",   # User  Contact-
+          ("from", "to"  ) : "subscribe",     # User+ Contact-      *
+          ("from", "from") : "",              #
+          ("from", "both") : "subscribe",     # User+ Contact
+          ("both", "none") : "unsubscribed",  # User- Contact-      *
+          ("both", "to"  ) : "unsubscribe",   # User  Contact-
+          ("both", "from") : "unsubscribed",  # User- Contact
+          ("both", "both") : ""               #
+       }
+          
+       def syncRoster(self, ptype=""):
+               if not ptype:
+                       ptype = self.syncChoice.get((self.origsub, self.sub))
+               if ptype:
+                       self.contactList.session.sendRosterImport(jid=self.jid, ptype=ptype, sub=self.sub, groups=self.groups, name=self.nickname)
+
        def contactGrantsAuth(self):
                """ Live roster event """
                if(self.sub == "none"):
@@ -111,7 +133,8 @@ class Contact:
                if subtype == "subscribe":
                        if self.sub == "to" or self.sub == "both":
                                self.sendSub("subscribed")
-                       self.contactList.legacyList.addContact(self.jid)
+                       else:
+                               self.contactList.legacyList.addContact(self.jid)
 
                elif subtype == "subscribed":
                        if self.sub == "none":
@@ -169,8 +192,6 @@ class Contact:
                        tojid=self.contactList.session.jabberID
                self.contactList.session.sendPresence(to=tojid, fro=self.jid, ptype=self.ptype, show=self.show, status=self.status, avatarHash=avatarHash, nickname=self.nickname, payload=[caps])
        
-       def updateRoster(self, ptype):
-               self.contactList.session.sendRosterImport(jid=self.jid, ptype=ptype, sub=self.sub, groups=self.groups, name=self.nickname)
 
 
 class ContactList:
index 286ce3f8959d242016d92da70bf615d42f92469c..3fb2fc90d4d4efe7a45933c0f3625e4fc5ff74d6 100644 (file)
@@ -17,7 +17,7 @@ DISCO_ITEMS   = DISCO + "#items"
 DISCO_INFO    = DISCO + "#info"
 COMMANDS      = "http://jabber.org/protocol/commands"
 CAPS          = "http://jabber.org/protocol/caps"
-SUBSYNC       = "http://jabber.org/protocol/roster-subsync"
+SUBSYNC       = "http://delx.cjb.net/protocol/roster-subsync"
 MUC           = "http://jabber.org/protocol/muc"
 MUC_USER      = MUC + "#user"
 FEATURE_NEG   = "http://jabber.org/protocol/feature-neg"
index 4c06e0a15eea22ab6a058bc8cbf70a6fee365d36..9d116d9a05a9f9dcb0e34d80c218de2ef71b2497 100644 (file)
@@ -616,6 +616,8 @@ class LegacyList:
 
                        if removedFromList(msn.REVERSE_LIST):
                                jabContact.contactDerequestsAuth()
+
+                       jabContact.syncRoster()
                        
                        item = newXDB.addElement("item")
                        item.attributes["jid"] = contact.userHandle