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

The PEPService.sendNotification method is now able to send to the full JID of...

The PEPService.sendNotification method is now able to send to the full JID of the recipient for all of its connected resources that the service has presence information about.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8852 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1d90be73
......@@ -480,10 +480,9 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
return;
}
// FIXME: Instead of the bare JID, use the full JID. Only change this
// when PEPService's sendNotification() is able to send to the full
// JID. See its FIXME as well.
String jidFrom = packet.getFrom().toBareJID();
// Get the sender's full JID considering they may be logged in from multiple
// clients with different notification filters.
String jidFrom = packet.getFrom().toString();
// For each feature variable, or in this case node ID, ending in "+notify" -- add
// the node ID to the set of filtered nodes that jidFrom is interested in being
......
......@@ -28,8 +28,10 @@ import org.jivesoftware.openfire.pubsub.models.AccessModel;
import org.jivesoftware.openfire.pubsub.models.PublisherModel;
import org.jivesoftware.openfire.roster.Roster;
import org.jivesoftware.openfire.roster.RosterItem;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.util.StringUtils;
import org.xmpp.packet.JID;
......@@ -37,6 +39,7 @@ import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketExtension;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
......@@ -313,11 +316,22 @@ public class PEPService implements PubSubService {
public void sendNotification(Node node, Message message, JID recipientJID) {
message.setFrom(getAddress());
// FIXME: Send to the full JID if this PEPService can retrieve presence
// for the recipient.
// If this PEPService can retrieve presence information for the recipient,
// collect all of their full JIDs and send the notification to each below.
Collection<JID> recipientFullJIDs = new ArrayList<JID>();
if (XMPPServer.getInstance().isLocal(recipientJID)) {
for (ClientSession clientSession : SessionManager.getInstance().getSessions(recipientJID.getNode())) {
recipientFullJIDs.add(clientSession.getAddress());
}
}
else {
recipientFullJIDs.add(recipientJID);
}
message.setTo(recipientJID);
message.setID(node.getNodeID() + "__" + recipientJID.toBareJID() + "__" + StringUtils.randomString(5));
for (JID recipientFullJID : recipientFullJIDs) {
// Include an Extended Stanza Addressing "replyto" extension specifying the publishing
// resource. However, only include the extension if the receiver has a presence subscription
// to the service owner.
......@@ -330,11 +344,11 @@ public class PEPService implements PubSubService {
String publishedItemID = itemsElement.element("item").attributeValue("id");
String nodeIDPublishedTo = itemsElement.attributeValue("node");
// Check if the recipientJID is interested in notifications for this node.
// Check if the recipientFullJID is interested in notifications for this node.
// If the recipient has not yet requested any notification filtering, continue and send
// the notification.
Map<String, HashSet<String>> filteredNodesMap = XMPPServer.getInstance().getIQPEPHandler().getFilteredNodesMap();
HashSet<String> filteredNodesSet = filteredNodesMap.get(recipientJID.toBareJID());
HashSet<String> filteredNodesSet = filteredNodesMap.get(recipientFullJID.toString());
if (filteredNodesSet != null && !filteredNodesSet.contains(nodeIDPublishedTo)) {
return;
}
......@@ -346,7 +360,7 @@ public class PEPService implements PubSubService {
// Ensure the recipientJID has access to receive notifications for items published to the leaf node.
AccessModel accessModel = leafNode.getAccessModel();
if (!accessModel.canAccessItems(leafNode, recipientJID, publisher)) {
if (!accessModel.canAccessItems(leafNode, recipientFullJID, publisher)) {
return;
}
......@@ -360,7 +374,7 @@ public class PEPService implements PubSubService {
// Ensure the recipient is subscribed to the service owner's (publisher's) presence.
Roster roster = XMPPServer.getInstance().getRosterManager().getRoster(publisher.getNode());
RosterItem item = roster.getRosterItem(recipientJID);
RosterItem item = roster.getRosterItem(recipientFullJID);
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
Element addresses = DocumentHelper.createElement(QName.get("addresses", "http://jabber.org/protocol/address"));
......@@ -371,7 +385,9 @@ public class PEPService implements PubSubService {
Message extendedMessage = message.createCopy();
extendedMessage.addExtension(new PacketExtension(addresses));
extendedMessage.setTo(recipientFullJID);
router.route(extendedMessage);
return;
}
}
......@@ -384,7 +400,7 @@ public class PEPService implements PubSubService {
catch (NullPointerException e) {
// Do not add addressing extension to message.
}
}
router.route(message);
}
......
......@@ -373,6 +373,7 @@ public class UserManager implements IQResultListener {
// Analyze the disco result packet
if (IQ.Type.result == packet.getType()) {
Element child = packet.getChildElement();
if (child != null) {
for (Iterator it=child.elementIterator("identity"); it.hasNext();) {
Element identity = (Element) it.next();
String accountType = identity.attributeValue("type");
......@@ -382,6 +383,7 @@ public class UserManager implements IQResultListener {
}
}
}
}
// Update cache of remote registered users
remoteUsersCache.put(from.toBareJID(), isRegistered);
......
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