<remark>Accepted by vote of Council on 2019-09-11.</remark>
</revision>
<revision>
<version>0.0.1</version>
<date>2019-09-04</date>
<initials>ks</initials>
<remark><p>First draft.</p></remark>
</revision>
</header>
<section1topic='Introduction'anchor='intro'>
<p>
There are many situations in which a message contains a payload that contains content that adds additional information to the context of a previous message. Examples of this might be a user sending a rection (e.g. a thumbs-up emoji) to another user's message, or a server adding information on a link previously posted to a chat room, a user updating/editing the content of a message they've previously sent. This specification provides a generic wrapper to fasten such new payloads to the message to which they apply.
<p>In order to mark that a payload applies to a previous message, a message is sent containing an "apply-to" element in the namespace "urn:xmpp:fasten:0", with attribute "id" that contains the &xep0359; origin-id of the stanza to which it applies, the children of which element are those that apply to the previous message (these are "wrapped payloads" because they are wrapped inside the <apply-to> element). The id of this apply-to-containing message is unimportant, and the type SHOULD be "normal" (KS: I don't care about this, it just seemed easier to spell it out).</p>
<p>If "user2@chatservice.example" wanted to send their approval (using a fictional 'i-like-this' element) for a message previously sent to chat room "chatroom@chatservice.example" with origin-id "origin-id-1", they would do the following.</p>
<p>Where the payload being fastened needs top-level child elements of the stanza holding the fastening (e.g. if a message edit uses the top-level <body> child), these can be listed in <external> child elements of the <apply-to> element, in the same namespace. An <external> element has two attributes: the 'name' attribute MUST be included, and is the name of the top-level stanza child element; the 'element-namespace' attribute specifies the namespace of the element, or if absent indicates that the element is in the same namespace as the stanza (eliding the stream namespace in this way avoids issues when transporting fastenings across combinations of 'jabber:server' and 'jabber:client' streams.</p>
<p>If "user2@chatservice.example" wanted to send an edit (using a fictional protocol) of a message they previously sent with origin-id 'origin-id-2', and the edit protocol used top-level <body> and <custom> elements, it would look like this.</p>
<section2topic="Replacing a previous fastening"anchor="replace">
<p>When an entity wishes to replace a fastening they have previously applied it does this by including an attribute 'replace' with value 'true' on the <apply-to> element. The child payload of the <apply-to> element then logically replaces a fastening previously applied by the sending entity with the same name and namespace.</p>
<p>For example, if user2 wished to update the fastening from the first example they would send:</p>
<p>In order for a message to be able to have fastenings applied to it it must contain a &xep0359; stanza id.</p>
<p>A message must only contain a single "apply-to" element (i.e. a message cannot be fastened to multiple other messages).</p>
<p>Fastenings are not to be chained - an <apply-to> element MUST reply to the original message to which it applies, not to an earlier fastening-containing-message (the 'id' attribute of an <apply-to> element must not be that of a stanza that itself contains an <apply-to>). For example, if this spec is used in the future to wrap multiple subsquent message edits for the same source message, each <apply-to> would contain the original stanza's id, not the id of any subsequent fastening stanza.</p>
<p>Some payloads should not be allowed to be fastened to a particular message by all users - e.g. if used to wrap message edits, it would be expected that only the original author be allowed to edit their message. It's the responsibility of specifications for protocols to be fastened to destribe such "who is allowed to do this?" applicability rules.</p>
<p>TODO: (future XEP) special handling by the archive to allow grouping and querying of things fastened to a message (this is going to involve following the externals and potentially wrapping them inside the apply-to when fetching from the archive).</p>