Mercurial > libervia-backend
diff src/plugins/plugin_xep_0060.py @ 1773:6e867caf4621
plugin XEP-0060, tmp(wokkel.rsm): small refactoring:
- don't use getRSMResponse anymore: rsm.PubSubClient use a different signature which return items and RSMResponse, this is better than the previous method as if the requested don't call getRSMResponse, there is no memory leak anymore.
- use RSMResponse directly instead of using ext_data, as other extension (like MAM) will be probably be managed with an other workflow
- don't do a useless deep copy of pubsub.PubSubRequest._parameters on each instance anymore
- RSMResponse.parse do now manage parsing of <set/> element directly
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Jan 2016 23:20:22 +0100 |
parents | d17772b0fe22 |
children | 8b18e5f55a90 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0060.py Tue Jan 05 23:20:22 2016 +0100 +++ b/src/plugins/plugin_xep_0060.py Tue Jan 05 23:20:22 2016 +0100 @@ -34,7 +34,7 @@ from wokkel import rsm from zope.interface import implements from collections import namedtuple -import uuid + UNSPECIFIED = "unspecified error" @@ -234,12 +234,11 @@ - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index value of RSMResponse """ if rsm_request and item_ids: - raise ValueError("items_id can't be used with rsm") + raise ValueError(u"items_id can't be used with rsm") if extra is None: extra = {} client = self.host.getClient(profile_key) - ext_data = {'id': unicode(uuid.uuid4()), 'rsm': rsm_request} if rsm_request is not None else None - d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, client.pubsub_client.parent.jid, ext_data) + d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, client.pubsub_client.parent.jid, rsm_request) try: subscribe = C.bool(extra['subscribe']) @@ -248,7 +247,7 @@ def subscribeEb(failure, service, node): failure.trap(error.StanzaError) - log.warning("Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value))) + log.warning(u"Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value))) def doSubscribe(items): self.subscribe(service, node, profile_key=profile_key).addErrback(subscribeEb, service, node) @@ -257,11 +256,12 @@ if subscribe: d.addCallback(doSubscribe) - def addMetadata(items): - metadata = {} - if rsm_request is not None: - rsm_data = client.pubsub_client.getRSMResponse(ext_data['id']) - metadata.update({'rsm_{}'.format(key): value for key, value in rsm_data.iteritems()}) + def addMetadata(result): + items, rsm_response = result + if rsm_request is not None and rsm_response is not None: + metadata = {'rsm_{}'.format(key): value for key, value in rsm_response.toDict().iteritems()} + else: + metadata = {} return (items, metadata) d.addCallback(addMetadata)