mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-12-23 13:07:59 +01:00
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
This commit is contained in:
parent
3fe4678384
commit
6af5705ae5
2 changed files with 30 additions and 0 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue