%ents; ]>
Best Practices for Message Threads This specification defines recommended handling of XMPP message threads. &LEGALNOTICE; 0201 Experimental Informational Standards Council XMPP Core N/A &stpeter; &ianpaterson; &ksmith; 0.4 2007-08-30 psa

Specified handling of thread IDs on groupchat messages.

0.3 2007-01-29 ip

Described handling of unavailable presence and chat messages without thread IDs; minor changes.

0.2 2007-01-23 psa/ks

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.

0.1 2006-12-20 psa

Initial version.

0.0.2 2006-12-14 psa Corrected SHIM example; added XMPP Registrar considerations. 0.0.1 2006-12-13 psa/ip First draft.

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 &rfc3921;). This document attempts to clearly specify the meaning and handling of message threads for implementation by XMPP clients and for potential inclusion in &rfc3921bis;.

Threads matter because they enable XMPP clients to:

Section 2.1.2.3 of RFC 3921 currently states the following regarding the semantics of the ThreadID:

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.

The description in RFC 3921 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 propose the following description:

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". It may also be used for <message/> stanzas not related to a conversation, such as a game session or between plugins.

Section 2.1.2.3 of RFC 3921 currently states the following uniqueness requirement:

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).

The uniqueness requirement in RFC 3921 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:

The value of the <thread/> element MUST be a universally unique identifier (UUID). The format described in &rfc4122; is RECOMMENDED.

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 XEP-0155 with no parameters specified). An entity SHOULD destroy the thread when it sends or receives a XEP-0155 "terminate" stanza (such a stanza SHOULD be sent even for sessions that were not negotitated with XEP-0155) and 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).

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 simply became "invisible", was temporarily disconnected by a network error, or is persisting the state of the session until it reconnects and receives "offline" messages).

If an entity receives a message of type "chat" without a thread ID then:

  • If the receiver has no sessions open with the sender (full JID), or if all the open sessions have already received a message that included the session's thread ID, then the receiver should create a new session with a new thread ID (and include that thread ID in all the messages it sends within the session).
  • If the receiver has a session open with the sender within which it has never received any message that included the session's thread ID, then it should consider the message to be part of that session. If more than one of such sessions exist, then the message should be considered part of the session in which the receiver last sent a message.

In the context of <message/> stanzas of type "groupchat" exchanged between multiple entities in a &xep0045; room or similar environment, the value of the <thread/> element shall be considered equivalent to a unique identifier for a conversation thread in the multi-user environment.

When displaying 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.

There are no special handling requirements related to threads in the context of <message/> stanzas of type "headline".

When sending a <message/> stanza of type "normal", the value of the <thread/> element is used to uniquely identify a conversation thread that may not be progressing in real-time. A <message/> stanza of type "normal" SHOULD always use a new <thread/> element identifier unless it is written in direct reply to another <message/> stanza, in which case the <thread/> element of the original <message/> should be used. Determining what constitutes a <message/> 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; alternatively, the entity that replies can include an "In-Reply-To" header as described in the Implementation Notes section of this document.

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.

Depending on the type of the message (i.e., the value of the 'type' attribute), the <thread/> should be included as follows:

Message Type Inclusion
chat RECOMMENDED
groupchat RECOMMENDED
headline OPTIONAL
normal OPTIONAL

In some contexts it may be desirable to enforce thread-like semantics when exchanging XMPP <iq/> stanzas. Because RFC 3920 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:

e0ffe42b28561960c6b12b944a092794b9683a38
]]>

An entity that needs to track replies to particular messages may do so by including an 'id' attribute with the &MESSAGE; stanza.

Art thou not Romeo, and a Montague? e0ffe42b28561960c6b12b944a092794b9683a38 ]]>

The entity that replies then MAY include an "In-Reply-To" SHIM header:

Neither, fair saint, if either thee dislike. e0ffe42b28561960c6b12b944a092794b9683a38
asiwe8289ljfdalk
]]>

An entity that generates the UUID used as the ThreadID MUST ensure that the UUID does not reveal identifying information about the entity.

This document requires no interaction with &IANA;.

The XMPP Registrar shall add "ThreadID" to its registry of SHIM headers (see &SHIMHEADERS;). The submission is as follows:

ThreadID This header has the same semantics as the thread child element of the XMPP message stanza but is for use in IQ stanzas. XEP-0201 ]]>