Commit b5e4ea02 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

PEP: Refactored the sendLastPublishedItem method in PEPService a bit.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/pep@8915 b35dd754-fafc-0310-a699-88a17e54d16e
parent bcca0dfa
......@@ -32,9 +32,10 @@ import org.jivesoftware.openfire.pubsub.LeafNode;
import org.jivesoftware.openfire.pubsub.Node;
import org.jivesoftware.openfire.pubsub.NodeSubscription;
import org.jivesoftware.openfire.pubsub.PubSubEngine;
import org.jivesoftware.openfire.pubsub.PublishedItem;
import org.jivesoftware.openfire.pubsub.models.AccessModel;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterEventDispatcher;
import org.jivesoftware.openfire.roster.RosterEventListener;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.Session;
......@@ -438,6 +439,8 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
}
}
}
pepService.sendLastPublishedItem(subscriberJID);
}
}
......@@ -456,35 +459,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
for (PEPService pepService : pepServices.values()) {
try {
if (presenceManager.canProbePresence(newlyAvailableJID, pepService.getAddress().getNode())) {
// Retrieve last published item.
CollectionNode rootNode = pepService.getRootCollectionNode();
PublishedItem lastPublishedItem = null;
for (Node leafNode : rootNode.getNodes()) {
PublishedItem leafLastPublishedItem = leafNode.getLastPublishedItem();
if (leafLastPublishedItem == null) {
continue;
}
if (lastPublishedItem == null) {
lastPublishedItem = leafLastPublishedItem;
continue;
}
if (leafLastPublishedItem.getCreationDate().compareTo(lastPublishedItem.getCreationDate()) > 0) {
lastPublishedItem = leafLastPublishedItem;
}
}
// Send last published item to the newly-available resource.
NodeSubscription subscription = rootNode.getSubscription(newlyAvailableJID);
if (subscription == null) {
subscription = rootNode.getSubscription(new JID(newlyAvailableJID.toBareJID()));
}
if (subscription != null) {
pepService.sendLastPublishedItem(subscription, lastPublishedItem);
}
pepService.sendLastPublishedItem(newlyAvailableJID);
}
}
catch (UserNotFoundException e) {
......@@ -672,5 +647,4 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
public Map<String, HashSet<JID>> getKnownRemotePresenes() {
return knownRemotePresences;
}
}
......@@ -501,19 +501,47 @@ public class PEPService implements PubSubService {
}
/**
* Sends an event notification for the last published item to the subscription's subscriber. If
* the subscription 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 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>
*
* Depending on the subscription configuration the event notification 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 subscription the subscription the published item is being sent for.
* @param publishedItem the last item that was published to the node.
* @param recipientJID the recipient that is to receive the last published item notification.
*/
public void sendLastPublishedItem(NodeSubscription subscription, PublishedItem publishedItem) {
public void sendLastPublishedItem(JID recipientJID) {
// Retrieve last published item.
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);
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(publishedItem.getNode(), publishedItem)) {
if (!subscription.canSendPublicationEvent(lastPublishedItem.getNode(), lastPublishedItem)) {
return;
}
// Send event notification to the subscriber
......@@ -521,13 +549,13 @@ public class PEPService implements PubSubService {
Element event = notification.getElement()
.addElement("event", "http://jabber.org/protocol/pubsub#event");
Element items = event.addElement("items");
items.addAttribute("node", publishedItem.getNode().getNodeID());
items.addAttribute("node", lastPublishedItem.getNode().getNodeID());
Element item = items.addElement("item");
if (((LeafNode) publishedItem.getNode()).isItemRequired()) {
item.addAttribute("id", publishedItem.getID());
if (((LeafNode) lastPublishedItem.getNode()).isItemRequired()) {
item.addAttribute("id", lastPublishedItem.getID());
}
if (publishedItem.getNode().isPayloadDelivered() && publishedItem.getPayload() != null) {
item.add(publishedItem.getPayload().createCopy());
if (lastPublishedItem.getNode().isPayloadDelivered() && lastPublishedItem.getPayload() != null) {
item.add(lastPublishedItem.getPayload().createCopy());
}
// Add a message body (if required)
if (subscription.isIncludingBody()) {
......@@ -535,7 +563,7 @@ public class PEPService implements PubSubService {
}
// Include date when published item was created
notification.getElement().addElement("x", "jabber:x:delay")
.addAttribute("stamp", fastDateFormat.format(publishedItem.getCreationDate()));
.addAttribute("stamp", fastDateFormat.format(lastPublishedItem.getCreationDate()));
// Send the event notification to the subscriber
this.sendNotification(subscription.getNode(), notification, subscription.getJID());
}
......
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