XEP-0012: Last Activity

This specification defines an XMPP protocol extension for communicating information about the last activity associated with an XMPP entity. It is typically used by an IM client to retrieve the most recent presence information from an offline contact by sending a last activity request to the server that hosts the account controlled by the contact.

NOTICE: The protocol defined herein is a Draft Standard of the XMPP Standards Foundation. Implementations are encouraged and the protocol is appropriate for deployment in production systems, but some changes to the protocol are possible before it becomes a Final Standard.

Document Information

Series: XEP
Number: 0012
Publisher: XMPP Standards Foundation
Status: Draft
Type: Standards Track
Version: 1.2
Last Updated: 2007-02-15
Approving Body: XMPP Council
Dependencies: XMPP Core, XMPP IM
Supersedes: None
Superseded By: None
Short Name: iq-last
Schema: <http://www.xmpp.org/schemas/iq-last.xsd>
Wiki Page: <http://wiki.jabber.org/index.php/Last Activity (XEP-0012)>

Author Information

Jeremie Miller

Email: jer@jabber.org
JabberID: jer@jabber.org

Thomas Muldowney

Email: temas@jabber.org
JabberID: temas@jabber.org

Peter Saint-Andre

JabberID: stpeter@jabber.org
URI: https://stpeter.im/

Legal Notices


This XMPP Extension Protocol is copyright (c) 1999 - 2008 by the XMPP Standards Foundation (XSF).


Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.

Disclaimer of Warranty

## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. In no event shall the XMPP Standards Foundation or the authors of this Specification be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification. ##

Limitation of Liability

In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising out of the use or inability to use the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.

IPR Conformance

This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which may be found at <http://www.xmpp.org/extensions/ipr-policy.shtml> or obtained by writing to XSF, P.O. Box 1641, Denver, CO 80201 USA).

Discussion Venue

The preferred venue for discussion of this document is the Standards discussion list: <http://mail.jabber.org/mailman/listinfo/standards>.

Errata may be sent to <editor@xmpp.org>.

Relation to XMPP

The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 3920) and XMPP IM (RFC 3921) specifications contributed by the XMPP Standards Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.

Conformance Terms

The following keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".

Table of Contents

1. Introduction
2. Protocol
3. Offline User Query
4. Online User Query
5. Server and Component Query
6. Determining Support
7. Implementation Notes
8. Security Considerations
9. IANA Considerations
10. XMPP Registrar Considerations
11. XML Schema
Revision History

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 the server. The 'jabber:iq:last' namespace provides a method for retrieving that information. The 'jabber:iq:last' namespace can also be used to discover 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.

2. Protocol

In order to request last activity information regarding another entity, the requesting entity shall send an <iq/> stanza of type "get" to the target entity, containing a <query/> element qualified by the 'jabber:iq:last' namespace:

Example 1. Last Activity Query

<iq from='romeo@montague.net/orchard' to='juliet@capulet.com' type='get' id='last1'>
  <query xmlns='jabber:iq:last'/>

The target entity MUST return either an IQ-result or an IQ-error. When returning an IQ-result, the target entity sends an <iq/> stanza of type='result' containing a <query/> element with a REQUIRED 'seconds' attribute and OPTIONAL XML character data.

Example 2. Last Activity Response

<iq from='juliet@capulet.com' to='romeo@montague.net/orchard' type='result' id='last1'>
  <query xmlns='jabber:iq:last' seconds='903'/>

The requesting entity must interpret the IQ-result based on the responding entity's JID type in order to determine the meaning of the information. Specifically, the information means something different depending on whether the responding entity has a JID of the form 'host', 'user@host', or 'user@host/resource'. These differences are explained more fully below.

3. Offline User Query

The primary usage of the 'jabber:iq:last' namespace is to find out how long ago a user logged out (and, additionally, what their status message was at that time). This primary usage assumes that the IQ-get is sent to a bare JID (<node@domain.tld>). When used in this way, the <query/> element contained in the IQ-result has a 'seconds' attribute, which is the number of seconds that have passed since the user last logged out. In addition, the element MAY contain XML character data that specifies the status message of the last unavailable presence received from the user. An example is shown below:

Example 3. Last Activity Query

<iq from='romeo@montague.net/orchard' to='juliet@capulet.com' type='get' id='last1'>
  <query xmlns='jabber:iq:last'/>

<iq from='juliet@capulet.com' to='romeo@montague.net/orchard' type='result' id='last1'>
  <query xmlns='jabber:iq:last' seconds='903'>Heading Home</query>

In this example, the user logged out fifteen minutes and three seconds ago, and when they logged out they sent a presence packet of type='unavailable' whose <status/> element contained the text "Heading Home".

If the user has at least one available resource when the server receives the request, the response SHOULD contain an empty <query/> element whose 'seconds' attribute is set to a value of '0'.

Note well that, as specified in XMPP Core [1] and XMPP IM [2], an IQ query sent to a JID of the form user@host is handled by a server on the user's behalf, not forwarded to one or more active resources. In addition, a server MUST NOT return last activity information to an entity that is not authorized to view the user's presence information (normally via presence subscription), and MUST return a "Forbidden" error in response to such a request (for information about error conditions, refer to Error Condition Mappings [3]).

4. Online User Query

When the IQ-get is sent to a full JID (<node@domain.tld/resource>), the responding entity MAY respond with the idle time of the user.

Example 4. Online User Last Query

<iq from='romeo@montague.net/orchard' to='juliet@capulet.com/balcony' type='get' id='last2'>
  <query xmlns='jabber:iq:last'/>
<iq from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard' type='result' id='last2'>
  <query xmlns='jabber:iq:last' seconds='123'/>

In this example, the user has been idle for about two minutes.

Support for this functionality is OPTIONAL (a client that does not support the protocol, or that does not wish to divulge this information, SHOULD return a <service-unavailable/> error).

Example 5. Service Unavailable Error

<iq from='juliet@capulet.com/balcony' to='romeo@montague.net/orchard' type='error' id='last2'>
  <query xmlns='jabber:iq:last'/>
  <error code='503' type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>

If there is no available resource matching the user@host/resource in the 'to' attribute of the request, the server MUST follow the rules in XMPP IM in order to determine what error stanza to return.

5. Server and Component Query

When the IQ-get namespace is sent to a server or component (i.e., to a JID of the form 'host'), the information contained in the IQ reply reflects the uptime of the JID sending the reply. The seconds attribute is how long the host has been up. The <query/> element SHOULD NOT contain XML character data.

Example 6. Server/Component Last Query

<iq from='romeo@montague.net/orchard' to='capulet.com' type='get' id='last3'>
  <query xmlns='jabber:iq:last'/>

<iq from='capulet.com' to='romeo@montague.net/orchard' type='result' id='last3'>
  <query xmlns='jabber:iq:last' seconds='123456'/>

In this example, the server has been up for a little more than 34 hours.

6. Determining Support

In order for a requesting entity to determine if a responding entity supports result set management, it SHOULD send a Service Discovery [4] information request to the responding entity:

Example 7. Requesting entity queries responding entity regarding protocol support

<iq from='stpeter@jabber.org/roundabout'
  <query xmlns='http://jabber.org/protocol/disco#info'/>

Example 8. Responding entity communicates protocol support

<iq from='jabber.org'
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <feature var='jabber:iq:last'/>

7. Implementation Notes

The information contained in an IQ reply for this namespace is inherently ambiguous. Specifically, for a bare JID (<node@domain.tld>) the information is the time since the JID was last connected to its server; for a full JID (<node@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.

8. Security Considerations

A server MUST NOT allow an unauthorized entity to learn a user's network availability by sending a Last Activity request to a JID of the form user@host or user@host/resource; i.e., Last Activity information MAY be divulged only to those entities that have permission to view the user's presence via a presence subscription (potentially as restricted by Server-Based Privacy Rules [5] or Simple Communications Blocking [6]).

A client MUST provide a way for a human user to disable sending of Last Activity responses from the client's full JID (<node@domain.tld/resource>).

9. IANA Considerations

This document requires no interaction with the Internet Assigned Numbers Authority (IANA) [7].

10. XMPP Registrar Considerations

No action on the part of the XMPP Registrar [8] is necessary as a result of this document, since 'jabber:iq:last' is already a registered protocol namespace.

11. XML Schema

<?xml version='1.0' encoding='UTF-8'?>


      The protocol documented by this schema is defined in
      XEP-0012: http://www.xmpp.org/extensions/xep-0012.html

  <xs:element name='query'>
        <xs:extension base='xs:string'>



1. RFC 3920: Extensible Messaging and Presence Protocol (XMPP): Core <http://tools.ietf.org/html/rfc3920>.

2. RFC 3921: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence <http://tools.ietf.org/html/rfc3921>.

3. XEP-0086: Error Condition Mappings <http://www.xmpp.org/extensions/xep-0086.html>.

4. XEP-0030: Service Discovery <http://www.xmpp.org/extensions/xep-0030.html>.

5. XEP-0016: Server-Based Privacy Rules <http://www.xmpp.org/extensions/xep-0016.html>.

6. XEP-0191: Simple Communications Blocking <http://www.xmpp.org/extensions/xep-0191.html>.

7. The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see <http://www.iana.org/>.

8. The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see <http://www.xmpp.org/registrar/>.

Revision History

Version 1.2 (2007-02-15)

Per a vote of the XMPP Council, changed from Historical and Active to Standards Track and Draft; added Implementation Notes and clarified text throughout; added proviso to security considerations regarding client support; added section on Service Discovery.


Version 1.1 (2004-01-22)

Editorial revisions.


Version 1.0 (2002-01-22)

Changed status to Active.


Version 0.3 (2002-01-14)

Made appropriate changes to reflect status as informational.


Version 0.2 (2002-01-04)

Converted to XML format.


Version 0.1 (2001-01-25)

Initial version from website.