<p>Although message threads are re-used in XMPP extension protocols such as &xep0085; and &xep0155;, the semantics of message threads have never been well specified (e.g., in <cite>RFC 3921</cite>). This document attempts to clearly specify the meaning and handling of message threads for implementation by XMPP clients and possible incorporation into the successor to <cite>RFC 3921</cite>.</p>
</section1>
<section1topic='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 or a &xep0045; room.</li>
<li>Restart a chat or groupchat conversation from message history.</li>
<li>Separate logical sessions from physical interface objects such as windows.</li>
<li>Route XMPP stanzas internally (e.g., dispatching different content types to different windows), thus facilitating the creation of more robust plugin architectures.</li>
</ul>
</section1>
<section1topic='Semantics'anchor='semantics'>
<p>Section 2.1.2.3 of <cite>RFC 3920</cite> currently states the following regarding the semantics of the ThreadID:</p>
<pclass='indent'>The <thread/> element contains non-human-readable XML character data specifying an identifier that is used for tracking a conversation thread (sometimes referred to as an "instant messaging session") between two entities.</p>
<p>The description in <cite>RFC 3921</cite> is deemed to be too limiting, since it ignores the potential use of the ThreadID when exchanging message stanzas of types other than 'chat'. Therefore we proposal the following description:</p>
<pclass='indent'>The primary use of the XMPP <thread/> element is to uniquely identify a conversation thread or "chat session" between two entities instantiated by <message/> stanzas of type 'chat'. However, the XMPP <thread/> element may also be used to uniquely identify an analogous thread between two entities instantiated by <message/> stanzas of type 'headline' or 'normal', or among multiple entities in the context of a multi-user chat room instantiated by <message/> stanzas of type 'groupchat'.</p>
</section1>
<section1topic='Uniqueness'anchor='unique'>
<p>Section 2.1.2.3 of <cite>RFC 3920</cite> currently states the following uniqueness requirement:</p>
<pclass='indent'>The value of the <thread/> element ... MUST be unique to that conversation thread within the stream and MUST be consistent throughout that conversation (a client that receives a message from the same full JID but with a different thread ID MUST assume that the message in question exists outside the context of the existing conversation thread).</p>
<p>The uniqueness requirement in <cite>RFC 3921</cite> is not deemed strong enough since it is desirable that a ThreadID could be used to (for instance) restart a conversation at a later date. Therefore we propose the following uniqueness requirement:</p>
<pclass='indent'>For messages of type 'chat', 'headline', or 'normal', the value of the <thread/> element MUST be unique for the combination of the sender's bare JID and recipient's bare JID (i.e., the thread MUST NOT ever be repeated in communications between the sender and recipient). For messages of type 'groupchat', the value of the <thread/> element MUST be unique in the context of the multi-user chat room, as long as the room remains in existence.</p>
</section1>
<section1topic='Handling'anchor='handling'>
<p>In the context of <message/> stanzas of type 'chat' exchanged between two entities, the value of the <thread/> 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 session with unnegotiated parameters (i.e., as equivalent to the first message in a chat session that has been negotiated via <cite>XEP-0155</cite> with no parameters specified). An entity SHOULD destroy the thread when it sends or receives a <cite>XEP-0155</cite> "terminate" action and MAY destroy the thread when it goes offline, but SHOULD NOT destroy the thread if a human user merely closes a window in a client interface.</p>
<p>To ensure the uniqueness of ThreadIDs in the context of a multi-user chat room, the multi-use chat service MAY provide a way for room occupants to request a unique ThreadID; definition of such methods is out of scope for this specification.</p>
<p>There are no special handling requirements related to threads in the context of <message/> stanzas of type 'headline' or 'normal'.</p>
</section1>
<section1topic='Inclusion'anchor='inclusion'>
<p>Depending on the type of the message (i.e., the value of the 'type' attribute), the <thread/> should be included as follows:</p>
<tablecaption='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>OPTIONAL</td>
</tr>
<tr>
<td>headline</td>
<td>OPTIONAL</td>
</tr>
<tr>
<td>normal</td>
<td>OPTIONAL</td>
</tr>
</table>
</section1>
<section1topic='SHIM Header'anchor='shim'>
<p>In some contexts it may be desirable to enforce thread-like semantics when exchanging XMPP <iq/> stanzas. Because <cite>RFC 3920</cite> disallows more than one direct child element of the <iq/> stanza, it is not possible to include the <thread/> element for tracking purposes. Therefore we define a "ThreadID" &xep0131; header with the same semantics as the <thread/> element, but with the syntax of a SHIM header:</p>
<p>This document introduces no new security concerns or considerations above and beyond those specified in <cite>RFC 3920</cite> and <cite>RFC 3921</cite>.</p>