/** * 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); } } } }
/** * The subscription has been approved by a node owner. The subscription is now active so the * subscriber is now allowed to get event notifications. */ void approved() { if (state == State.subscribed) { // Do nothing return; } state = State.subscribed; if (savedToDB) { // Update the subscription in the backend store PubSubPersistenceManager.saveSubscription(service, node, this, false); } // 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); } } }