Commit 1771dc01 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Split "retrieve current subscriptions" and "retrieve current afilliations" to track the 1.8 spec.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3757 b35dd754-fafc-0310-a699-88a17e54d16e
parent 70c3fee9
......@@ -151,6 +151,12 @@ public class PubSubEngine {
unsubscribeNode(iq, action);
return true;
}
action = childElement.element("subscriptions");
if (action != null) {
// Entity requests all current subscriptions
getSubscriptions(iq, childElement);
return true;
}
action = childElement.element("affiliations");
if (action != null) {
// Entity requests all current affiliations
......@@ -867,61 +873,75 @@ public class PubSubEngine {
}
}
private void getAffiliations(IQ iq, Element childElement) {
private void getSubscriptions(IQ iq, Element childElement) {
// TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet
JID owner = new JID(iq.getFrom().toBareJID());
// Collect subscriptions (and implicit affiliations) or affiliations for
// which a subscription does not exists (e.g. outcast user)
// Collect subscriptions of owner for all nodes at the service
Collection<NodeSubscription> subscriptions = new ArrayList<NodeSubscription>();
Collection<NodeAffiliate> affiliations = new ArrayList<NodeAffiliate>();
for (Node node : service.getNodes()) {
Collection<NodeSubscription> nodeSubscriptions = node.getSubscriptions(owner);
if (!nodeSubscriptions.isEmpty()) {
subscriptions.addAll(nodeSubscriptions);
}
else {
NodeAffiliate nodeAffiliate = node.getAffiliate(owner);
if (nodeAffiliate != null) {
affiliations.add(nodeAffiliate);
}
}
subscriptions.addAll(node.getSubscriptions(owner));
}
// Create reply to send
IQ reply = IQ.createResultIQ(iq);
Element replyChildElement = childElement.createCopy();
reply.setChildElement(replyChildElement);
if (subscriptions.isEmpty() && affiliations.isEmpty()) {
if (subscriptions.isEmpty()) {
// User does not have any affiliation or subscription with the pubsub service
reply.setError(PacketError.Condition.item_not_found);
}
else {
Element affiliationsElement = replyChildElement.element("affiliations");
// Add information about affiliations without subscriptions
for (NodeAffiliate affiliate : affiliations) {
Element entity = affiliationsElement.addElement("entity");
// Do not include the node id when node is the root collection node
if (!affiliate.getNode().isRootCollectionNode()) {
entity.addAttribute("node", affiliate.getNode().getNodeID());
}
entity.addAttribute("jid", affiliate.getJID().toString());
entity.addAttribute("affiliation", affiliate.getAffiliation().name());
entity.addAttribute("subscription", NodeSubscription.State.none.name());
}
Element affiliationsElement = replyChildElement.element("subscriptions");
// Add information about subscriptions including existing affiliations
for (NodeSubscription subscription : subscriptions) {
Element entity = affiliationsElement.addElement("entity");
Element subElement = affiliationsElement.addElement("subscription");
Node node = subscription.getNode();
NodeAffiliate nodeAffiliate = subscription.getAffiliate();
// Do not include the node id when node is the root collection node
if (!node.isRootCollectionNode()) {
entity.addAttribute("node", node.getNodeID());
subElement.addAttribute("node", node.getNodeID());
}
entity.addAttribute("jid", subscription.getJID().toString());
entity.addAttribute("affiliation", nodeAffiliate.getAffiliation().name());
entity.addAttribute("subscription", subscription.getState().name());
subElement.addAttribute("jid", subscription.getJID().toString());
subElement.addAttribute("affiliation", nodeAffiliate.getAffiliation().name());
subElement.addAttribute("subscription", subscription.getState().name());
if (node.isMultipleSubscriptionsEnabled()) {
entity.addAttribute("subid", subscription.getID());
subElement.addAttribute("subid", subscription.getID());
}
}
}
// Send reply
router.route(reply);
}
private void getAffiliations(IQ iq, Element childElement) {
// TODO Assuming that owner is the bare JID (as defined in the JEP). This can be replaced with an explicit owner specified in the packet
JID owner = new JID(iq.getFrom().toBareJID());
// Collect affiliations of owner for all nodes at the service
Collection<NodeAffiliate> affiliations = new ArrayList<NodeAffiliate>();
for (Node node : service.getNodes()) {
NodeAffiliate nodeAffiliate = node.getAffiliate(owner);
if (nodeAffiliate != null) {
affiliations.add(nodeAffiliate);
}
}
// Create reply to send
IQ reply = IQ.createResultIQ(iq);
Element replyChildElement = childElement.createCopy();
reply.setChildElement(replyChildElement);
if (affiliations.isEmpty()) {
// User does not have any affiliation or subscription with the pubsub service
reply.setError(PacketError.Condition.item_not_found);
}
else {
Element affiliationsElement = replyChildElement.element("affiliations");
// Add information about affiliations without subscriptions
for (NodeAffiliate affiliate : affiliations) {
Element affiliateElement = affiliationsElement.addElement("affiliation");
// Do not include the node id when node is the root collection node
if (!affiliate.getNode().isRootCollectionNode()) {
affiliateElement.addAttribute("node", affiliate.getNode().getNodeID());
}
affiliateElement.addAttribute("jid", affiliate.getJID().toString());
affiliateElement.addAttribute("affiliation", affiliate.getAffiliation().name());
}
}
// Send reply
......
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