mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-26 00:02:06 +01:00
Add Node.getSubscriptionsAsOwner() in PubSub API
To retrieve the subscriptions of a PubSub node as owner. Fixes SMACK-623.
This commit is contained in:
parent
f029b576a5
commit
5c086eeefa
3 changed files with 125 additions and 2 deletions
|
@ -166,8 +166,56 @@ abstract public class Node
|
||||||
*/
|
*/
|
||||||
public List<Subscription> getSubscriptions(List<PacketExtension> additionalExtensions, Collection<PacketExtension> returnedExtensions)
|
public List<Subscription> getSubscriptions(List<PacketExtension> additionalExtensions, Collection<PacketExtension> returnedExtensions)
|
||||||
throws NoResponseException, XMPPErrorException, NotConnectedException {
|
throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||||
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(
|
return getSubscriptions(additionalExtensions, returnedExtensions, null);
|
||||||
PubSubElementType.SUBSCRIPTIONS, getId()));
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the subscriptions currently associated with this node as owner.
|
||||||
|
*
|
||||||
|
* @return List of {@link Subscription}
|
||||||
|
* @throws XMPPErrorException
|
||||||
|
* @throws NoResponseException
|
||||||
|
* @throws NotConnectedException
|
||||||
|
* @see #getSubscriptionsAsOwner(List, Collection)
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public List<Subscription> getSubscriptionsAsOwner() throws NoResponseException, XMPPErrorException,
|
||||||
|
NotConnectedException {
|
||||||
|
return getSubscriptionsAsOwner(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the subscriptions currently associated with this node as owner.
|
||||||
|
* <p>
|
||||||
|
* Unlike {@link #getSubscriptions(List, Collection)}, which only retrieves the subscriptions of the current entity
|
||||||
|
* ("user"), this method returns a list of <b>all</b> subscriptions. This requires the entity to have the sufficient
|
||||||
|
* privileges to manage subscriptions.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* {@code additionalExtensions} can be used e.g. to add a "Result Set Management" extension.
|
||||||
|
* {@code returnedExtensions} will be filled with the packet extensions found in the answer.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param additionalExtensions
|
||||||
|
* @param returnedExtensions a collection that will be filled with the returned packet extensions
|
||||||
|
* @return List of {@link Subscription}
|
||||||
|
* @throws NoResponseException
|
||||||
|
* @throws XMPPErrorException
|
||||||
|
* @throws NotConnectedException
|
||||||
|
* @see <a href="http://www.xmpp.org/extensions/xep-0060.html#owner-subscriptions-retrieve">XEP-60 § 8.8.1 -
|
||||||
|
* Retrieve Subscriptions List</a>
|
||||||
|
* @since 4.1
|
||||||
|
*/
|
||||||
|
public List<Subscription> getSubscriptionsAsOwner(List<PacketExtension> additionalExtensions,
|
||||||
|
Collection<PacketExtension> returnedExtensions) throws NoResponseException, XMPPErrorException,
|
||||||
|
NotConnectedException {
|
||||||
|
return getSubscriptions(additionalExtensions, returnedExtensions, PubSubNamespace.OWNER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Subscription> getSubscriptions(List<PacketExtension> additionalExtensions,
|
||||||
|
Collection<PacketExtension> returnedExtensions, PubSubNamespace pubSubNamespace)
|
||||||
|
throws NoResponseException, XMPPErrorException, NotConnectedException {
|
||||||
|
PubSub pubSub = createPubsubPacket(Type.get, new NodeExtension(PubSubElementType.SUBSCRIPTIONS, getId()), pubSubNamespace);
|
||||||
if (additionalExtensions != null) {
|
if (additionalExtensions != null) {
|
||||||
for (PacketExtension pe : additionalExtensions) {
|
for (PacketExtension pe : additionalExtensions) {
|
||||||
pubSub.addExtension(pe);
|
pubSub.addExtension(pe);
|
||||||
|
|
|
@ -339,6 +339,18 @@
|
||||||
<className>org.jivesoftware.smackx.pubsub.provider.FormNodeProvider</className>
|
<className>org.jivesoftware.smackx.pubsub.provider.FormNodeProvider</className>
|
||||||
</extensionProvider>
|
</extensionProvider>
|
||||||
|
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>subscriptions</elementName>
|
||||||
|
<namespace>http://jabber.org/protocol/pubsub#owner</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.pubsub.provider.SubscriptionsProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
|
<extensionProvider>
|
||||||
|
<elementName>subscription</elementName>
|
||||||
|
<namespace>http://jabber.org/protocol/pubsub#owner</namespace>
|
||||||
|
<className>org.jivesoftware.smackx.pubsub.provider.SubscriptionProvider</className>
|
||||||
|
</extensionProvider>
|
||||||
|
|
||||||
<!-- XEP-0060 pubsub#event -->
|
<!-- XEP-0060 pubsub#event -->
|
||||||
<extensionProvider>
|
<extensionProvider>
|
||||||
<elementName>event</elementName>
|
<elementName>event</elementName>
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright 2014 Florian Schmaus
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.jivesoftware.smackx.pubsub.provider;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.test.util.TestUtils;
|
||||||
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
import org.jivesoftware.smackx.pubsub.PubSubElementType;
|
||||||
|
import org.jivesoftware.smackx.pubsub.Subscription;
|
||||||
|
import org.jivesoftware.smackx.pubsub.SubscriptionsExtension;
|
||||||
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
|
||||||
|
public class PubSubProviderTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void subscriptionsOwnerResultTest() throws Exception {
|
||||||
|
// @formatter:off
|
||||||
|
final String resultStanza =
|
||||||
|
"<iq from='pubsub.example.org' to='julia@example.org/Smack' id='HaT4m-13' type='result'>" +
|
||||||
|
"<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" +
|
||||||
|
"<subscriptions node='test'>" +
|
||||||
|
"<subscription jid='foo@example.org/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" +
|
||||||
|
"<subscription jid='julia@example.org/Smack' subscription='subscribed' subid='58C18F8917321'/>" +
|
||||||
|
"</subscriptions>" +
|
||||||
|
"</pubsub>" +
|
||||||
|
"</iq>";
|
||||||
|
// @formatter:on
|
||||||
|
XmlPullParser parser = TestUtils.getIQParser(resultStanza);
|
||||||
|
PubSub pubsubResult = (PubSub) PacketParserUtils.parse(parser, null);
|
||||||
|
SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS);
|
||||||
|
List<Subscription> subscriptions = subElem.getSubscriptions();
|
||||||
|
assertEquals(2, subscriptions.size());
|
||||||
|
|
||||||
|
Subscription sub1 = subscriptions.get(0);
|
||||||
|
assertEquals("foo@example.org/Smack", sub1.getJid());
|
||||||
|
assertEquals(Subscription.State.subscribed, sub1.getState());
|
||||||
|
assertEquals("58C1A6F99F2A7", sub1.getId());
|
||||||
|
|
||||||
|
Subscription sub2 = subscriptions.get(1);
|
||||||
|
assertEquals("julia@example.org/Smack", sub2.getJid());
|
||||||
|
assertEquals(Subscription.State.subscribed, sub2.getState());
|
||||||
|
assertEquals("58C18F8917321", sub2.getId());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue