]> code.delx.au - pymsnt/blobdiff - src/contact.py
Sending of chunked messages works now.
[pymsnt] / src / contact.py
index bab7bec1ad7ce6a80e0cdcf3e8525b9719db8586..2e58902e7a410553eb5ce3c5f610086d0189e4e9 100644 (file)
@@ -1,16 +1,13 @@
 # Copyright 2005 James Bunton <james@delx.cjb.net>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
-import utils
+from debug import LogEvent, INFO, WARN, ERROR
+
 from twisted.internet import reactor
 from tlib.xmlw import Element
-from debug import LogEvent, INFO, WARN, ERROR
+
 import disco
 import legacy
-import jabw
-import config
-import lang
-import sha
 
 
 class Contact:
@@ -19,6 +16,7 @@ class Contact:
                self.jid = jid
                self.contactList = contactList
                self.groups = []
+               self.origsub = sub
                self.sub = sub
                self.nickname = ""
                self.avatar = None
@@ -40,7 +38,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 +48,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 +58,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 +68,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 +130,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":
@@ -155,7 +175,7 @@ class Contact:
                if(push): self.sendPresence()
        
        def sendSub(self, ptype):
-               self.contactList.session.sendPresence(to=self.contactList.session.jabberID, fro=self.jid, ptype=ptype)
+               self.contactList.session.sendPresence(to=self.contactList.session.jabberID, fro=self.jid + "/" + legacy.id, ptype=ptype)
        
        def sendPresence(self, tojid=""):
                avatarHash = ""
@@ -167,10 +187,8 @@ class Contact:
                caps.attributes["ver"] = legacy.version
                if not tojid:
                        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])
+               self.contactList.session.sendPresence(to=tojid, fro=self.jid + "/" + legacy.id, 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: