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
public final class Presence extends MessageOrPresence<PresenceBuilder> implements PresenceView
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 Classes Modifier and Type Class Description static classPresence.ModeAn enum to represent the presence mode.static classPresence.TypeAn enum to represent the presence type.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PresenceBuilderasBuilder()PresenceBuilderasBuilder(java.lang.String id)PresenceBuilderasBuilder(XMPPConnection connection)java.lang.StringgetElementName()Returns the root element name.Presence.ModegetMode()Returns the mode of the presence update.intgetPriority()Returns the priority of the presence.bytegetPriorityByte()Returns the priority of the presence.java.lang.StringgetStatus()Returns the status message of the presence update, ornullif there is not a status.Presence.TypegetType()Returns the type of this presence stanza.booleanisAvailable()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.booleanisAway()Returns true if the presence type isavailableand the presence mode isaway,extended away, ordo not disturb.voidsetPriority(byte priority)Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.java.lang.StringtoString()Returns a short String describing the Stanza.XmlStringBuildertoXML(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 Detail
-
ELEMENT
public static final java.lang.String ELEMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Presence
public Presence(Presence other)
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 Detail
-
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
public Presence.Type getType()
Description copied from interface:PresenceViewReturns the type of this presence stanza.- Specified by:
getTypein interfacePresenceView- Returns:
- the type of the presence stanza.
-
getStatus
public java.lang.String 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:
- RFC 6121 § 4.7.2.3. Priority Element
-
getPriorityByte
public byte getPriorityByte()
Description copied from interface:PresenceViewReturns the priority of the presence.- Specified by:
getPriorityBytein interfacePresenceView- Returns:
- the priority.
- See Also:
- RFC 6121 § 4.7.2.3. Priority Element
-
setPriority
@Deprecated public void setPriority(byte priority)
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:
- RFC 6121 § 4.7.2.3. Priority Element
-
getMode
public Presence.Mode getMode()
Description copied from interface:PresenceViewReturns the mode of the presence update.- Specified by:
getModein interfacePresenceView- Returns:
- the mode.
-
getElementName
public java.lang.String getElementName()
Description copied from interface:NamedElementReturns the root element name.- Specified by:
getElementNamein interfaceNamedElement- Returns:
- the element name.
-
asBuilder
public PresenceBuilder asBuilder()
- Specified by:
asBuilderin classMessageOrPresence<PresenceBuilder>
-
asBuilder
public PresenceBuilder asBuilder(java.lang.String id)
- Specified by:
asBuilderin classMessageOrPresence<PresenceBuilder>
-
asBuilder
public PresenceBuilder asBuilder(XMPPConnection connection)
- Specified by:
asBuilderin classMessageOrPresence<PresenceBuilder>
-
toString
public java.lang.String toString()
Description copied from class:StanzaReturns a short String describing the Stanza. This method is suited for log purposes.
-
toXML
public XmlStringBuilder toXML(XmlEnvironment enclosingNamespace)
-
-