Package org.jivesoftware.smack.packet
Class Presence
java.lang.Object
org.jivesoftware.smack.packet.Stanza
org.jivesoftware.smack.packet.MessageOrPresence<PresenceBuilder>
org.jivesoftware.smack.packet.Presence
- All Implemented Interfaces:
Element
,NamedElement
,PresenceView
,StanzaView
,TopLevelStreamElement
,XmlElement
,XmlLangElement
Represents XMPP presence stanzas. Every presence stanza has a type, which is one of
the following values:
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 stanza contains an error message.
A number of attributes are optional:
- Status -- free-form text describing a user's presence (i.e., gone to lunch).
- Priority -- non-negative numerical priority of a sender's resource. The highest resource priority is the default recipient of packets not addressed to a particular resource.
- Mode -- one of five presence modes:
available
(the default),chat
,away
,xa
(extended away), anddnd
(do not disturb).
Presence stanzas 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
An enum to represent the presence mode.static enum
An enum to represent the presence type. -
Field Summary
FieldsFields inherited from class org.jivesoftware.smack.packet.Stanza
DEFAULT_LANGUAGE, ITEM, language, TEXT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasBuilder
(XMPPConnection connection) Returns the root element name.getMode()
Returns the mode of the presence update.int
Returns the priority of the presence.byte
Returns the priority of the presence.Returns the status message of the presence update, ornull
if there is not a status.getType()
Returns the type of this presence stanza.boolean
Returns true if thepresence 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 isavailable
and the presence mode isaway
,extended away
, ordo not disturb
.void
setPriority
(byte priority) Deprecated.toString()
Returns a short String describing the Stanza.toXML
(XmlEnvironment enclosingNamespace) Methods inherited from class org.jivesoftware.smack.packet.Stanza
addCommonAttributes, addExtension, addExtensions, appendErrorIfExists, getDefaultLanguage, getError, getExtension, getExtension, getExtensionElement, getExtensions, getExtensions, getExtensions, getExtensions, getExtensionsMap, getFrom, getLanguage, getNamespace, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, setError, setFrom, setNewStanzaId, setStanzaId, setTo, throwIfNoStanzaId
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtension
Methods inherited from interface org.jivesoftware.smack.packet.XmlElement
getQName
-
Field Details
-
ELEMENT
- See Also:
-
-
Constructor Details
-
Presence
Copy constructor.This does not perform a deep clone, as extension elements are shared between the new and old instance.
- Parameters:
other
- TODO javadoc me please
-
-
Method Details
-
isAvailable
Returns true if thepresence 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 togetType() == Presence.Type.available
. Note that even when the user is available, their presence mode may beaway
,extended away
ordo not disturb
. UseisAway()
to determine if the user is away.- Returns:
- true if the presence type is available.
-
isAway
Returns true if the presence type isavailable
and the presence mode isaway
,extended away
, ordo 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 totype == Type.available && (mode == Mode.away || mode == Mode.xa || mode == Mode.dnd)
.- Returns:
- true if the presence type is available and the presence mode is away, xa, or dnd.
-
getType
Description copied from interface:PresenceView
Returns the type of this presence stanza.- Specified by:
getType
in interfacePresenceView
- Returns:
- the type of the presence stanza.
-
getStatus
Description copied from interface:PresenceView
Returns the status message of the presence update, ornull
if there is not a status. The status is free-form text describing a user's presence (i.e., "gone to lunch").- Specified by:
getStatus
in interfacePresenceView
- Returns:
- the status message.
-
getPriority
Description copied from interface:PresenceView
Returns the priority of the presence.- Specified by:
getPriority
in interfacePresenceView
- Returns:
- the priority.
- See Also:
-
getPriorityByte
Description copied from interface:PresenceView
Returns the priority of the presence.- Specified by:
getPriorityByte
in interfacePresenceView
- Returns:
- the priority.
- See Also:
-
setPriority
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.Sets the priority of the presence. The valid range is -128 through 127.- Parameters:
priority
- the priority of the presence.- See Also:
-
getMode
Description copied from interface:PresenceView
Returns the mode of the presence update.- Specified by:
getMode
in interfacePresenceView
- Returns:
- the mode.
-
getElementName
Description copied from interface:NamedElement
Returns the root element name.- Specified by:
getElementName
in interfaceNamedElement
- Returns:
- the element name.
-
asBuilder
- Specified by:
asBuilder
in classMessageOrPresence<PresenceBuilder>
-
asBuilder
- Specified by:
asBuilder
in classMessageOrPresence<PresenceBuilder>
-
asBuilder
- Specified by:
asBuilder
in classMessageOrPresence<PresenceBuilder>
-
toString
Description copied from class:Stanza
Returns a short String describing the Stanza. This method is suited for log purposes. -
toXML
-
PresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.