Search in sources :

Example 1 with MucNotJoinedException

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

the class MultiUserChat method changeNickname.

/**
     * Changes the occupant's nickname to a new nickname within the room. Each room occupant
     * will receive two presence packets. One of type "unavailable" for the old nickname and one
     * indicating availability for the new nickname. The unavailable presence will contain the new
     * nickname and an appropriate status code (namely 303) as extended presence information. The
     * status code 303 indicates that the occupant is changing his/her nickname.
     *
     * @param nickname the new nickname within the room.
     * @throws XMPPErrorException if the new nickname is already in use by another occupant.
     * @throws NoResponseException if there was no response from the server.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * @throws MucNotJoinedException 
     */
public synchronized void changeNickname(Resourcepart nickname) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, MucNotJoinedException {
    StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
    // nickname.
    if (!joined) {
        throw new MucNotJoinedException(this);
    }
    final EntityFullJid jid = JidCreate.fullFrom(room, nickname);
    // We change the nickname by sending a presence packet where the "to"
    // field is in the form "roomName@service/nickname"
    // We don't have to signal the MUC support again
    Presence joinPresence = new Presence(Presence.Type.available);
    joinPresence.setTo(jid);
    // Wait for a presence packet back from the server.
    StanzaFilter responseFilter = new AndFilter(FromMatchesFilter.createFull(jid), new StanzaTypeFilter(Presence.class));
    StanzaCollector response = connection.createStanzaCollectorAndSend(responseFilter, joinPresence);
    // Wait up to a certain number of seconds for a reply. If there is a negative reply, an
    // exception will be thrown
    response.nextResultOrThrow();
    this.nickname = nickname;
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) EntityFullJid(org.jxmpp.jid.EntityFullJid) Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence) MucNotJoinedException(org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 2 with MucNotJoinedException

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

the class MultiUserChat method changeAvailabilityStatus.

/**
     * Changes the occupant's availability status within the room. The presence type
     * will remain available but with a new status that describes the presence update and
     * a new presence mode (e.g. Extended away).
     *
     * @param status a text message describing the presence update.
     * @param mode the mode type for the presence update.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * @throws MucNotJoinedException 
     */
public void changeAvailabilityStatus(String status, Presence.Mode mode) throws NotConnectedException, InterruptedException, MucNotJoinedException {
    StringUtils.requireNotNullOrEmpty(nickname, "Nickname must not be null or blank.");
    // availability status.
    if (!joined) {
        throw new MucNotJoinedException(this);
    }
    // We change the availability status by sending a presence packet to the room with the
    // new presence status and mode
    Presence joinPresence = new Presence(Presence.Type.available);
    joinPresence.setStatus(status);
    joinPresence.setMode(mode);
    joinPresence.setTo(JidCreate.fullFrom(room, nickname));
    // Send join packet.
    connection.sendStanza(joinPresence);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence) MucNotJoinedException(org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException)

Aggregations

Presence (org.jivesoftware.smack.packet.Presence)2 MucNotJoinedException (org.jivesoftware.smackx.muc.MultiUserChatException.MucNotJoinedException)2 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)2 StanzaCollector (org.jivesoftware.smack.StanzaCollector)1 AndFilter (org.jivesoftware.smack.filter.AndFilter)1 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)1 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)1 EntityFullJid (org.jxmpp.jid.EntityFullJid)1