Class 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), and dnd (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.

    • Constructor Detail

      • Presence

        @Deprecated
        public Presence​(org.jxmpp.jid.Jid to,
                        Presence.Type type)
        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)
        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.
      • 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 the presence 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 to getType() == Presence.Type.available. Note that even when the user is available, their presence mode may be away, extended away or do not disturb. Use isAway() 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 is available and the presence mode is away, extended away, or do 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 to type == 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 interface PresenceView
        Returns:
        the type of the presence stanza.
      • getStatus

        public java.lang.String getStatus()
        Description copied from interface: PresenceView
        Returns the status message of the presence update, or null 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 interface PresenceView
        Returns:
        the status message.
      • setStatus

        @Deprecated
        public void setStatus​(java.lang.String status)
        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.
      • setPriority

        public void setPriority​(byte priority)
      • getElementName

        public java.lang.String getElementName()
        Description copied from interface: NamedElement
        Returns the root element name.
        Specified by:
        getElementName in interface NamedElement
        Returns:
        the element name.
      • toString

        public java.lang.String toString()
        Description copied from class: Stanza
        Returns a short String describing the Stanza. This method is suited for log purposes.
        Specified by:
        toString in class Stanza
      • clone

        @Deprecated
        public Presence clone()
        Deprecated.
        use asBuilder() 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:
        clone in class java.lang.Object
        Returns:
        a clone of this presence.
      • cloneWithNewId

        @Deprecated
        public Presence cloneWithNewId()
        Deprecated.
        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