self.jid = jid
self.contactList = contactList
self.groups = []
+ self.origsub = sub
self.sub = sub
self.nickname = ""
self.avatar = None
self.sub = "both"
else:
return
- self.updateRoster("subscribe")
def syncContactRemovedAuth(self):
""" Since last using the transport the user has been blocked by this 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.
self.sub = "both"
else:
return
- self.updateRoster("subscribe")
def syncUserRemovedAuth(self):
""" Since last using the transport the user has removed this contact's authorisation.
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"):
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":
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: