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 enumAn enum to represent the presence mode.static enumAn 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.intReturns the priority of the presence.byteReturns the priority of the presence.Returns the status message of the presence update, ornullif there is not a status.getType()Returns the type of this presence stanza.booleanReturns true if thepresence typeis available (online) and false if the user is unavailable (offline), or if this is a presence packet involved in a subscription operation.booleanisAway()Returns true if the presence type isavailableand the presence mode isaway,extended away, ordo not disturb.voidsetPriority(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, throwIfNoStanzaIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtensionMethods 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
public boolean isAvailable()Returns true if thepresence typeis 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 awayordo not disturb. UseisAway()to determine if the user is away.- Returns:
- true if the presence type is available.
-
isAway
public boolean isAway()Returns true if the presence type isavailableand 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:PresenceViewReturns the type of this presence stanza.- Specified by:
getTypein interfacePresenceView- Returns:
- the type of the presence stanza.
-
getStatus
Description copied from interface:PresenceViewReturns the status message of the presence update, ornullif there is not a status. The status is free-form text describing a user's presence (i.e., "gone to lunch").- Specified by:
getStatusin interfacePresenceView- Returns:
- the status message.
-
getPriority
public int getPriority()Description copied from interface:PresenceViewReturns the priority of the presence.- Specified by:
getPriorityin interfacePresenceView- Returns:
- the priority.
- See Also:
-
getPriorityByte
public byte getPriorityByte()Description copied from interface:PresenceViewReturns the priority of the presence.- Specified by:
getPriorityBytein interfacePresenceView- Returns:
- the priority.
- See Also:
-
setPriority
Deprecated.usePresenceBuilderorXMPPConnection.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:PresenceViewReturns the mode of the presence update.- Specified by:
getModein interfacePresenceView- Returns:
- the mode.
-
getElementName
Description copied from interface:NamedElementReturns the root element name.- Specified by:
getElementNamein interfaceNamedElement- Returns:
- the element name.
-
asBuilder
- Specified by:
asBuilderin classMessageOrPresence<PresenceBuilder>
-
asBuilder
- Specified by:
asBuilderin classMessageOrPresence<PresenceBuilder>
-
asBuilder
- Specified by:
asBuilderin classMessageOrPresence<PresenceBuilder>
-
toString
Description copied from class:StanzaReturns a short String describing the Stanza. This method is suited for log purposes. -
toXML
-
PresenceBuilderorXMPPConnection.getStanzaFactory()instead.