public final class LastActivityManager extends Manager
The implementation of XEP-0012: Last Activity and XEP-0256: Last Activity in Presence.
This class also takes care about the following use case, by automatically appending last activity information to ‘away’ and ‘xa’ presences: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 manager also automatically adds anWhen 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.
<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}.
LastActivityManager lastActivityManager = xmppSession.getManager(LastActivityManager.class);
LastActivity lastActivity = lastActivityManager.getLastActivity(Jid.of("juliet@example.com/balcony")).getResult();
Modifier and Type | Method and Description |
---|---|
java.util.function.Supplier<java.time.Instant> |
getIdleStrategy()
Gets the current idle strategy, i.e. a supplier for last user interaction.
|
AsyncResult<LastActivity> |
getLastActivity(Jid jid)
Gets the last activity of the specified user.
|
java.time.Instant |
getLastSentStanzaTime()
Gets the time of the last sent message or non-away, non-xa presence.
|
void |
setIdleStrategy(java.util.function.Supplier<java.time.Instant> idleStrategy)
Sets an idle strategy, i.e. a supplier for last user interaction.
|
isEnabled, setEnabled
public java.time.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.
public void setIdleStrategy(java.util.function.Supplier<java.time.Instant> idleStrategy)
Sets an idle strategy, i.e. a supplier for last user interaction.
idleStrategy
- The strategy.getLastSentStanzaTime()
public java.util.function.Supplier<java.time.Instant> getIdleStrategy()
Gets the current idle strategy, i.e. a supplier for last user interaction.
public AsyncResult<LastActivity> getLastActivity(Jid jid)
Gets the last activity of the specified user.
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).
jid
- The JID for which the last activity is requested.Copyright © 2014–2019 XMPP.rocks. All rights reserved.