/** * Configures the subscription based on the sent {@link DataForm} included in the IQ packet sent * by the subscriber. If the subscription was pending of configuration then the last published * item is going to be sent to the subscriber. * * <p>The originalIQ parameter may be <tt>null</tt> when using this API internally. When no IQ * packet was sent then no IQ result will be sent to the sender. The rest of the functionality is * the same. * * @param originalIQ the IQ packet sent by the subscriber to configure his subscription or null * when using this API internally. * @param options the data form containing the new subscription configuration. */ public void configure(IQ originalIQ, DataForm options) { boolean wasUnconfigured = isConfigurationPending(); // Change the subscription configuration based on the completed form configure(options); if (originalIQ != null) { // Return success response service.send(IQ.createResultIQ(originalIQ)); } if (wasUnconfigured) { // If subscription is pending then send notification to node owners // asking to approve the now configured subscription if (isAuthorizationPending()) { sendAuthorizationRequest(); } // Send last published item (if node is leaf node and subscription status is ok) if (node.isSendItemSubscribe() && isActive()) { PublishedItem lastItem = node.getLastPublishedItem(); if (lastItem != null) { sendLastPublishedItem(lastItem); } } } }
/** * Sends an request to authorize the pending subscription to the specified owner. * * @param owner the JID of the user that will get the authorization request. */ public void sendAuthorizationRequest(JID owner) { Message authRequest = new Message(); authRequest.addExtension(node.getAuthRequestForm(this)); authRequest.setTo(owner); authRequest.setFrom(service.getAddress()); // Send authentication request to node owners service.send(authRequest); }
/** * Sends the current subscription status to the user that tried to create a subscription to the * node. The subscription status is sent to the subsciber after the subscription was created or if * the subscriber tries to subscribe many times and the node does not support multpiple * subscriptions. * * @param originalRequest the IQ packet sent by the subscriber to create the subscription. */ void sendSubscriptionState(IQ originalRequest) { IQ result = IQ.createResultIQ(originalRequest); Element child = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub"); Element entity = child.addElement("subscription"); if (!node.isRootCollectionNode()) { entity.addAttribute("node", node.getNodeID()); } entity.addAttribute("jid", getJID().toString()); if (node.isMultipleSubscriptionsEnabled()) { entity.addAttribute("subid", getID()); } entity.addAttribute("subscription", getState().name()); Element subscribeOptions = entity.addElement("subscribe-options"); if (node.isSubscriptionConfigurationRequired() && isConfigurationPending()) { subscribeOptions.addElement("required"); } // Send the result service.send(result); }