<abstract>This document defines an XMPP protocol extension for communicating the status of a user in a chat session, thus indicating whether a chat partner is actively engaged in the chat, composing a message, temporarily paused, inactive, or gone. The protocol can be used in the context of a one-to-one chat session or a multi-user chat room.</abstract>
<remark><p>Clarified business rules regarding generation of notifications; added reference to XEP-0155; rewrote introduction; moved previous introductory text to section on superseding XEP-0022.</p></remark>
<remark><p>Added optional <initial/> state; added business rule on repetition of notifications; added implementation note.</p></remark>
</revision>
<revision>
<version>0.9</version>
<date>2004-10-28</date>
<initials>psa</initials>
<remark><p>Made <inactive/> state definition consistent with <paused/> per list discussion; made slight adjustments to wording throughout.</p></remark>
</revision>
<revision>
<version>0.8</version>
<date>2004-10-28</date>
<initials>psa</initials>
<remark><p>Further clarified state definitions and adjusted suggested event timing.</p></remark>
</revision>
<revision>
<version>0.7</version>
<date>2004-10-27</date>
<initials>psa</initials>
<remark><p>Clarified the meaning of the <gone/> state; adjusted suggested timing for events.</p></remark>
</revision>
<revision>
<version>0.6</version>
<date>2004-02-19</date>
<initials>psa</initials>
<remark><p>Added <paused/> state; defined the chat states; clarified the state chart; simplified the business rules.</p></remark>
</revision>
<revision>
<version>0.5</version>
<date>2003-09-18</date>
<initials>psa</initials>
<remark><p>Clarified that 'type' must be "chat" or "groupchat" for chat state notification messages.</p></remark>
</revision>
<revision>
<version>0.4</version>
<date>2003-05-22</date>
<initials>psa</initials>
<remark><p>Made Thread IDs optional; made <inactive/> and <gone/> states optional if Thread IDs are not used; removed requirement for explicit service discovery in favor of implicit discovery.</p></remark>
</revision>
<revision>
<version>0.3</version>
<date>2003-05-20</date>
<initials>psa</initials>
<remark><p>Clarified terminology; added support for groupchat; added several implementation notes.</p></remark>
<p>Many instant messaging systems include notifications about the state of one's conversation partner in a one-to-one chat (or, sometimes, in a many-to-many chat). Usually these are limited to notification that one's partner is currently typing -- e.g., the Composing event in the older (deprecated) &xep0022; protocol. However, a composing event is essentially information about a person's participation in or involvement with the chat "session" and therefore is really a session-level state rather than a per-message event (in contrast to the Delivered and Displayed events in <cite>XEP-0022</cite>). While the composing event is interesting, the concept of a session-level state can be extended to answer a variety of questions about the participation of a person in a real-time chat conversation, such as:</p>
<p>To answer such questions, this document supplements the traditional composing state by defining four additional chat states (paused, active, inactive, gone), for a total of five states that (it is hoped) together fully describe the possible states of a person's participation in or involvement with a chat conversation. <note>These states do not necessarily refer to the state of the client interface and certainly not to the disposition of a particular message. However, the user's involvement with the system, device, chat session interface, or input interface can provide important clues regarding the user's involvement with the chat session; these clues can be used by the client in determining when to generate chat state notifications.</note></p>
<p>In essence, chat state notifications can be thought of as a form of chat-specific presence. For example, consider what might happen if a user "loses" a chat window on his desktop; the user might still be interacting with his messaging client (thus never automatically changing his basic presence to "away"), but the user's state with regard to the chat session might change progressively from active to inactive to gone. This information would help the user's conversation partner understand why she has not received a response to her messages in the chat session.</p>
<p>Chat state notifications can appear in two kinds of &MESSAGE; stanzas:</p>
<li>A "content message" -- that is, a message stanza whose primary meaning is contained in standard messaging content such as the XMPP <body/> or any other properly-namespaced child element(s) other than those defined for chat state notifications in this specification.</li>
<li>A "standalone notification" -- that is, a message stanza that does not contain standard messaging content but instead is intended to specify only the chat state since it contains only a child element qualified by the "http://jabber.org/protocol/chatstates" namespace (or possibly also the XMPP <thread/> element; see the <linkurl='#bizrules-threads'>Threads</link> section below).</li>
<p>The five chat states specified in this document are described below. The suggested triggers are simply that: <em>suggestions</em>. It is up to the implementation to determine when to generate chat state notifications and which notifications to generate.</p>
<td>User accepts an initial content message, sends a content message, gives focus to the chat session interface (perhaps after being inactive), or is otherwise paying attention to the conversation.</td>
<td>User is actively interacting with a message input interface specific to this chat session (e.g., by typing in the input area of a chat window).</td>
</tr>
<tr>
<td><paused/></td>
<td>User had been composing but now has stopped.</td>
<td>User was composing but has not interacted with the message input interface for a short period of time (e.g., 30 seconds).</td>
<p>Note that the <active/>, <inactive/>, and <gone/> states refer to the overall chat session interface whereas the <composing/> and <paused/> states refer to the message input interface (and are in some sense a subset of <active/>). Some implementations might support only events related to the message input interface, some implementations might support only events related to the overall chat session interface, and some implementations might support both kinds of events.</p>
<p>The following figure attempts to capture the most common state transitions in visual form (all four of the states shown can also transition to the GONE state).</p>
<p>Note: Other transitions are not forbidden if the developers of an implementation feel that such transitions are desirable (e.g., INACTIVE to PAUSED if a user returns to a chat session interface containing an unfinished message).</p>
<p>If an entity supports the Chat State Notifications protocol, it MUST advertise that fact in its responses to &xep0030; information ("disco#info") requests by returning a feature of "http://jabber.org/protocol/chatstates":</p>
<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 &xep0115;. However, if an application has not received entity capabilities information from an entity, it SHOULD use explicit service discovery instead.</p>
<p>Before generating chat state notifications, a User SHOULD explicitly discover whether the Contact supports the protocol defined herein (as described in the <linkurl='#disco'>Discovering Support</link> section of this document) or explicitly negotiate the use of chat state notifications with the Contact (e.g., via &xep0155;).</p>
<p>In the absence of explicit discovery or negotiation, the User MAY implicitly request and discover the use of chat state notifications in a one-to-one chat session by adhering to the following business rules:</p>
<li>If the User desires chat state notifications, the message(s) that it sends to the Contact before receiving a reply MUST contain a chat state notification extension, which SHOULD be <active/>.</li>
<li>If the Contact replies but does not include a chat state notification extension, the User MUST NOT send subsequent chat state notifications to the Contact.</li>
<li>If the Contact replies and includes an <active/> notification (or sends a standalone notification to the User), the User and Contact SHOULD send subsequent notifications for supported chat states (as specified in the next subsection) by including an <active/> notification in each content message and sending standalone notifications for the chat states they support (at a minimum, the <composing/> state).</li>
<p>The foregoing rules imply that the sending of chat state notifications is bidirectional (i.e., both User and Contact will either send or not send chat state notifications) rather than unidirectional (i.e., one of the conversation partners will send chat state notifications but the other will not); this is by design.</p>
<p>Note: Support for only <active/> and <composing/> is functionally equivalent to supporting the Composing event from <cite>XEP-0022</cite>.</p>
<p>Even if the user types continuously for a long time (e.g., while composing a lengthy reply), the client MUST NOT send more than one standalone <composing/> notification in a row. More generally, a client MUST NOT send a second instance of any given standalone notification (i.e., a standalone notification MUST be followed by a different state, not repetition of the same state). However, every content message SHOULD contain an <active/> notification.</p>
</section2>
<section2topic='Context of Usage'anchor='bizrules-context'>
<ol>
<li>This protocol MUST NOT be used with stanzas other than &MESSAGE;.</li>
<li>This protocol SHOULD NOT be used with message types other than "chat" or "groupchat".</li>
<li>The 'type' attribute for content messages and standalone notifications SHOULD be set to a value of "chat" (for one-to-one sessions) or "groupchat" (for many-to-many sessions).</li>
<li>A chat session MAY span multiple user sessions (i.e., chat state is orthogonal to the presence of one's conversation partner), although this is unlikely given the suggested timing of event triggers.</li>
<li>A message stanza that contains standard instant messaging content SHOULD NOT contain a chat state notification extension other than <active/>, where "standard instant messaging content" is taken to mean the <body/>, <subject/>, and <thread/> child elements defined in &xmppim; or any other child element that would lead the recipient to treat the stanza as an instant message as explained in &xep0226;.</li>
<li>A message stanza that does not contain standard messaging content and is intended to specify only the chat state MUST NOT contain any child elements other than the chat state notification extension, which SHOULD be a state other than <active/>; however, if threads are used (see below) then the standalone notification MUST also contain the <thread/> element.</li>
<p>While chat state notifications provide a mechanism for managing chat threads as communicated by inclusion of the XMPP <thread/> element, support for threads is OPTIONAL (for further information about threads, refer to &xep0201;). However, if all of the clients participating in a chat both support and use threads, the following additional business rules apply:</p>
<li>Clients MUST copy back Thread IDs (i.e., the value of the <thread/> element) in any replies.</li>
<li>When a client terminates a one-to-one chat session (e.g., when a user closes the chat session interface), it MUST generate a <gone/> event.</li>
<li>Upon receiving a <gone/> event, a client MUST NOT re-use the same Thread ID and MUST generate a new Thread ID for any subsequent chat messages sent to the conversation partner.</li>
</ol>
</section2>
<section2topic='Server Handling of Notifications'anchor='bizrules-notify'>
<p>Servers in constrained network environments (e.g., serving small-footprint clients via &xep0025; or &xep0124;) and services that rebroadcast message stanzas (e.g., Multi-User Chat services) MAY process standalone notifications differently from other messages. In particular, a server or service MAY refuse to deliver standalone notifications to its users, and SHOULD NOT store them offline. In contrast to <cite>XEP-0022</cite>, chat state notifications are completely the responsibility of the client, and MUST NOT be generated by a server or service.</p>
<p>In the following conversation, both User <bernardo@shakespeare.lit> and Contact <francisco@shakespeare.lit> support chat state notifications.</p>
<p>The following conversation flow illustrates in more detail the workings of chat state notifications (in this case also using threads) between a User <romeo@shakespeare.lit> and a Contact <juliet@capulet.com>.</p>
<p>At this point Juliet's client knows that Romeo's client supports chat state notifications. Thus she replies to the content message and her client includes a notification that her state is <active/>:</p>
<p>Romeo realizes his reply is too rash and pauses to choose the right words; after some (configurable) time period, his client senses the delay and sends a state of <paused/>.</p>
<p>When Juliet returns to her computer on the balcony, she finds the new message from Romeo. When she finishes her reply, her client includes both an <active/> notification and the new Thread ID with the body of her reply:</p>
<p>A client that receives a chat state notification might never receive another message or chat state notification from the other entity (e.g., because the other entity crashes or goes offline) and needs to plan accordingly.</p>
<p>The states of a chat thread can reveal information about a user's interaction with his or her computer, including his or her physical presence; such information SHOULD NOT be revealed to conversation partners who are not trusted to know such information. Client implementations MUST provide a mechanism that enables the user to disable chat state notifications if desired.</p>