Commit a6457cb7 authored by Tom Evans's avatar Tom Evans Committed by tevans

OF-14: Avoid delivering multiple copies of pubsub event messages

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13608 b35dd754-fafc-0310-a699-88a17e54d16e
parent a68931fc
......@@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import org.dom4j.Element;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.pubsub.cluster.AffiliationTask;
......@@ -224,17 +225,10 @@ public abstract class Node {
*/
public NodeAffiliate addOwner(JID jid) {
NodeAffiliate nodeAffiliate = addAffiliation(jid, NodeAffiliate.Affiliation.owner);
Collection<NodeSubscription> subscriptions = getSubscriptions(jid);
if (subscriptions.isEmpty()) {
// User does not have a subscription with the node so create a default one
createSubscription(null, jid, jid, false, null);
}
else {
// Approve any pending subscription
for (NodeSubscription subscription : getSubscriptions(jid)) {
if (subscription.isAuthorizationPending()) {
subscription.approved();
}
// Approve any pending subscription
for (NodeSubscription subscription : getSubscriptions(jid)) {
if (subscription.isAuthorizationPending()) {
subscription.approved();
}
}
return nodeAffiliate;
......@@ -268,21 +262,7 @@ public abstract class Node {
* @return the newly created or modified affiliation to the node.
*/
public NodeAffiliate addPublisher(JID jid) {
NodeAffiliate nodeAffiliate = addAffiliation(jid, NodeAffiliate.Affiliation.publisher);
Collection<NodeSubscription> subscriptions = getSubscriptions(jid);
if (subscriptions.isEmpty()) {
// User does not have a subscription with the node so create a default one
createSubscription(null, jid, jid, false, null);
}
else {
// Approve any pending subscription
for (NodeSubscription subscription : getSubscriptions(jid)) {
if (subscription.isAuthorizationPending()) {
subscription.approved();
}
}
}
return nodeAffiliate;
return addAffiliation(jid, NodeAffiliate.Affiliation.publisher);
}
/**
......@@ -2040,8 +2020,15 @@ public abstract class Node {
header.setText(subID);
}
}
service.sendNotification(this, notification, subscriberJID);
// Verify that the subscriber JID is currently available to receive
// notification messages. This is needed because the message router
// delivers packets via the bare JID if a session for the full JID
// is not available. This check will prevent inadvertent delivery of
// multiple copies of the same notification to the user. (OF-14)
if (subscriberJID.getResource() == null ||
SessionManager.getInstance().getSession(subscriberJID) != null) {
service.sendNotification(this, notification, subscriberJID);
}
if (headers != null) {
// Remove the added child element that includes subscription IDs information
......
......@@ -20,12 +20,16 @@
package org.jivesoftware.openfire.pubsub;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dom4j.Element;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import java.util.*;
/**
* A NodeAffiliate keeps information about the affiliation of an entity with a node. Possible
* affiliations are: owner, publisher, none or outcast. All except for outcast affiliations
......@@ -228,7 +232,7 @@ public class NodeAffiliate {
for(NodeSubscription subscription: notifySubscriptions) {
JID sub = subscription.getJID();
if (!subs.contains(sub)) {
node.sendEventNotification(subscription.getJID(), notification, null);
node.sendEventNotification(sub, notification, null);
subs.add(sub);
}
}
......
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