# HG changeset patch # User Goffi # Date 1504850525 -7200 # Node ID c72fcbdcdab7c1af1d1c853b1a4506fd60df9e4f # Parent 18b983fe9e1b628eaaeb0e6b29851de94a31cb7f backend: fixed subscription, PEP was not handled correctly diff -r 18b983fe9e1b -r c72fcbdcdab7 sat_pubsub/backend.py --- a/sat_pubsub/backend.py Fri Sep 08 08:02:05 2017 +0200 +++ b/sat_pubsub/backend.py Fri Sep 08 08:02:05 2017 +0200 @@ -460,11 +460,10 @@ d = self.storage.getNode(nodeIdentifier, pep, recipient) d.addCallback(_getAffiliation, subscriberEntity) - d.addCallback(self._doSubscribe, subscriber) + d.addCallback(self._doSubscribe, subscriber, pep, recipient) return d - def _doSubscribe(self, result, subscriber): - # TODO: implement other access models + def _doSubscribe(self, result, subscriber, pep, recipient): node, affiliation = result if affiliation == 'outcast': @@ -490,22 +489,24 @@ def cb(sendLast): d = node.getSubscription(subscriber) if sendLast: - d.addCallback(self._sendLastPublished, node) + d.addCallback(self._sendLastPublished, node, pep, recipient) return d - d = node.addSubscription(subscriber, 'subscribed', {}) + d.addCallback(lambda _: node.addSubscription(subscriber, 'subscribed', {})) d.addCallbacks(lambda _: True, trapExists) d.addCallback(cb) return d - def _sendLastPublished(self, subscription, node): + def _sendLastPublished(self, subscription, node, pep, recipient): - def notifyItem(items): - if items: + def notifyItem(items_data): + if items_data: reactor.callLater(0, self.dispatch, - {'items': items, + {'items_data': items_data, 'node': node, + 'pep': pep, + 'recipient': recipient, 'subscription': subscription, }, '//event/pubsub/notify') @@ -515,7 +516,7 @@ 'never') if sendLastPublished == 'on_sub' and node.nodeType == 'leaf': entity = subscription.subscriber.userhostJID() - d = self.getItems(node.nodeIdentifier, entity, 1) + d = self.getItemsData(node.nodeIdentifier, entity, recipient, maxItems=1, ext_data={'pep': pep}) d.addCallback(notifyItem) d.addErrback(log.err) @@ -529,8 +530,8 @@ d.addCallback(lambda node: node.removeSubscription(subscriber)) return d - def getSubscriptions(self, entity): - return self.storage.getSubscriptions(entity) + def getSubscriptions(self, requestor, pep, recipient): + return self.storage.getSubscriptions(requestor, pep, recipient) def supportsAutoCreate(self): return True