changeset 251:0a7d43b3dad6

owner is now notified of items published
author Goffi <goffi@goffi.org>
date Tue, 23 Oct 2012 00:09:38 +0200
parents eb14b8d30cba
children 25a1dc7181cc
files sat_pubsub/backend.py
diffstat 1 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat_pubsub/backend.py	Sun Jun 24 19:35:49 2012 +0200
+++ b/sat_pubsub/backend.py	Tue Oct 23 00:09:38 2012 +0200
@@ -75,7 +75,7 @@
 
 from wokkel import disco, data_form
 from wokkel.iwokkel import IPubSubResource
-from wokkel.pubsub import PubSubResource, PubSubError
+from wokkel.pubsub import PubSubResource, PubSubError, Subscription
 
 from sat_pubsub import error, iidavoll, const
 from sat_pubsub.iidavoll import IBackendService, ILeafNode
@@ -711,7 +711,7 @@
         def _notifyAllowed(result):
             """Check access of subscriber for each item,
             and notify only allowed ones"""
-            notifications, roster = result
+            notifications, (owner_jid,roster) = result
             
             #we filter items not allowed for the subscribers
             notifications_filtered = []
@@ -736,6 +736,16 @@
 
                 notifications_filtered.append((subscriber, subscriptions, allowed_items))
             
+            #we notify the owner
+            #FIXME: check if this comply with XEP-0060 (option needed ?)
+            #TODO: item's access model have to be sent back to owner
+            #TODO: same thing for getItems
+            notifications_filtered.append((owner_jid,
+                                           set([Subscription(node.nodeIdentifier, 
+                                                            owner_jid,
+                                                            'subscribed')]),
+                                           [item for access_model, item_config, item in items])) 
+
             return self.pubsubService.notifyPublish(
                                                 self.serviceJID,
                                                 node.nodeIdentifier,
@@ -748,9 +758,14 @@
             subscription = data['subscription']
             d1 = defer.succeed([(subscription.subscriber, [subscription],
                                 items)])
-        
+       
+        def _got_owner(owner_jid):
+            #return a tuple with owner_jid and roster
+            d = self.backend.roster.getRoster(owner_jid)
+            return d.addCallback(lambda roster: (owner_jid,roster))
+
         d2 = node.getNodeOwner()
-        d2.addCallback(self.backend.roster.getRoster)
+        d2.addCallback(_got_owner)
 
         d = defer.gatherResults([d1, d2])
         d.addCallback(_notifyAllowed)