<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Last Activity</title>
  <abstract>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.</abstract>
  
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>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.</permissions>
<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. ##</warranty>
<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 from, out of, or in connection with the Specification or the implementation, deployment, or other use of 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.</liability>
<conformance>This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
  <number>0012</number>
  <status>Final</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XMPP IM</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>iq-last</shortname>
  <schemaloc>
    <url>http://www.xmpp.org/schemas/iq-last.xsd</url>
  </schemaloc>
  
  <author>
    <firstname>Jeremie</firstname>
    <surname>Miller</surname>
    <email>jer@jabber.org</email>
    <jid>jer@jabber.org</jid>
  </author>

  
  <author>
    <firstname>Thomas</firstname>
    <surname>Muldowney</surname>
    <email>temas@jabber.org</email>
    <jid>temas@jabber.org</jid>
  </author>

  
  <author>
    <firstname>Peter</firstname>
    <surname>Saint-Andre</surname>
    <email>stpeter@stpeter.im</email>
    <jid>stpeter@jabber.org</jid>
    <uri>https://stpeter.im/</uri>
  </author>

  <revision>
    <version>2.0</version>
    <date>2008-11-26</date>
    <initials>psa</initials>
    <remark><p>Per a vote of the XMPP Council, advanced specification to Final; clarified a few small points in the text; added a reference to XEP-0115.</p></remark>
  </revision>
  <revision>
    <version>1.3</version>
    <date>2008-07-16</date>
    <initials>psa</initials>
    <remark><p>Corrected server processing rules to block queries to a full JID when the requesting entity is not authorized to view the presence of the user.</p></remark>
  </revision>
  <revision>
    <version>1.2</version>
    <date>2007-02-15</date>
    <initials>psa</initials>
    <remark><p>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.</p></remark>
  </revision>
  <revision>
    <version>1.1</version>
    <date>2004-01-22</date>
    <initials>psa</initials>
    <remark><p>Editorial revisions.</p></remark>
  </revision>
  <revision>
    <version>1.0</version>
    <date>2002-01-22</date>
    <initials>psa</initials>
    <remark><p>Changed status to Active.</p></remark>
  </revision>
  <revision>
    <version>0.3</version>
    <date>2002-01-14</date>
    <initials>psa</initials>
    <remark><p>Made appropriate changes to reflect status as informational.</p></remark>
  </revision>
  <revision>
    <version>0.2</version>
    <date>2002-01-04</date>
    <initials>tjm</initials>
    <remark><p>Converted to XML format.</p></remark>
  </revision>
  <revision>
    <version>0.1</version>
    <date>2001-01-25</date>
    <initials>jm</initials>
    <remark><p>Initial version from website.</p></remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p>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.</p>
</section1>
<section1 topic="Protocol" anchor="protocol">
  <p>In order to request last activity information regarding another entity, the requesting entity sends an &lt;iq/&gt; stanza of type "get" to the target entity, containing a &lt;query/&gt; element qualified by the 'jabber:iq:last' namespace:</p>
  <example caption="Last Activity Query"><![CDATA[
<iq from='romeo@montague.net/orchard'
    id='last1'
    to='juliet@capulet.com'
    type='get'>
  <query xmlns='jabber:iq:last'/>
</iq>
]]></example>
  <p>The target entity MUST return either an IQ-result or an IQ-error. When returning an IQ-result, the target entity sends an &lt;iq/&gt; stanza of type='result' containing a &lt;query/&gt; element with a REQUIRED 'seconds' attribute and OPTIONAL XML character data.</p>
  <example caption="Last Activity Response"><![CDATA[
<iq from='juliet@capulet.com'
    id='last1'
    to='romeo@montague.net/orchard'
    type='result'>
  <query xmlns='jabber:iq:last' seconds='903'/>
</iq>
]]></example>
  <p>The requesting entity interprets 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 the identity of the responding entity:</p>
  <ol>
    <li>An account registered on an XMPP server, with a JID of the form &lt;localpart@domain.tld&gt;.</li>
    <li>A connected or available resource associated with such an account, with a JID of the form &lt;localpart@domain.tld/resource&gt;.</li>
    <li>An "always-on" XMPP server or service, with a JID of the form &lt;domain.tld&gt;.</li>
  </ol>
  <p>These differences are explained more fully below.</p>
</section1>
<section1 topic="Offline User Query" anchor="offline">
  <p>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 &lt;localpart@domain.tld&gt;. When used in this way, the &lt;query/&gt; 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:</p>
  <example caption="Last Activity Query"><![CDATA[
<iq from='romeo@montague.net/orchard'
    id='last1'
    to='juliet@capulet.com'
    type='get'>
  <query xmlns='jabber:iq:last'/>
</iq>
]]></example>
  <p>As specified in <span class="ref"><link url="http://tools.ietf.org/html/rfc6120">XMPP Core</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note> and <span class="ref"><link url="http://tools.ietf.org/html/rfc6121">XMPP IM</link></span> <note>RFC 6121: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence &lt;<link url="http://tools.ietf.org/html/rfc6121">http://tools.ietf.org/html/rfc6121</link>&gt;.</note>, an IQ stanza of type "get" sent to a bare JID &lt;localpart@domain.tld&gt; is handled by the user's server on the user's behalf, not delivered to one or more connected or available resources.</p>
  <p>If the requesting entity is not authorized to view the user's presence information (normally via a presence subscription as defined in <cite>XMPP-IM</cite>), the user's server MUST NOT return last activity information but instead MUST return a &lt;forbidden/&gt; error in response to the last activity request.</p>
  <example caption="Requesting Entity is Not Authorized to Retrieve Last Activity Information"><![CDATA[
<iq from='juliet@capulet.com'
    id='last1'
    to='romeo@montague.net/orchard'
    type='error'>
  <error type='auth'>
    <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
]]></example>
  <p>If the requesting entity is authorized to view the user's presence information, the server shall return information about the last presence activity recorded by the server for that user.</p>
  <example caption="Last Activity Response by Server"><![CDATA[
<iq from='juliet@capulet.com'
    id='last1'
    to='romeo@montague.net/orchard'
    type='result'>
  <query xmlns='jabber:iq:last' seconds='903'>Heading Home</query>
</iq>
]]></example>
  <p>In this example, the user logged out fifteen minutes and three seconds ago, and when they logged out they sent a presence stanza of type='unavailable' whose &lt;status/&gt; element contained the text "Heading Home".</p>
  <p>If the user has at least one connected or available resource when the server receives the request, the response MUST (subject to local security policies) contain an empty &lt;query/&gt; element whose 'seconds' attribute is set to a value of '0'.</p>
</section1>
<section1 topic="Online User Query" anchor="online">
  <p>A requesting entity can send a last activity query to the full JID &lt;localpart@domain.tld/resource&gt; of a connected or available resource associated with an account.</p>
  <example caption="Last Activity Query Sent to Full JID"><![CDATA[
<iq from='romeo@montague.net/orchard'
    id='last2'
    to='juliet@capulet.com/balcony'
    type='get'>
  <query xmlns='jabber:iq:last'/>
</iq>
]]></example>
  <p>In this case, the user's server shall either deliver the IQ to an available resource or respond on behalf of the user.</p>
  <p>In particular, as with the offline query use case above, if the requesting entity is not authorized to view the user's presence information (normally via a presence subscription as defined in <cite>XMPP IM</cite>), the user's server MUST NOT deliver the IQ-get to an available resource but instead MUST return a &lt;forbidden/&gt; error in response to the last activity request.</p>
  <example caption="Requesting Entity is Not Authorized to Retrieve Last Activity Information"><![CDATA[
<iq from='juliet@capulet.com'
    id='last1'
    to='romeo@montague.net/orchard'
    type='error'>
  <error type='auth'>
    <forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
]]></example>
  <p>If the user's server delivers the IQ-get to one of the user's available resources, the user's client MAY respond with the idle time of the user (i.e., the last time that a human user interacted with the client application).</p>
  <example caption="Last Activity Response by Client"><![CDATA[
<iq from='juliet@capulet.com/balcony'
    id='last2'
    to='romeo@montague.net/orchard'
    type='result'>
  <query xmlns='jabber:iq:last' seconds='123'/>
</iq>
]]></example>
  <p>In the foregoing example, the user has been idle for about two minutes.</p>
  <p>Support for this functionality is OPTIONAL. A client that does not support the protocol, or that does not wish to divulge this information, MUST return a &lt;service-unavailable/&gt; error.</p>
  <example caption="Service Unavailable Error"><![CDATA[
<iq from='juliet@capulet.com/balcony'
    id='last2'
    to='romeo@montague.net/orchard'
    type='error'>
  <error type='cancel'>
    <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  </error>
</iq>
]]></example>
  <p>If there is no available resource matching the &lt;localpart@domain.tld&gt; in the 'to' attribute of the request, the server MUST follow the rules in <cite>XMPP IM</cite> in order to determine what error stanza to return.</p>
</section1>
<section1 topic="Server and Component Query" anchor="server">
  <p>When the last activity query is sent to a server or component (i.e., to a JID of the form &lt;domain.tld&gt;), the information contained in the IQ reply reflects the uptime of the JID sending the reply. The seconds attribute specifies how long the host has been running since it was last (re-)started. The &lt;query/&gt; element SHOULD NOT contain XML character data.</p>
  <example caption="Last Activity Query Sent to Server or Service"><![CDATA[
<iq from='romeo@montague.net/orchard'
    id='last3'
    to='capulet.com'
    type='get'>
  <query xmlns='jabber:iq:last'/>
</iq>
]]></example>
  <example caption="Last Activity Response from Server or Service"><![CDATA[
<iq from='capulet.com'
    id='last3'
    to='romeo@montague.net/orchard'
    type='result'>
  <query xmlns='jabber:iq:last' seconds='123456'/>
</iq>
]]></example>
  <p>In this example, the server has been running for a little more than 34 hours.</p>
</section1>
<section1 topic="Determining Support" anchor="support">
  <p>If an entity supports the Last Activity protocol, it MUST advertise that fact in its responses to <span class="ref"><link url="https://xmpp.org/extensions/xep-0030.html">Service Discovery (XEP-0030)</link></span> <note>XEP-0030: Service Discovery &lt;<link url="https://xmpp.org/extensions/xep-0030.html">https://xmpp.org/extensions/xep-0030.html</link>&gt;.</note> information ("disco#info") requests by returning a feature of "jabber:iq:last".</p>
  <example caption="Requesting entity queries responding entity regarding protocol support"><![CDATA[
<iq from='stpeter@jabber.org/roundabout'
    id='disco1'
    to='jabber.org'
    type='get'>
  <query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
]]></example>
  <example caption="Responding entity communicates protocol support"><![CDATA[
<iq from='jabber.org'
    id='disco1'
    to='stpeter@jabber.org/roundabout'
    type='result'>
  <query xmlns='http://jabber.org/protocol/disco#info'>
    <feature var='jabber:iq:last'/>
  </query>
</iq>
]]></example>
  <p>In order for an application to determine whether an entity supports this protocol, where possible it SHOULD use the dynamic, presence-based profile of service discovery defined in <span class="ref"><link url="https://xmpp.org/extensions/xep-0115.html">Entity Capabilities (XEP-0115)</link></span> <note>XEP-0115: Entity Capabilities &lt;<link url="https://xmpp.org/extensions/xep-0115.html">https://xmpp.org/extensions/xep-0115.html</link>&gt;.</note>. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.</p>
</section1>
<section1 topic="Implementation Notes" anchor="impl">
  <p>The information contained in an IQ reply for this namespace is inherently ambiguous. Specifically, for a bare JID &lt;localpart@domain.tld&gt; the information is the time since the JID was last connected to its server; for a full JID &lt;localpart@domain.tld/resource&gt; 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).</p>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>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 &lt;localpart@domain.tld&gt; or &lt;localpart@domain.tld/resource&gt;, since doing so would constitute a "presence leak" as described in <span class="ref"><link url="http://tools.ietf.org/html/rfc6120">RFC 6120</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note>. That is, 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 <span class="ref"><link url="https://xmpp.org/extensions/xep-0016.html">Privacy Lists (XEP-0016)</link></span> <note>XEP-0016: Privacy Lists &lt;<link url="https://xmpp.org/extensions/xep-0016.html">https://xmpp.org/extensions/xep-0016.html</link>&gt;.</note> or <span class="ref"><link url="https://xmpp.org/extensions/xep-0191.html">Blocking Command (XEP-0191)</link></span> <note>XEP-0191: Blocking Command &lt;<link url="https://xmpp.org/extensions/xep-0191.html">https://xmpp.org/extensions/xep-0191.html</link>&gt;.</note>).</p>
  <p>A client MUST provide a way for a human user to disable sending of Last Activity responses from the client's full JID &lt;localpart@domain.tld/resource&gt;.</p>
</section1>
<section1 topic="IANA Considerations" anchor="iana">
  <p>This document requires no interaction with the <span class="ref"><link url="http://www.iana.org/">Internet Assigned Numbers Authority (IANA)</link></span> <note>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 &lt;<link url="http://www.iana.org/">http://www.iana.org/</link>&gt;.</note>.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <p>No action on the part of the <span class="ref"><link url="https://xmpp.org/registrar/">XMPP Registrar</link></span> <note>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 &lt;<link url="https://xmpp.org/registrar/">https://xmpp.org/registrar/</link>&gt;.</note> is necessary as a result of this document, since 'jabber:iq:last' is already registered in the protocol namespaces registry located at &lt;<link url="https://xmpp.org/registrar/namespaces.html">https://xmpp.org/registrar/namespaces.html</link>&gt;.</p>
</section1>
<section1 topic="XML Schema" anchor="schema">
  <code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='jabber:iq:last'
    xmlns='jabber:iq:last'
    elementFormDefault='qualified'>

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

  <xs:element name='query'>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base='xs:string'>
          <xs:attribute
              name='seconds'
              type='xs:unsignedLong'
              use='optional'/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>

</xs:schema>
]]></code>
</section1>
</xep>
