1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-14 06:51:08 +01:00

Add API to find services for a given feature

It's a common pattern to look for all services hosted under the users
service that provide a given feature. Let's provide an API for that and
use that API in the methods that benefit from it.
This commit is contained in:
Florian Schmaus 2014-07-25 20:49:11 +02:00
parent 6b7fa4a788
commit 7b3331dda0
5 changed files with 95 additions and 93 deletions

View file

@ -260,16 +260,8 @@ public class MultiUserChat {
* @throws NotConnectedException
*/
public static Collection<String> getServiceNames(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException {
final List<String> answer = new ArrayList<String>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(connection.getServiceName());
for (DiscoverItems.Item item : items.getItems()) {
DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
if (info.containsFeature(MUCInitialPresence.NAMESPACE)) {
answer.add(item.getEntityID());
}
}
return answer;
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
return sdm.findServices(MUCInitialPresence.NAMESPACE, false, false);
}
/**