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

Squashed a bug that sent out redundant publish notifications from leaf PEP...

Squashed a bug that sent out redundant publish notifications from leaf PEP node subscriptions along with publish notifications from a root PEP node subscriptions.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8836 b35dd754-fafc-0310-a699-88a17e54d16e
parent 710896ae
...@@ -26,6 +26,7 @@ import org.jivesoftware.openfire.handler.IQHandler; ...@@ -26,6 +26,7 @@ import org.jivesoftware.openfire.handler.IQHandler;
import org.jivesoftware.openfire.pubsub.CollectionNode; import org.jivesoftware.openfire.pubsub.CollectionNode;
import org.jivesoftware.openfire.pubsub.LeafNode; import org.jivesoftware.openfire.pubsub.LeafNode;
import org.jivesoftware.openfire.pubsub.Node; import org.jivesoftware.openfire.pubsub.Node;
import org.jivesoftware.openfire.pubsub.NodeSubscription;
import org.jivesoftware.openfire.pubsub.PubSubEngine; import org.jivesoftware.openfire.pubsub.PubSubEngine;
import org.jivesoftware.openfire.pubsub.models.AccessModel; import org.jivesoftware.openfire.pubsub.models.AccessModel;
import org.jivesoftware.openfire.roster.Roster; import org.jivesoftware.openfire.roster.Roster;
...@@ -80,8 +81,8 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -80,8 +81,8 @@ import java.util.concurrent.ConcurrentHashMap;
* @author Armando Jagucki * @author Armando Jagucki
* *
*/ */
public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ServerFeaturesProvider, public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ServerFeaturesProvider, UserIdentitiesProvider, UserItemsProvider,
UserIdentitiesProvider, UserItemsProvider, PresenceEventListener { PresenceEventListener {
// Map of PEP services. Table, Key: bare JID (String); Value: PEPService // Map of PEP services. Table, Key: bare JID (String); Value: PEPService
private Map<String, PEPService> pepServices; private Map<String, PEPService> pepServices;
...@@ -206,7 +207,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -206,7 +207,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
Roster roster = XMPPServer.getInstance().getRosterManager().getRoster(packet.getFrom().getNode()); Roster roster = XMPPServer.getInstance().getRosterManager().getRoster(packet.getFrom().getNode());
for (RosterItem item : roster.getRosterItems()) { for (RosterItem item : roster.getRosterItems()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) { if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
createSubscriptionToPEPService(item.getJid(), packet.getFrom()); createSubscriptionToPEPService(pepService, item.getJid(), packet.getFrom());
} }
} }
} }
...@@ -266,10 +267,11 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -266,10 +267,11 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
/** /**
* Generates and processes an IQ stanza that subscribes to a PEP service. * Generates and processes an IQ stanza that subscribes to a PEP service.
* *
* @param pepService the PEP service of the owner.
* @param subscriber the JID of the entity that is subscribing to the PEP service. * @param subscriber the JID of the entity that is subscribing to the PEP service.
* @param owner the JID of the owner of the PEP service. * @param owner the JID of the owner of the PEP service.
*/ */
private void createSubscriptionToPEPService(JID subscriber, JID owner) { private void createSubscriptionToPEPService(PEPService pepService, JID subscriber, JID owner) {
// If `owner` has a PEP service, generate and process a pubsub subscription packet // If `owner` has a PEP service, generate and process a pubsub subscription packet
// that is equivalent to: (where 'from' field is JID of subscriber and 'to' field is JID of owner) // that is equivalent to: (where 'from' field is JID of subscriber and 'to' field is JID of owner)
// //
...@@ -294,8 +296,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -294,8 +296,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// </options> // </options>
// </pubsub> // </pubsub>
// </iq> // </iq>
PEPService pepService = pepServices.get(owner.toBareJID());
if (pepService != null) {
IQ subscriptionPacket = new IQ(IQ.Type.set); IQ subscriptionPacket = new IQ(IQ.Type.set);
subscriptionPacket.setFrom(subscriber); subscriptionPacket.setFrom(subscriber);
subscriptionPacket.setTo(owner.toBareJID()); subscriptionPacket.setTo(owner.toBareJID());
...@@ -325,7 +326,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -325,7 +326,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
pubSubEngine.process(pepService, subscriptionPacket); pubSubEngine.process(pepService, subscriptionPacket);
} }
}
/** /**
* Implements ServerIdentitiesProvider and UserIdentitiesProvider, adding * Implements ServerIdentitiesProvider and UserIdentitiesProvider, adding
...@@ -383,7 +383,23 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -383,7 +383,23 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
public void subscribedToPresence(JID subscriberJID, JID authorizerJID) { public void subscribedToPresence(JID subscriberJID, JID authorizerJID) {
createSubscriptionToPEPService(subscriberJID, authorizerJID); PEPService pepService = pepServices.get(authorizerJID.toBareJID());
if (pepService != null) {
createSubscriptionToPEPService(pepService, subscriberJID, authorizerJID);
// Delete any leaf node subscriptions the subscriber may have already
// had (since a subscription to the PEP service, and thus its leaf PEP
// nodes, would be duplicating publish notifications from previous leaf
// node subscriptions).
CollectionNode rootNode = pepService.getRootCollectionNode();
for (Node node : pepService.getNodes()) {
if (rootNode.isChildNode(node)) {
for (NodeSubscription subscription : node.getSubscriptions(subscriberJID)) {
node.cancelSubscription(subscription);
}
}
}
}
} }
public void unavailableSession(ClientSession session, Presence presence) { public void unavailableSession(ClientSession session, Presence presence) {
......
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