Search in sources :

Example 1 with MucAlreadyJoinedException

use of org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException in project Smack by igniterealtime.

the class MultiUserChat method createOrJoin.

/**
     * Like {@link #create(Resourcepart)}, but will return a {@link MucCreateConfigFormHandle} if the room creation was acknowledged by
     * the service (with an 201 status code). It's up to the caller to decide, based on the return
     * value, if he needs to continue sending the room configuration. If {@code null} is returned, the room
     * already existed and the user is able to join right away, without sending a form.
     *
     * @param mucEnterConfiguration the configuration used to enter the MUC.
     * @return A {@link MucCreateConfigFormHandle} if the room was created while joining, or {@code null} if the room was just joined.
     * @throws XMPPErrorException if the room couldn't be created for some reason (e.g. 405 error if
     *         the user is not allowed to create the room)
     * @throws NoResponseException if there was no response from the server.
     * @throws InterruptedException 
     * @throws MucAlreadyJoinedException if the MUC is already joined
     * @throws NotConnectedException 
     * @throws NotAMucServiceException 
     */
public synchronized MucCreateConfigFormHandle createOrJoin(MucEnterConfiguration mucEnterConfiguration) throws NoResponseException, XMPPErrorException, InterruptedException, MucAlreadyJoinedException, NotConnectedException, NotAMucServiceException {
    if (joined) {
        throw new MucAlreadyJoinedException();
    }
    Presence presence = enter(mucEnterConfiguration);
    // Look for confirmation of room creation from the server
    MUCUser mucUser = MUCUser.from(presence);
    if (mucUser != null && mucUser.getStatus().contains(Status.ROOM_CREATED_201)) {
        // Room was created and the user has joined the room
        return new MucCreateConfigFormHandle();
    }
    return null;
}
Also used : MucAlreadyJoinedException(org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence)

Aggregations

Presence (org.jivesoftware.smack.packet.Presence)1 MucAlreadyJoinedException (org.jivesoftware.smackx.muc.MultiUserChatException.MucAlreadyJoinedException)1 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)1 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)1