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,
}
}
pepService.sendLastPublishedItem(subscriberJID);
pepService.sendLastPublishedItems(subscriberJID);
}
}
......@@ -513,7 +513,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
for (PEPService pepService : pepServices.values()) {
try {
if (presenceManager.canProbePresence(newlyAvailableJID, pepService.getAddress().getNode())) {
pepService.sendLastPublishedItem(newlyAvailableJID);
pepService.sendLastPublishedItems(newlyAvailableJID);
}
}
catch (UserNotFoundException e) {
......
......@@ -468,69 +468,61 @@ public class PEPService implements PubSubService {
}
/**
* Sends an event notification for the last published item to the recipient JID. For
* a PEPService, the last published item is the latest item published for all of the
* last published items of each leaf node under the root collection node. If the
* recipient has no subscription to the root collection node, has not yet been authorized,
* or is pending to be configured -- then no notification is going to be sent.<p>
* Sends an event notification for the last published item of each leaf node under the
* root collection node to the recipient JID. If the recipient has no subscription to
* the root collection node, has not yet been authorized, or is pending to be
* configured -- then no notifications are 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.
*
* @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) {
// Retrieve last published item.
PublishedItem lastPublishedItem = null;
public void sendLastPublishedItems(JID recipientJID) {
// Ensure the recipient has a subscription to this service's root collection node.
NodeSubscription subscription = rootCollectionNode.getSubscription(recipientJID);
if (subscription == null) {
subscription = rootCollectionNode.getSubscription(new JID(recipientJID.toBareJID()));
}
if (subscription == null) {
return;
}
// Send the last published item of each leaf node to the recipient.
for (Node leafNode : rootCollectionNode.getNodes()) {
PublishedItem leafLastPublishedItem = leafNode.getLastPublishedItem();
// Retrieve last published item for the leaf node.
PublishedItem leafLastPublishedItem = null;
leafLastPublishedItem = leafNode.getLastPublishedItem();
if (leafLastPublishedItem == null) {
continue;
}
if (lastPublishedItem == null) {
lastPublishedItem = leafLastPublishedItem;
continue;
// Check if the published item can be sent to the subscriber
if (!subscription.canSendPublicationEvent(leafLastPublishedItem.getNode(), leafLastPublishedItem)) {
return;
}
if (leafLastPublishedItem.getCreationDate().compareTo(lastPublishedItem.getCreationDate()) > 0) {
lastPublishedItem = leafLastPublishedItem;
// Send event notification to the subscriber
Message notification = new Message();
Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event");
Element items = event.addElement("items");
items.addAttribute("node", leafLastPublishedItem.getNode().getNodeID());
Element item = items.addElement("item");
if (((LeafNode) leafLastPublishedItem.getNode()).isItemRequired()) {
item.addAttribute("id", leafLastPublishedItem.getID());
}
if (leafLastPublishedItem.getNode().isPayloadDelivered() && leafLastPublishedItem.getPayload() != null) {
item.add(leafLastPublishedItem.getPayload().createCopy());
}
// Add a message body (if required)
if (subscription.isIncludingBody()) {
notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body"));
}
// Include date when published item was created
notification.getElement().addElement("x", "jabber:x:delay").addAttribute("stamp", fastDateFormat.format(leafLastPublishedItem.getCreationDate()));
// Send the event notification to the subscriber
this.sendNotification(subscription.getNode(), notification, subscription.getJID());
}
NodeSubscription subscription = rootCollectionNode.getSubscription(recipientJID);
if (subscription == null) {
subscription = rootCollectionNode.getSubscription(new JID(recipientJID.toBareJID()));
}
if (subscription == null) {
return;
}
// Check if the published item can be sent to the subscriber
if (!subscription.canSendPublicationEvent(lastPublishedItem.getNode(), lastPublishedItem)) {
return;
}
// Send event notification to the subscriber
Message notification = new Message();
Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event");
Element items = event.addElement("items");
items.addAttribute("node", lastPublishedItem.getNode().getNodeID());
Element item = items.addElement("item");
if (((LeafNode) lastPublishedItem.getNode()).isItemRequired()) {
item.addAttribute("id", lastPublishedItem.getID());
}
if (lastPublishedItem.getNode().isPayloadDelivered() && lastPublishedItem.getPayload() != null) {
item.add(lastPublishedItem.getPayload().createCopy());
}
// Add a message body (if required)
if (subscription.isIncludingBody()) {
notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body"));
}
// Include date when published item was created
notification.getElement().addElement("x", "jabber:x:delay").addAttribute("stamp", fastDateFormat.format(lastPublishedItem.getCreationDate()));
// Send the event notification to the subscriber
this.sendNotification(subscription.getNode(), notification, subscription.getJID());
}
public void queueItemToAdd(PublishedItem 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