Mercurial > libervia-pubsub
changeset 37:9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
'subscribed' state.
Implement unsubscribe().
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sun, 31 Oct 2004 15:59:40 +0000 |
parents | 23b1dca64d06 |
children | c9ddca3cce20 |
files | idavoll/memory_backend.py |
diffstat | 1 files changed, 22 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/idavoll/memory_backend.py Sun Oct 31 15:57:47 2004 +0000 +++ b/idavoll/memory_backend.py Sun Oct 31 15:59:40 2004 +0000 @@ -87,13 +87,16 @@ item.children = [] self.dispatch({ 'items': items, 'node_id': node_id }, - '//event/pubsub/notify') + '//event/pubsub/notify') return defer.succeed(None) def get_notification_list(self, node_id, items): + subscriptions = self.nodes[node_id].subscriptions try: - d = defer.succeed(self.nodes[node_id].subscriptions.keys()) + subscribers = [s for s in subscriptions + if subscriptions[s].state == 'subscribed'] + d = defer.succeed(subscribers) except: d = defer.fail() @@ -137,6 +140,22 @@ 'jid': subscriber, 'subscription': subscription.state}) + def unsubscribe(self, node_id, subscriber, requestor): + try: + node = self.nodes[node_id] + except KeyError: + raise backend.NodeNotFound + + if subscriber.userhostJID() != requestor: + raise backend.NotAuthorized + + try: + del node.subscriptions[subscriber.full()] + except KeyError: + raise backend.NotSubscribed + + return defer.succeed(None) + def store_items(self, node_id, items, publisher): for item in items: self.nodes[node_id].items[item["id"]] = item @@ -171,7 +190,7 @@ return self.parent.subscribe(node_id, subscriber, requestor) def unsubscribe(self, node_id, subscriber, requestor): - raise backend.NotImplemented + return self.parent.unsubscribe(node_id, subscriber, requestor) class PersistenceService(service.Service):