Search in sources :

Example 76 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class MultiUserChat method leave.

/**
     * Leave the chat room.
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public synchronized void leave() throws NotConnectedException, InterruptedException {
    // If not joined already, do nothing.
    if (!joined) {
        return;
    }
    // We leave a room by sending a presence packet where the "to"
    // field is in the form "roomName@service/nickname"
    Presence leavePresence = new Presence(Presence.Type.unavailable);
    leavePresence.setTo(JidCreate.fullFrom(room, nickname));
    connection.sendStanza(leavePresence);
    // Reset occupant information.
    occupantsMap.clear();
    nickname = null;
    joined = false;
    userHasLeft();
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) MUCInitialPresence(org.jivesoftware.smackx.muc.packet.MUCInitialPresence)

Example 77 with Presence

use of org.jivesoftware.smack.packet.Presence 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)

Example 78 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class Roster method sendSubscriptionRequest.

public void sendSubscriptionRequest(BareJid jid) throws NotLoggedInException, NotConnectedException, InterruptedException {
    final XMPPConnection connection = getAuthenticatedConnectionOrThrow();
    // Create a presence subscription packet and send.
    Presence presencePacket = new Presence(Presence.Type.subscribe);
    presencePacket.setTo(jid);
    connection.sendStanza(presencePacket);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 79 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class Roster method preApprove.

/**
     * Pre-approve user presence subscription.
     *
     * @param user the user. (e.g. johndoe@jabber.org)
     * @throws NotLoggedInException if not logged in.
     * @throws NotConnectedException
     * @throws InterruptedException
     * @throws FeatureNotSupportedException if pre-approving is not supported.
     * @since 4.2
     */
public void preApprove(BareJid user) throws NotLoggedInException, NotConnectedException, InterruptedException, FeatureNotSupportedException {
    final XMPPConnection connection = connection();
    if (!isSubscriptionPreApprovalSupported()) {
        throw new FeatureNotSupportedException("Pre-approving");
    }
    Presence presencePacket = new Presence(Presence.Type.subscribed);
    presencePacket.setTo(user);
    connection.sendStanza(presencePacket);
}
Also used : FeatureNotSupportedException(org.jivesoftware.smack.SmackException.FeatureNotSupportedException) Presence(org.jivesoftware.smack.packet.Presence) XMPPConnection(org.jivesoftware.smack.XMPPConnection)

Example 80 with Presence

use of org.jivesoftware.smack.packet.Presence in project Smack by igniterealtime.

the class Roster method getAvailablePresences.

/**
     * Returns a List of all <b>available</b> Presence Objects for the given bare JID. If there are no available
     * presences, then the empty list will be returned.
     *
     * @param bareJid the bare JID from which the presences should be retrieved.
     * @return available presences for the bare JID.
     */
public List<Presence> getAvailablePresences(BareJid bareJid) {
    List<Presence> allPresences = getAllPresences(bareJid);
    List<Presence> res = new ArrayList<>(allPresences.size());
    for (Presence presence : allPresences) {
        if (presence.isAvailable()) {
            // No need to clone presence here, getAllPresences already returns clones
            res.add(presence);
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) Presence(org.jivesoftware.smack.packet.Presence)

Aggregations

Presence (org.jivesoftware.smack.packet.Presence)103 Message (org.jivesoftware.smack.packet.Message)21 Resourcepart (org.jxmpp.jid.parts.Resourcepart)12 Jid (org.jxmpp.jid.Jid)11 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)10 AccountItem (com.xabber.android.data.account.AccountItem)9 UserJid (com.xabber.android.data.entity.UserJid)9 AccountJid (com.xabber.android.data.entity.AccountJid)7 StanzaCollector (org.jivesoftware.smack.StanzaCollector)7 AndFilter (org.jivesoftware.smack.filter.AndFilter)7 UserPresence (jetbrains.communicator.core.users.UserPresence)6 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)6 BareJid (org.jxmpp.jid.BareJid)6 ClientInfo (com.xabber.android.data.extension.capability.ClientInfo)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)5 Test (org.junit.Test)5 EntityFullJid (org.jxmpp.jid.EntityFullJid)5