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 class
Presence.Mode
An enum to represent the presence mode.static class
Presence.Type
An enum to represent the presence type.
-
Constructor Summary
Constructors Constructor Description Presence(Presence other)
Copy constructor.Presence(Presence.Type type)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.Presence(Presence.Type type, String status, int priority, Presence.Mode mode)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.Presence(Jid to, Presence.Type type)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PresenceBuilder
asBuilder()
PresenceBuilder
asBuilder(String id)
PresenceBuilder
asBuilder(XMPPConnection connection)
Presence
clone()
Deprecated.useasBuilder()
instead.Presence
cloneWithNewId()
Deprecated.useasBuilder(XMPPConnection)
orasBuilder(String)
instead.String
getElementName()
Returns the root element name.Presence.Mode
getMode()
Returns the mode of the presence update.int
getPriority()
Returns the priority of the presence.byte
getPriorityByte()
Returns the priority of the presence.String
getStatus()
Returns the status message of the presence update, ornull
if there is not a status.Presence.Type
getType()
Returns the type of this presence stanza.boolean
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.boolean
isAway()
Returns true if the presence type isavailable
and the presence mode isaway
,extended away
, ordo not disturb
.void
setMode(Presence.Mode mode)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.void
setPriority(byte priority)
void
setPriority(int priority)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.void
setStatus(String status)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.void
setType(Presence.Type type)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.String
toString()
Returns a short String describing the Stanza.XmlStringBuilder
toXML(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 String ELEMENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Presence
@Deprecated public Presence(Presence.Type type)
Deprecated.usePresenceBuilder
orXMPPConnection.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.usePresenceBuilder
orXMPPConnection.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, String status, int priority, Presence.Mode mode)
Deprecated.usePresenceBuilder
orXMPPConnection.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 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
public boolean 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
public Presence.Type 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.
-
setType
@Deprecated public void setType(Presence.Type type)
Deprecated.usePresenceBuilder
orXMPPConnection.getStanzaFactory()
instead.Sets the type of the presence packet.- Parameters:
type
- the type of the presence packet.
-
getStatus
public String 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.
-
setStatus
@Deprecated public void setStatus(String status)
Deprecated.usePresenceBuilder
orXMPPConnection.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:PresenceView
Returns the priority of the presence.- Specified by:
getPriority
in interfacePresenceView
- Returns:
- the priority.
- See Also:
- RFC 6121 § 4.7.2.3. Priority Element
-
getPriorityByte
public byte getPriorityByte()
Description copied from interface:PresenceView
Returns the priority of the presence.- Specified by:
getPriorityByte
in interfacePresenceView
- Returns:
- the priority.
- See Also:
- RFC 6121 § 4.7.2.3. Priority Element
-
setPriority
@Deprecated public void setPriority(int priority)
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.- Throws:
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:PresenceView
Returns the mode of the presence update.- Specified by:
getMode
in interfacePresenceView
- Returns:
- the mode.
-
setMode
@Deprecated public void setMode(Presence.Mode mode)
Deprecated.usePresenceBuilder
orXMPPConnection.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 String getElementName()
Description copied from interface:NamedElement
Returns the root element name.- Specified by:
getElementName
in interfaceNamedElement
- Returns:
- the element name.
-
asBuilder
public PresenceBuilder asBuilder()
- Specified by:
asBuilder
in classMessageOrPresence<PresenceBuilder>
-
asBuilder
public PresenceBuilder asBuilder(String id)
- Specified by:
asBuilder
in classMessageOrPresence<PresenceBuilder>
-
asBuilder
public PresenceBuilder asBuilder(XMPPConnection connection)
- Specified by:
asBuilder
in classMessageOrPresence<PresenceBuilder>
-
toString
public String toString()
Description copied from class:Stanza
Returns 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.
-
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
-
-