Commit 7df954a8 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

The logic for sending the last published item in a PEP service has been...

The logic for sending the last published item in a PEP service has been redesigned to send the last published item of each leaf node under the root collection node.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8964 b35dd754-fafc-0310-a699-88a17e54d16e
parent e3dc7f3f
...@@ -491,7 +491,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -491,7 +491,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
} }
pepService.sendLastPublishedItem(subscriberJID); pepService.sendLastPublishedItems(subscriberJID);
} }
} }
...@@ -513,7 +513,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -513,7 +513,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
for (PEPService pepService : pepServices.values()) { for (PEPService pepService : pepServices.values()) {
try { try {
if (presenceManager.canProbePresence(newlyAvailableJID, pepService.getAddress().getNode())) { if (presenceManager.canProbePresence(newlyAvailableJID, pepService.getAddress().getNode())) {
pepService.sendLastPublishedItem(newlyAvailableJID); pepService.sendLastPublishedItems(newlyAvailableJID);
} }
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
......
...@@ -468,37 +468,18 @@ public class PEPService implements PubSubService { ...@@ -468,37 +468,18 @@ public class PEPService implements PubSubService {
} }
/** /**
* Sends an event notification for the last published item to the recipient JID. For * Sends an event notification for the last published item of each leaf node under the
* a PEPService, the last published item is the latest item published for all of the * root collection node to the recipient JID. If the recipient has no subscription to
* last published items of each leaf node under the root collection node. If the * the root collection node, has not yet been authorized, or is pending to be
* recipient has no subscription to the root collection node, has not yet been authorized, * configured -- then no notifications are going to be sent.<p>
* or is pending to be configured -- then no notification is going to be sent.<p>
* *
* Depending on the subscription configuration the event notification may or may not have * Depending on the subscription configuration the event notifications may or may not have
* a payload, may not be sent if a keyword (i.e. filter) was defined and it was not matched. * a payload, may not be sent if a keyword (i.e. filter) was defined and it was not matched.
* *
* @param recipientJID the recipient that is to receive the last published item notification. * @param recipientJID the recipient that is to receive the last published item notifications.
*/ */
public void sendLastPublishedItem(JID recipientJID) { public void sendLastPublishedItems(JID recipientJID) {
// Retrieve last published item. // Ensure the recipient has a subscription to this service's root collection node.
PublishedItem lastPublishedItem = null;
for (Node leafNode : rootCollectionNode.getNodes()) {
PublishedItem leafLastPublishedItem = leafNode.getLastPublishedItem();
if (leafLastPublishedItem == null) {
continue;
}
if (lastPublishedItem == null) {
lastPublishedItem = leafLastPublishedItem;
continue;
}
if (leafLastPublishedItem.getCreationDate().compareTo(lastPublishedItem.getCreationDate()) > 0) {
lastPublishedItem = leafLastPublishedItem;
}
}
NodeSubscription subscription = rootCollectionNode.getSubscription(recipientJID); NodeSubscription subscription = rootCollectionNode.getSubscription(recipientJID);
if (subscription == null) { if (subscription == null) {
subscription = rootCollectionNode.getSubscription(new JID(recipientJID.toBareJID())); subscription = rootCollectionNode.getSubscription(new JID(recipientJID.toBareJID()));
...@@ -507,31 +488,42 @@ public class PEPService implements PubSubService { ...@@ -507,31 +488,42 @@ public class PEPService implements PubSubService {
return; return;
} }
// Send the last published item of each leaf node to the recipient.
for (Node leafNode : rootCollectionNode.getNodes()) {
// Retrieve last published item for the leaf node.
PublishedItem leafLastPublishedItem = null;
leafLastPublishedItem = leafNode.getLastPublishedItem();
if (leafLastPublishedItem == null) {
continue;
}
// Check if the published item can be sent to the subscriber // Check if the published item can be sent to the subscriber
if (!subscription.canSendPublicationEvent(lastPublishedItem.getNode(), lastPublishedItem)) { if (!subscription.canSendPublicationEvent(leafLastPublishedItem.getNode(), leafLastPublishedItem)) {
return; return;
} }
// Send event notification to the subscriber // Send event notification to the subscriber
Message notification = new Message(); Message notification = new Message();
Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event"); Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event");
Element items = event.addElement("items"); Element items = event.addElement("items");
items.addAttribute("node", lastPublishedItem.getNode().getNodeID()); items.addAttribute("node", leafLastPublishedItem.getNode().getNodeID());
Element item = items.addElement("item"); Element item = items.addElement("item");
if (((LeafNode) lastPublishedItem.getNode()).isItemRequired()) { if (((LeafNode) leafLastPublishedItem.getNode()).isItemRequired()) {
item.addAttribute("id", lastPublishedItem.getID()); item.addAttribute("id", leafLastPublishedItem.getID());
} }
if (lastPublishedItem.getNode().isPayloadDelivered() && lastPublishedItem.getPayload() != null) { if (leafLastPublishedItem.getNode().isPayloadDelivered() && leafLastPublishedItem.getPayload() != null) {
item.add(lastPublishedItem.getPayload().createCopy()); item.add(leafLastPublishedItem.getPayload().createCopy());
} }
// Add a message body (if required) // Add a message body (if required)
if (subscription.isIncludingBody()) { if (subscription.isIncludingBody()) {
notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body")); notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body"));
} }
// Include date when published item was created // Include date when published item was created
notification.getElement().addElement("x", "jabber:x:delay").addAttribute("stamp", fastDateFormat.format(lastPublishedItem.getCreationDate())); notification.getElement().addElement("x", "jabber:x:delay").addAttribute("stamp", fastDateFormat.format(leafLastPublishedItem.getCreationDate()));
// Send the event notification to the subscriber // Send the event notification to the subscriber
this.sendNotification(subscription.getNode(), notification, subscription.getJID()); this.sendNotification(subscription.getNode(), notification, subscription.getJID());
} }
}
public void queueItemToAdd(PublishedItem newItem) { public void queueItemToAdd(PublishedItem newItem) {
PubSubEngine.queueItemToAdd(this, newItem); PubSubEngine.queueItemToAdd(this, newItem);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment