Search in sources :

Example 6 with MUCOwner

use of org.jivesoftware.smackx.muc.packet.MUCOwner in project Smack by igniterealtime.

the class MultiUserChat method destroy.

/**
 * Sends a request to the server to destroy the room. The sender of the request
 * should be the room's owner. If the sender of the destroy request is not the room's owner
 * then the server will answer a "Forbidden" error (403).
 *
 * @param reason an optional reason for the room destruction.
 * @param alternateJID an optional JID of an alternate location.
 * @throws XMPPErrorException if an error occurs while trying to destroy the room.
 *      An error can occur which will be wrapped by an XMPPException --
 *      XMPP error code 403. The error code can be used to present more
 *      appropriate error messages to end-users.
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public void destroy(String reason, EntityBareJid alternateJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    MUCOwner iq = new MUCOwner();
    iq.setTo(room);
    iq.setType(IQ.Type.set);
    // Create the reason for the room destruction
    Destroy destroy = new Destroy(alternateJID, reason);
    iq.setDestroy(destroy);
    try {
        connection.sendIqRequestAndWaitForResponse(iq);
    } catch (XMPPErrorException e) {
        // room was not destroyed and we therefore we also did not leave the room.
        throw e;
    } catch (NoResponseException | NotConnectedException | InterruptedException e) {
        // Reset occupant information.
        userHasLeft();
        throw e;
    }
    // Reset occupant information.
    userHasLeft();
}
Also used : XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) Destroy(org.jivesoftware.smackx.muc.packet.Destroy) MUCOwner(org.jivesoftware.smackx.muc.packet.MUCOwner) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException)

Aggregations

MUCOwner (org.jivesoftware.smackx.muc.packet.MUCOwner)6 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)2 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)1 IQ (org.jivesoftware.smack.packet.IQ)1 XmlPullParser (org.jivesoftware.smack.xml.XmlPullParser)1 Destroy (org.jivesoftware.smackx.muc.packet.Destroy)1 FillableForm (org.jivesoftware.smackx.xdata.form.FillableForm)1 Form (org.jivesoftware.smackx.xdata.form.Form)1