public class Presence extends Packet
available
-- (Default) indicates the user is available to
receive messages.
unavailable
-- the user is unavailable to receive messages.
subscribe
-- request subscription to recipient's presence.
subscribed
-- grant subscription to sender's presence.
unsubscribe
-- request removal of subscription to
sender's presence.
unsubscribed
-- grant removal of subscription to
sender's presence.
error
-- the presence packet contains an error message.
A number of attributes are optional:
available
(the default),
chat
, away
, xa
(extended away), and
dnd
(do not disturb).
Presence packets are used for two purposes. First, to notify the server of the user's current presence status. Second, they are used to subscribe and unsubscribe users from the roster.
RosterPacket
Modifier and Type | Class and Description |
---|---|
static class |
Presence.Mode
An enum to represent the presence mode.
|
static class |
Presence.Type
An enum to represent the presence type.
|
DEFAULT_LANGUAGE, ID_NOT_AVAILABLE
Constructor and Description |
---|
Presence(Presence.Type type)
Creates a new presence update.
|
Presence(Presence.Type type,
String status,
int priority,
Presence.Mode mode)
Creates a new presence update with a specified status, priority, and mode.
|
Modifier and Type | Method and Description |
---|---|
String |
getLanguage()
Returns the xml:lang of this Presence, or null if one has not been set.
|
Presence.Mode |
getMode()
Returns the mode of the presence update, or null if the mode is not set.
|
int |
getPriority()
Returns the priority of the presence, or Integer.MIN_VALUE if no priority has been set.
|
String |
getStatus()
Returns the status message of the presence update, or null if there
is not a status.
|
Presence.Type |
getType()
Returns the type of this presence packet.
|
boolean |
isAvailable()
Returns true if the
presence type is available (online) and
false if the user is unavailable (offline), or if this is a presence packet
involved in a subscription operation. |
boolean |
isAway()
Returns true if the presence type is
available and the presence
mode is away , extended away , or
do not disturb . |
void |
setLanguage(String language)
Sets the xml:lang of this Presence.
|
void |
setMode(Presence.Mode mode)
Sets the mode of the presence update.
|
void |
setPriority(int priority)
Sets the priority of the presence.
|
void |
setStatus(String status)
Sets the status message of the presence update.
|
void |
setType(Presence.Type type)
Sets the type of the presence packet.
|
String |
toString() |
XmlStringBuilder |
toXML()
Returns the packet as XML.
|
addCommonAttributes, addExtension, addExtensions, equals, getDefaultLanguage, getError, getExtension, getExtension, getExtensions, getExtensionsXML, getFrom, getPacketID, getTo, getXmlns, hashCode, nextID, removeExtension, setDefaultXmlns, setError, setFrom, setPacketID, setTo
public Presence(Presence.Type type)
type
- the type.public Presence(Presence.Type type, String status, int priority, Presence.Mode mode)
type
- the type.status
- a text message describing the presence update.priority
- the priority of this presence update.mode
- the mode type for this presence update.public boolean isAvailable()
presence type
is available (online) and
false if the user is unavailable (offline), or if this is a presence packet
involved in a subscription operation. This is a convenience method
equivalent to getType() == Presence.Type.available. Note that even
when the user is available, their presence mode may be away
,
extended away
or do not disturb
. Use
isAway()
to determine if the user is away.public boolean isAway()
available
and the presence
mode is away
, extended away
, or
do not disturb
. False will be returned when the type or mode
is any other value, including when the presence type is unavailable (offline).
This is a convenience method equivalent to
type == Type.available && (mode == Mode.away || mode == Mode.xa || mode == Mode.dnd).public Presence.Type getType()
public void setType(Presence.Type type)
type
- the type of the presence packet.public String getStatus()
public void setStatus(String status)
status
- the status message.public int getPriority()
public void setPriority(int priority)
priority
- the priority of the presence.IllegalArgumentException
- if the priority is outside the valid range.public Presence.Mode getMode()
Presence.Mode.available
.public void setMode(Presence.Mode mode)
Presence.Mode.available
.mode
- the mode.public String getLanguage()
public void setLanguage(String language)
language
- the xml:lang of this Presence.public XmlStringBuilder toXML()
Packet