diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java index 8c5a98ccd..33e36e76b 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/muc/MultiUserChatManager.java @@ -19,6 +19,7 @@ package org.jivesoftware.smackx.muc; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -392,19 +393,46 @@ public final class MultiUserChatManager extends Manager { * @throws NotConnectedException * @throws InterruptedException * @throws NotAMucServiceException + * @deprecated use {@link #getRoomsHostedBy(DomainBareJid)} instead. */ + @Deprecated + // TODO: Remove in Smack 4.4. public List getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotAMucServiceException { + Map hostedRooms = getRoomsHostedBy(serviceName); + return new ArrayList<>(hostedRooms.values()); + } + + /** + * Returns a Map of HostedRooms where each HostedRoom has the XMPP address of the room and the room's name. + * Once discovered the rooms hosted by a chat service it is possible to discover more detailed room information or + * join the room. + * + * @param serviceName the service that is hosting the rooms to discover. + * @return a map from the room's address to its HostedRoom information. + * @throws XMPPErrorException + * @throws NoResponseException + * @throws NotConnectedException + * @throws InterruptedException + * @throws NotAMucServiceException + * @since 4.3.1 + */ + public Map getRoomsHostedBy(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, + NotConnectedException, InterruptedException, NotAMucServiceException { if (!providesMucService(serviceName)) { throw new NotAMucServiceException(serviceName); } ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection()); DiscoverItems discoverItems = discoManager.discoverItems(serviceName); List items = discoverItems.getItems(); - List answer = new ArrayList(items.size()); + + Map answer = new HashMap<>(items.size()); for (DiscoverItems.Item item : items) { - answer.add(new HostedRoom(item)); + HostedRoom hostedRoom = new HostedRoom(item); + HostedRoom previousRoom = answer.put(hostedRoom.getJid(), hostedRoom); + assert previousRoom == null; } + return answer; }