From 6af5705ae5b9f1c32ece6e7f50e11fe04eec2ae6 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Sun, 6 Feb 2005 16:36:23 +0000 Subject: [PATCH] Added support for discovering the rooms hosted by a MUC service. SMACK-13 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2455 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/muc/MultiUserChat.java | 22 +++++++++++++++++++ .../smackx/muc/MultiUserChatTest.java | 8 +++++++ 2 files changed, 30 insertions(+) diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java index cdcd2e115..d56478c88 100644 --- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -216,6 +216,28 @@ public class MultiUserChat { return answer; } + /** + * Returns a collection 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 connection the XMPP connection to use for discovering hosted rooms by the MUC service. + * @param serviceName the service that is hosting the rooms to discover. + * @return a collection of HostedRooms. + * @throws XMPPException if an error occured while trying to discover the information. + */ + public static Collection getHostedRooms(XMPPConnection connection, String serviceName) + throws XMPPException { + List answer = new ArrayList(); + ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); + DiscoverItems items = discoManager.discoverItems(serviceName); + for (Iterator it = items.getItems(); it.hasNext();) { + DiscoverItems.Item item = (DiscoverItems.Item) it.next(); + answer.add(new HostedRoom(item)); + } + return answer; + } + /** * Returns the name of the room this MultiUserChat object represents. * diff --git a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java index 936b21cbd..2a09f5b27 100644 --- a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java +++ b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java @@ -420,6 +420,14 @@ public class MultiUserChatTest extends SmackTestCase { try { Collection services = MultiUserChat.getServiceNames(getConnection(1)); assertFalse("No MUC service was found", services.isEmpty()); + + // Discover the hosted rooms by the chat service. + Collection rooms = MultiUserChat.getHostedRooms(getConnection(1), + (String) services.toArray()[0]); + // Check that we have discovered the room used by this test + assertFalse("No room was found", rooms.isEmpty()); + // Check that we have discovered the room used by this test + assertEquals("Wrong room JID found", room, ((HostedRoom)rooms.toArray()[0]).getJid()); } catch (XMPPException e) { e.printStackTrace();