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();
}
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);
}
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);
}
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);
}
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;
}
Aggregations