Mercurial > libervia-pubsub
comparison idavoll/backend.py @ 178:07114105885a
Send last published item on subscription if node is so configured.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Thu, 10 Apr 2008 14:02:53 +0000 |
parents | 79d451d186b1 |
children | 42e23a62b57f |
comparison
equal
deleted
inserted
replaced
177:faf1c9bc2612 | 178:07114105885a |
---|---|
157 | 157 |
158 if affiliation == 'outcast': | 158 if affiliation == 'outcast': |
159 raise error.Forbidden() | 159 raise error.Forbidden() |
160 | 160 |
161 d = node.add_subscription(subscriber, 'subscribed') | 161 d = node.add_subscription(subscriber, 'subscribed') |
162 d.addCallback(lambda _: self._send_last_published(node, subscriber)) | |
162 d.addCallback(lambda _: 'subscribed') | 163 d.addCallback(lambda _: 'subscribed') |
163 d.addErrback(self._get_subscription, node, subscriber) | 164 d.addErrback(self._get_subscription, node, subscriber) |
164 d.addCallback(self._return_subscription, node.id) | 165 d.addCallback(self._return_subscription, node.id) |
165 return d | 166 return d |
166 | 167 |
168 failure.trap(error.SubscriptionExists) | 169 failure.trap(error.SubscriptionExists) |
169 return node.get_subscription(subscriber) | 170 return node.get_subscription(subscriber) |
170 | 171 |
171 def _return_subscription(self, result, node_id): | 172 def _return_subscription(self, result, node_id): |
172 return node_id, result | 173 return node_id, result |
174 | |
175 def _send_last_published(self, node, subscriber): | |
176 def notify_item(items): | |
177 if not items: | |
178 return | |
179 | |
180 self.dispatch({'items': items, | |
181 'node_id': node.id, | |
182 'subscriber': subscriber}, | |
183 '//event/pubsub/notify') | |
184 | |
185 config = node.get_configuration() | |
186 if config["pubsub#send_last_published_item"] != 'on_sub': | |
187 return | |
188 | |
189 d = self.get_items(node.id, subscriber.userhostJID(), 1) | |
190 d.addCallback(notify_item) | |
173 | 191 |
174 def unsubscribe(self, node_id, subscriber, requestor): | 192 def unsubscribe(self, node_id, subscriber, requestor): |
175 if subscriber.userhostJID() != requestor: | 193 if subscriber.userhostJID() != requestor: |
176 return defer.fail(error.Forbidden()) | 194 return defer.fail(error.Forbidden()) |
177 | 195 |
420 return features | 438 return features |
421 | 439 |
422 def _notify(self, data): | 440 def _notify(self, data): |
423 items = data['items'] | 441 items = data['items'] |
424 nodeIdentifier = data['node_id'] | 442 nodeIdentifier = data['node_id'] |
425 d = self.backend.get_notification_list(nodeIdentifier, items) | 443 if 'subscriber' not in data: |
444 d = self.backend.get_notification_list(nodeIdentifier, items) | |
445 else: | |
446 d = defer.succeed([(data['subscriber'], items)]) | |
426 d.addCallback(lambda notifications: self.notifyPublish(self.serviceJID, | 447 d.addCallback(lambda notifications: self.notifyPublish(self.serviceJID, |
427 nodeIdentifier, | 448 nodeIdentifier, |
428 notifications)) | 449 notifications)) |
429 | 450 |
430 def _pre_delete(self, nodeIdentifier): | 451 def _pre_delete(self, nodeIdentifier): |