<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Best Practices for Message Threads</title>
  <abstract>This specification defines recommended handling of XMPP message threads.</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>0201</number>
  <status>Active</status>
  <type>Informational</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>N/A</shortname>
  
  <author>
    <firstname>Peter</firstname>
    <surname>Saint-Andre</surname>
    <email>stpeter@stpeter.im</email>
    <jid>stpeter@jabber.org</jid>
    <uri>https://stpeter.im/</uri>
  </author>

  
  <author>
    <firstname>Ian</firstname>
    <surname>Paterson</surname>
    <email>ian.paterson@clientside.co.uk</email>
    <jid>ian@zoofy.com</jid>
  </author>

  
  <author>
    <firstname>Kevin</firstname>
    <surname>Smith</surname>
    <email>kevin@kismith.co.uk</email>
    <jid>kevin@doomsong.co.uk</jid>
  </author>

  <revision>
    <version>1.0</version>
    <date>2010-11-29</date>
    <initials>psa</initials>
    <remark><p>Per a vote of the XMPP Council, advanced specification to Active.</p></remark>
  </revision>
  <revision>
    <version>0.8</version>
    <date>2010-09-28</date>
    <initials>psa</initials>
    <remark><p>Expanded upon use with normal messages; cleaned up several matters in the text; added informational pointers to RFC 5322 (email) and RFC 5536 (netnews).</p></remark>
  </revision>
  <revision>
    <version>0.7</version>
    <date>2010-07-12</date>
    <initials>psa</initials>
    <remark><p>Removed definition of ThreadID syntax, semantics, and uniqueness because the revisions to RFC 3921 covers those topics.</p></remark>
  </revision>
  <revision>
    <version>0.6</version>
    <date>2010-05-21</date>
    <initials>psa</initials>
    <remark><p>Simplified several handling rules; removed ThreadID SHIM header for IQ stanzas; removed implementation note about In-Reply-To SHIM header; removed references to XEP-0155; corrected some errors; harmonized text with the revisions to RFC 3921 in coordination with editor's review.</p></remark>
  </revision>
  <revision>
    <version>0.5</version>
    <date>2008-02-06</date>
    <initials>psa</initials>
    <remark><p>Defined parent attribute and provided recommendations regarding creation of new threads and child threads.</p></remark>
  </revision>
  <revision>
    <version>0.4</version>
    <date>2007-08-30</date>
    <initials>psa</initials>
    <remark><p>Specified handling of thread IDs on groupchat messages.</p></remark>
  </revision>
  <revision>
    <version>0.3</version>
    <date>2007-01-29</date>
    <initials>ip</initials>
    <remark><p>Described handling of unavailable presence and chat messages without thread IDs; minor changes.</p></remark>
  </revision>
  <revision>
    <version>0.2</version>
    <date>2007-01-23</date>
    <initials>psa/ks</initials>
    <remark><p>Equalized treatment of different message types (chat and groupchat not preferred over normal); required the use of UUIDs; specified use of In-Reply-To header; added Kevin Smith as co-author.</p></remark>
  </revision>
  <revision>
    <version>0.1</version>
    <date>2006-12-20</date>
    <initials>psa</initials>
    <remark><p>Initial version.</p></remark>
  </revision>
  <revision>
    <version>0.0.2</version>
    <date>2006-12-14</date>
    <initials>psa</initials>
    <remark>Corrected SHIM example; added XMPP Registrar considerations.</remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2006-12-13</date>
    <initials>psa/ip</initials>
    <remark>First draft.</remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p>Although message threads are re-used in XMPP extension protocols such as <span class="ref"><link url="https://xmpp.org/extensions/xep-0085.html">Chat State Notifications (XEP-0085)</link></span> <note>XEP-0085: Chat State Notifications &lt;<link url="https://xmpp.org/extensions/xep-0085.html">https://xmpp.org/extensions/xep-0085.html</link>&gt;.</note>, best practices for generating and handling message threads have never been well specified (e.g., in <span class="ref"><link url="http://tools.ietf.org/html/rfc3921">RFC 3921</link></span> <note>RFC 3921: Extensible Messaging and Presence Protocol (XMPP): Instant Messaging and Presence &lt;<link url="http://tools.ietf.org/html/rfc3921">http://tools.ietf.org/html/rfc3921</link>&gt;.</note> or <span class="ref"><link url="http://tools.ietf.org/html/rfc6121">RFC 6121</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>). This document attempts to clearly specify those matters for implementation by XMPP clients.</p>
</section1>
<section1 topic="Motivation" anchor="motivation">
  <p>Threads matter because they enable XMPP clients to:</p>
  <ul>
    <li>Track conversation topics within the context of a one-to-one chat session, a <span class="ref"><link url="https://xmpp.org/extensions/xep-0045.html">Multi-User Chat (XEP-0045)</link></span> <note>XEP-0045: Multi-User Chat &lt;<link url="https://xmpp.org/extensions/xep-0045.html">https://xmpp.org/extensions/xep-0045.html</link>&gt;.</note> room, or exchange of normal messages.</li>
    <li>Restart a conversation from message history.</li>
    <li>Enable clients to distinguish between different conversation threads when presenting a user's message, chat, and groupchat histories, thus providing a more coherent user interface (e.g. by collapsing threads to a single history entry).</li>
    <li>Separate logical sessions from physical interface objects such as windows.</li>
    <li>Route XMPP stanzas within a client (e.g., dispatching different content types to different windows), thus facilitating the creation of more robust plugin architectures.</li>
  </ul>
</section1>
<section1 topic="Generation" anchor="generation">
  <section2 topic="Inclusion" anchor="inclusion">
    <p>Depending on the type of the message (i.e., the value of the 'type' attribute), the &lt;thread/&gt; should be included as follows:</p>
    <table caption="When to Include Threads">
      <tr>
        <th>Message Type</th>
        <th>Inclusion</th>
      </tr>
      <tr>
        <td>chat</td>
        <td>RECOMMENDED</td>
      </tr>
      <tr>
        <td>groupchat</td>
        <td>RECOMMENDED</td>
      </tr>
      <tr>
        <td>headline</td>
        <td>OPTIONAL</td>
      </tr>
      <tr>
        <td>normal</td>
        <td>OPTIONAL</td>
      </tr>
    </table>
  </section2>
  <section2 topic="New Threads" anchor="new">
    <p>Unless a &lt;message/&gt; stanza is written in direct reply to another &lt;message/&gt; stanza, if a ThreadID is included then its value SHOULD be newly generated when a human user initiates a chat conversation with another user (i.e., a &lt;message/&gt; stanza of type 'chat'), starts a new conversation in the context of a multi-user chat environment (i.e., a &lt;message/&gt; stanza of type 'groupchat'), or sends a normal message.</p>
    <p>If the &lt;message/&gt; stanza is written in direct reply to another &lt;message/&gt; stanza, then the ThreadID SHOULD be the value from the the original &lt;message/&gt; stanza. (Determining what constitutes a &lt;message/&gt; stanza written in reply to another is a matter left to individual implementation, but it is envisaged that in most cases it would be the result of, e.g., the user clicking a 'reply' button when reading the contents of the previous stanza.)</p>
  </section2>
  <section2 topic="Child Threads" anchor="child">
    <p>In some situations, the conversation veers from the original topic. In this situation, it can be sensible to generate a new thread that is an offshoot or child of the original thread. The connection of the child thread to the parent thread is indicated by including the original ThreadID as the value of the 'parent' attribute.</p>
    <example caption="Thread with parent"><![CDATA[
<message
    to='romeo@example.net/orchard'
    from='juliet@example.com/balcony'
    id='asiwe8289ljfdalk'
    type='chat'
    xml:lang='en'>
  <body>Art thou not Romeo, and a Montague?</body>
  <thread parent='7edac73ab41e45c4aafa7b2d7b749080'>
    e0ffe42b28561960c6b12b944a092794b9683a38
  </thread>
</message>
]]></example>
  </section2>
</section1>
<section1 topic="Handling" anchor="handling">
  <p>In general, the XMPP &lt;thread/&gt; element is handled in a manner similar to the "References:" header field from email (see <span class="ref"><link url="http://tools.ietf.org/html/rfc5322">RFC 5322</link></span> <note>RFC 5322: Internet Message Format &lt;<link url="http://tools.ietf.org/html/rfc5322">http://tools.ietf.org/html/rfc5322</link>&gt;.</note>) and netnews (see <span class="ref"><link url="http://tools.ietf.org/html/rfc5536">RFC 5536</link></span> <note>RFC 5536: Netnews Article Format &lt;<link url="http://tools.ietf.org/html/rfc5536">http://tools.ietf.org/html/rfc5536</link>&gt;.</note>), as well as the THREAD extension to IMAP (see <span class="ref"><link url="http://tools.ietf.org/html/rfc5256">RFC 5256</link></span> <note>RFC 5256: Internet Message Access Protocol - SORT and THREAD Extensions &lt;<link url="http://tools.ietf.org/html/rfc5256">http://tools.ietf.org/html/rfc5256</link>&gt;.</note>). Detailed guidelines for particular XMPP message types are provided in the following sections.</p>
  <section2 topic="Chat Messages" anchor="chat">
    <p>For &lt;message/&gt; stanzas of type "chat" exchanged between two entities, the value of the &lt;thread/&gt; element shall be considered equivalent to a unique identifier for the chat session or conversation thread. If an entity receives such a message with a new or unknown ThreadID, it SHOULD treat the message as part of a new chat session. A client MAY destroy the thread when it goes offline, but SHOULD NOT destroy the thread if a human user merely disengages from the chat session (e.g., by closing a window in a client interface).</p>
    <p>If an entity receives an XMPP presence stanza of type "unavailable" from the other entity during a chat session, it SHOULD NOT destroy the thread; instead, it SHOULD assume that the other entity will still be able to continue the session (perhaps the other entity was temporarily disconnected by a network error or is persisting the state of the session until it reconnects and receives "offline" messages).</p>
    <p>If an entity receives a message of type "chat" without a thread ID, then it SHOULD create a new session with a new thread ID (and include that thread ID in all the messages it sends within the new session).</p>
  </section2>
  <section2 topic="Groupchat Messages" anchor="groupchat">
    <p>For &lt;message/&gt; stanzas of type "groupchat" exchanged between multiple entities in a <span class="ref"><link url="https://xmpp.org/extensions/xep-0045.html">Multi-User Chat (XEP-0045)</link></span> <note>XEP-0045: Multi-User Chat &lt;<link url="https://xmpp.org/extensions/xep-0045.html">https://xmpp.org/extensions/xep-0045.html</link>&gt;.</note> room or similar environment, the value of the &lt;thread/&gt; element shall be considered equivalent to a unique identifier for a conversation thread in the multi-user environment.</p>
    <p>When displaying a threaded groupchat conversation within a user interface, a client SHOULD provide a visual indication of the thread to which a message belongs. Methods for such indications include (non-exhaustively) the grouping together of all messages from the same thread, providing an index of threads, or formatting all messages within a thread in a cohesive manner, e.g. with uniform coloring.</p>
  </section2>
  <section2 topic="Normal Messages" anchor="normal">
    <p>For &lt;message/&gt; stanzas of type "normal", the value of the &lt;thread/&gt; element shall be considered equivalent to a unique identifier for a conversation thread that proceeds outside the context of a "real-time" chat session or groupchat session.</p>
    <p>When displaying threaded messages of type "normal" within a user interface, a client SHOULD provide a visual indication of the thread to which a message belongs. Methods for such indications include (non-exhaustively) the grouping together of all messages from the same thread, providing an index of threads, or formatting all messages within a thread in a cohesive manner, e.g. with uniform coloring.</p>
  </section2>
  <section2 topic="Headline Messages" anchor="headline">
    <p>There are no special handling requirements related to threads for &lt;message/&gt; stanzas of type "headline", because it is not expected that a client will allow the recipient to reply to such messages.</p>
  </section2>
  <section2 topic="Messages That Have Been Archived" anchor="archived">
    <p>When displaying historical conversations within a user interface, a client SHOULD provide a visual indication of the thread to which a message belongs. Methods for such indications include (non-exhaustively) the grouping together of all messages from the same thread, providing an index of threads, or formatting all messages within a thread in a cohesive manner, e.g. with uniform coloring.</p>
  </section2>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>Several security considerations related to XMPP threads are described in <span class="ref"><link url="http://tools.ietf.org/html/rfc6121">RFC 6121</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>.</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>This document requires no interaction with 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>.</p>
</section1>
</xep>
