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,FullyQualifiedElement,NamedElement,PresenceView,StanzaView,TopLevelStreamElement,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.
-
Constructor Summary
Constructors Constructor Description Presence(Presence other)Copy constructor.Presence(Presence.Type type)Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Presence(Presence.Type type, java.lang.String status, int priority, Presence.Mode mode)Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Presence(Jid to, Presence.Type type)Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PresenceBuilderasBuilder()PresenceBuilderasBuilder(java.lang.String id)PresenceBuilderasBuilder(XMPPConnection connection)Presenceclone()Deprecated.useasBuilder()instead.PresencecloneWithNewId()Deprecated.useasBuilder(XMPPConnection)orasBuilder(String)instead.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.voidsetMode(Presence.Mode mode)Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.voidsetPriority(byte priority)voidsetPriority(int priority)Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.voidsetStatus(java.lang.String status)Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.voidsetType(Presence.Type type)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, getExtension, getExtensionElement, getExtensions, getExtensions, getExtensions, getExtensions, getExtensionsMap, getFrom, getLanguage, getNamespace, getStanzaId, getTo, hasExtension, hasExtension, hasStanzaIdSet, logCommonAttributes, overrideExtension, removeExtension, removeExtension, setError, setError, setFrom, setLanguage, setNewStanzaId, setStanzaId, setStanzaId, setTo, throwIfNoStanzaId
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.smack.packet.FullyQualifiedElement
getQName
-
Methods inherited from interface org.jivesoftware.smack.packet.StanzaView
getError, getExtension, getExtension, getExtensions, getExtensions, getExtensions, getFrom, getStanzaId, getTo, hasExtension, hasExtension, hasExtension
-
-
-
-
Field Detail
-
ELEMENT
public static final java.lang.String ELEMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Presence
@Deprecated public Presence(Presence.Type type)
Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Creates a new presence update. Status, priority, and mode are left un-set.- Parameters:
type- the type.
-
Presence
@Deprecated public Presence(Jid to, Presence.Type type)
Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Creates a new presence with the given type and using the given XMPP address as recipient.- Parameters:
to- the recipient.type- the type.- Since:
- 4.2
-
Presence
@Deprecated public Presence(Presence.Type type, java.lang.String status, int priority, Presence.Mode mode)
Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Creates a new presence update with a specified status, priority, and mode.- Parameters:
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.
-
-
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.
-
setType
@Deprecated public void setType(Presence.Type type)
Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Sets the type of the presence packet.- Parameters:
type- the type of the presence packet.
-
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.
-
setStatus
@Deprecated public void setStatus(java.lang.String status)
Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Sets the status message of the presence update. The status is free-form text describing a user's presence (i.e., "gone to lunch").- Parameters:
status- 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(int 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.- Throws:
java.lang.IllegalArgumentException- if the priority is outside the valid range.- See Also:
- RFC 6121 § 4.7.2.3. Priority Element
-
setPriority
public void setPriority(byte priority)
-
getMode
public Presence.Mode getMode()
Description copied from interface:PresenceViewReturns the mode of the presence update.- Specified by:
getModein interfacePresenceView- Returns:
- the mode.
-
setMode
@Deprecated public void setMode(Presence.Mode mode)
Deprecated.usePresenceBuilderorXMPPConnection.getStanzaFactory()instead.Sets the mode of the presence update. A null presence mode value is interpreted to be the same thing asPresence.Mode.available.- Parameters:
mode- 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)
-
clone
@Deprecated public Presence clone()
Deprecated.useasBuilder()instead.Creates and returns a copy of this presence stanza.This does not perform a deep clone, as extension elements are shared between the new and old instance.
- Overrides:
clonein classjava.lang.Object- Returns:
- a clone of this presence.
-
cloneWithNewId
@Deprecated public Presence cloneWithNewId()
Deprecated.useasBuilder(XMPPConnection)orasBuilder(String)instead.Clone this presence and set a newly generated stanza ID as the clone's ID.- Returns:
- a "clone" of this presence with a different stanza ID.
- Since:
- 4.1.2
-
-