1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-22 20:12:07 +01:00

Check that service is MUC service in getHostedRooms()

and otherwhise throw a NotAMucServiceException.
This commit is contained in:
Florian Schmaus 2015-07-17 09:07:29 +02:00
parent 2e03f0f3f3
commit 19ebcb814b
2 changed files with 13 additions and 2 deletions

View file

@ -17,6 +17,7 @@
package org.jivesoftware.smackx.muc; package org.jivesoftware.smackx.muc;
import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.SmackException;
import org.jxmpp.jid.DomainBareJid;
public abstract class MultiUserChatException extends SmackException { public abstract class MultiUserChatException extends SmackException {
@ -96,7 +97,12 @@ public abstract class MultiUserChatException extends SmackException {
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public NotAMucServiceException(MultiUserChat multiUserChat) { NotAMucServiceException(DomainBareJid service) {
super("Can't perform operation because " + service
+ " does not provide a MUC (XEP-45) service.");
}
NotAMucServiceException(MultiUserChat multiUserChat) {
super("Can not join '" + multiUserChat.getRoom() + "', because '" super("Can not join '" + multiUserChat.getRoom() + "', because '"
+ multiUserChat.getRoom().asDomainBareJid() + multiUserChat.getRoom().asDomainBareJid()
+ "' does not provide a MUC (XEP-45) service."); + "' does not provide a MUC (XEP-45) service.");

View file

@ -48,6 +48,7 @@ import org.jivesoftware.smackx.disco.AbstractNodeInformationProvider;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.disco.packet.DiscoverInfo; import org.jivesoftware.smackx.disco.packet.DiscoverInfo;
import org.jivesoftware.smackx.disco.packet.DiscoverItems; import org.jivesoftware.smackx.disco.packet.DiscoverItems;
import org.jivesoftware.smackx.muc.MultiUserChatException.NotAMucServiceException;
import org.jivesoftware.smackx.muc.packet.MUCInitialPresence; import org.jivesoftware.smackx.muc.packet.MUCInitialPresence;
import org.jivesoftware.smackx.muc.packet.MUCUser; import org.jivesoftware.smackx.muc.packet.MUCUser;
import org.jxmpp.jid.EntityBareJid; import org.jxmpp.jid.EntityBareJid;
@ -290,9 +291,13 @@ public final class MultiUserChatManager extends Manager {
* @throws NoResponseException * @throws NoResponseException
* @throws NotConnectedException * @throws NotConnectedException
* @throws InterruptedException * @throws InterruptedException
* @throws NotAMucServiceException
*/ */
public List<HostedRoom> getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException, public List<HostedRoom> getHostedRooms(DomainBareJid serviceName) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException { NotConnectedException, InterruptedException, NotAMucServiceException {
if (!providesMucService(serviceName)) {
throw new NotAMucServiceException(serviceName);
}
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection()); ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection());
DiscoverItems discoverItems = discoManager.discoverItems(serviceName); DiscoverItems discoverItems = discoManager.discoverItems(serviceName);
List<DiscoverItems.Item> items = discoverItems.getItems(); List<DiscoverItems.Item> items = discoverItems.getItems();