summaryrefslogtreecommitdiff
path: root/sleekxmpp/clientxmpp.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-03-07 11:44:07 -0800
committerLance Stout <lancestout@gmail.com>2012-03-07 14:55:27 -0800
commita71823dc040062c02a2036db7473845ca07b52f3 (patch)
treec3e97566ec63cd936203684321e1cce1df73fb74 /sleekxmpp/clientxmpp.py
parentd41ada6b66e4fb1b447c2f6aa4f0e227429afbbf (diff)
downloadslixmpp-a71823dc040062c02a2036db7473845ca07b52f3.tar.gz
slixmpp-a71823dc040062c02a2036db7473845ca07b52f3.tar.bz2
slixmpp-a71823dc040062c02a2036db7473845ca07b52f3.tar.xz
slixmpp-a71823dc040062c02a2036db7473845ca07b52f3.zip
Add support for roster versioning.
This was XEP-0237, but is now part of RFC 6121. Roster backends should now expose two additional methods: version(jid): Return the version of the given JID's roster. set_version(jid, version): Update the version of the given JID's roster. A new state field will be passed to the backend if an item has been marked for removal. This is 'removed' which will be set to True.
Diffstat (limited to 'sleekxmpp/clientxmpp.py')
-rw-r--r--sleekxmpp/clientxmpp.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py
index 458af2b7..590192db 100644
--- a/sleekxmpp/clientxmpp.py
+++ b/sleekxmpp/clientxmpp.py
@@ -18,6 +18,7 @@ import logging
from sleekxmpp.stanza import StreamFeatures
from sleekxmpp.basexmpp import BaseXMPP
+from sleekxmpp.exceptions import XMPPError
from sleekxmpp.xmlstream import XMLStream
from sleekxmpp.xmlstream.matcher import MatchXPath
from sleekxmpp.xmlstream.handler import Callback
@@ -111,6 +112,7 @@ class ClientXMPP(BaseXMPP):
self.register_plugin('feature_session')
self.register_plugin('feature_mechanisms',
pconfig={'use_mech': sasl_mech} if sasl_mech else None)
+ self.register_plugin('feature_rosterver')
@property
def password(self):
@@ -240,6 +242,8 @@ class ClientXMPP(BaseXMPP):
iq = self.Iq()
iq['type'] = 'get'
iq.enable('roster')
+ if 'rosterver' in self.features:
+ iq['roster']['ver'] = self.client_roster.version
if not block and callback is None:
callback = lambda resp: self._handle_roster(resp, request=True)
@@ -279,15 +283,22 @@ class ClientXMPP(BaseXMPP):
to a request for the roster, and not an
empty acknowledgement from the server.
"""
+ if iq['from'].bare and iq['from'].bare != self.boundjid.bare:
+ raise XMPPError(condition='service-unavailable')
if iq['type'] == 'set' or (iq['type'] == 'result' and request):
+ roster = self.client_roster
+ if iq['roster']['ver']:
+ roster.version = iq['roster']['ver']
for jid in iq['roster']['items']:
item = iq['roster']['items'][jid]
- roster = self.roster[iq['to'].bare]
roster[jid]['name'] = item['name']
roster[jid]['groups'] = item['groups']
roster[jid]['from'] = item['subscription'] in ['from', 'both']
roster[jid]['to'] = item['subscription'] in ['to', 'both']
roster[jid]['pending_out'] = (item['ask'] == 'subscribe')
+
+ roster[jid].save(remove=(item['subscription'] == 'remove'))
+
self.event('roster_received', iq)
self.event("roster_update", iq)