Class LastActivityManager

  • All Implemented Interfaces:
    ExtensionProtocol, DiscoverableInfo

    public final class LastActivityManager
    extends Manager
    implements ExtensionProtocol, DiscoverableInfo
    The implementation of XEP-0012: Last Activity and XEP-0256: Last Activity in Presence.

    1. Introduction

    It is often helpful to know the time of the last activity associated with a entity. The canonical usage is to discover when a disconnected user last accessed its server. The 'jabber:iq:last' namespace provides a method for retrieving that information. The 'jabber:iq:last' namespace can also be used to discover or publicize when a connected user was last active on the server (i.e., the user's idle time) or to query servers and components about their current uptime.

    This class also takes care about the following use case, by automatically appending last activity information to 'away' and 'xa' presences:

    1.2 Away and Extended Away

    When a client automatically sets the user's <show/> value to "away" or "xa" (extended away), it can indicate when that particular was last active during the current presence session.

    This manager also automatically adds an <idle/> extension to outbound presences, if the presence is of type away or xa. However, sending such presences is still the responsibility of the application developer, i.e. no presences are sent automatically.

    By default, idle time is determined by outbound messages and non-away, non-xa presences. E.g. whenever a message is sent, the idle time is reset to the current time. Then, when a 'away' or 'xa' presence is sent, the <idle/> extension is added with the date of the last sent message.

    The strategy for determining last user interaction can be changed by setting a supplier which returns the timestamp of last user interaction. Possible alternative strategies is to track mouse movement or keyboard interaction for which cases you would set a supplier which gets the date of the last mouse movement.

    Automatic inclusion of last activity information in presence stanzas and support for this protocol can be Manager.setEnabled(boolean) enabled or disabled}.

    Code sample

    
     LastActivityManager lastActivityManager = xmppSession.getManager(LastActivityManager.class);
     LastActivity lastActivity = lastActivityManager.getLastActivity(Jid.of("juliet@example.com/balcony")).getResult();
     
    • Method Detail

      • getLastSentStanzaTime

        public Instant getLastSentStanzaTime()
        Gets the time of the last sent message or non-away, non-xa presence.

        This is the default strategy for determining last user interaction.

        Returns:
        The time of the last sent stanza.
      • setIdleStrategy

        public void setIdleStrategy​(Supplier<Instant> idleStrategy)
        Sets an idle strategy, i.e. a supplier for last user interaction.
        Parameters:
        idleStrategy - The strategy.
        See Also:
        getLastSentStanzaTime()
      • getIdleStrategy

        public Supplier<Instant> getIdleStrategy()
        Gets the current idle strategy, i.e. a supplier for last user interaction.
        Returns:
        The strategy or null if no strategy is set.
      • getLastActivity

        public AsyncResult<LastActivity> getLastActivity​(Jid jid)
        Gets the last activity of the specified user.

        7. Implementation Notes

        The information contained in an IQ reply for this namespace is inherently ambiguous. Specifically, for a bare JID <localpart@domain.tld> the information is the time since the JID was last connected to its server; for a full JID <localpart@domain.tld/resource> the information is the time since the resource was last active in the context of an existing session; and for a bare domain the information is the uptime for the server or component. An application MUST take these differences into account when presenting the information to a human user (if any).

        Parameters:
        jid - The JID for which the last activity is requested.
        Returns:
        The async result with the last activity of the requested JID or null if the feature is not implemented or a time out has occurred.
      • getNamespace

        public final String getNamespace()
        Description copied from interface: ExtensionProtocol
        The protocol's main namespace. This is used to uniquely identify the extension protocol.
        Specified by:
        getNamespace in interface ExtensionProtocol
        Returns:
        The main namespace.