<remark>Accepted by vote of Council on 2020-11-18.</remark>
</revision>
<revision>
<version>0.0.1</version>
<date>2020-11-03</date>
<initials>lmw</initials>
<remark><p>First draft.</p></remark>
</revision>
</header>
<section1topic='Introduction'anchor='intro'>
<p>Stickers<note><em>Sticker (messaging)</em> on Wikipedia <<linkurl='https://en.wikipedia.org/wiki/Sticker_(messaging)'>https://en.wikipedia.org/wiki/Sticker_(messaging)</link>>.</note> are images or short animations that often represent an emoticon or an action. They are increasingly used in private messaging in the last years, especially on mobile phone apps. Stickers can be more nuanced and expressive than emoticons. They can be used to convey emotions or tell stories in a fun and easy way.</p>
<p>Recently, demand to implement stickers, including their social feature of sharing sticker packs arised within the XMPP community. This specification is to fulfill this demand.</p>
</section1>
<section1topic='Requirements'anchor='reqs'>
<ul>
<li>Do not require additional server components for easier deployment</li>
<li>Compatibility with non-graphical user interfaces (terminals, etc)</li>
<di><dt>Sticker pack</dt><dd>Collection of stickers, typically devoted to a specific theme or with all stickers created by the same author</dd></di>
</dl>
</section1>
<section1topic='Use Cases'anchor='usecases'>
<section2topic='Creating a sticker pack'anchor='create'>
<p>
Sticker packs are stored on pubsub nodes.
They SHOULD be located at a personal eventing (PEP) node named "urn:xmpp:stickers:0" but MAY be located at a generic publish-subscribe node that is not attached to a user's IM account.
The pubsub node's access model SHOULD be set to 'open', so that other users can fetch sticker packs.
Each sticker pack is one item on the pubsub node consisting of a <tt><pack/></tt> element.
</p>
<p>
The <tt><pack/></tt> element includes elements <tt><name/></tt> and <tt><summary/></tt> to announce a name and summary of the sticker pack that can be displayed to users, respectively.
The summary MAY contain copyright and license information in user-readable format.
Multiple <tt><name/></tt> and <tt><summary/></tt> elements MAY be included given that no two elements of same name specify the same <tt>xml:lang</tt>.
</p>
<p>
The <tt><pack/></tt> element MAY include a <tt><restricted/></tt> element to indicate that this sticker pack may not be used or imported by other users.
The <tt><pack/></tt> element contains one or more <tt><item/></tt> elements that include details on the stickers in the pack. Each <tt><item/></tt> element has <tt><file/></tt> element as described in &xep0446;. The metadata MUST include one or multiple <tt><hash/></tt> elements as described in &xep0300;. All stickers in a pack MUST use the same algorithm for their <tt><hash/></tt> elements. The metadata MUST include one <tt><desc/></tt> element that is not qualified by a <tt>xml:lang</tt> attribute and describes the textual fallback (often an emoji or a sequence of emojis) of the sticker. Each <tt><item/></tt> element further has a <tt><sources/></tt> element as described in &xep0447; describing how to retrieve the image file of the sticker. Each <tt><item/></tt> element MAY include one or more <tt><suggest/></tt> elements that include a text that clients may replace with the sticker. <tt><suggest/></tt> elements MAY have an <tt>xml:lang</tt> attribute.
Finally, the <tt><pack/></tt> element includes a single <tt><hash/></tt> element as described in &xep0300;, specifying the hash of the sticker pack. See <linkurl='#pack-hash'>next section</link> on how such hash is generated.
<p>Each sticker pack has a unique ID, which is used as the pubsub item's id. This ID is derived from a hash of significant information from a <tt><pack/></tt> element as outlined in this section.</p>
<ol>
<li><p>Processing <tt><name/></tt> and <tt><summary/></tt> elements:</p>
<ol>
<li><p>For each <tt><name/></tt> or <tt><summary/></tt> element:</p>
<ol>
<li>Encode the character data of element name (<tt>name</tt> or <tt>summary</tt>), <tt>xml:lang</tt> attribute value and content.</li>
<li>Append an octet of value &sepl4; to each resulting octet string.</li>
<li>Join the resulting octet strings together, in the order of element name, <tt>xml:lang</tt> attribute and content, resulting in a single octet string for the <tt><name/></tt> or <tt><summary/></tt> element.</li>
<li>Append an octet of value &sepl3;.</li>
</ol>
</li>
<li>Join the resulting octet strings together, ordered from lesser to greater.</li>
<li>Append an octet of value &sepl1;.</li>
</ol>
<p>The result of this step is referenced as <em>Meta string</em> later.</p>
<li><p>For each <tt><item/></tt> element:</p>
<ol>
<li>Encode the character data of <tt><file/></tt>'s <tt><desc/></tt> content.</li>
<li>Append an octet of value &sepl3; to the resulting octet string.</li>
<li><p>For each of <tt><hash/></tt> element in <tt><file/></tt>:</p>
<ol>
<li>Encode the character data of <tt>algo</tt> attribute and content.</li>
<li>Append an octet of value &sepl4; to the resulting octet strings.</li>
<li>Join the resulting octet strings together, in the order of <tt>algo</tt> attribute and content, resulting in a single octet string for the <tt><hash/></tt> element.</li>
<li>Append an octet of value &sepl3;.</li>
</ol>
</li>
<li>Join the resulting octet strings together, in the order of <tt><file/></tt>'s <tt><desc/></tt> content first and then all <tt><hash/></tt> elements ordered from lesser to greater.</li>
<li>Append an octet of value &sepl2;.</li>
</ol>
</li>
<li>Join the resulting octet strings together, ordered from lesser to greater.</li>
<li>Append an octet of value &sepl1;.</li>
</ol>
<p>The result of this step is referenced as <em>Stickers string</em> later.</p>
</li>
<li>Join the <em>Meta String</em> and <em>Stickers String</em> together, in this order.</li>
<li>Hash the resulting string using the algorithm choosen for the sticker pack.</li>
</ol>
<p>The ID of the sticker pack is dervied by taking the first 144 bit of the hash and encode it using Base64. This is equivalent to the first 24 characters of the Base64 encoded content of the <tt><hash/></tt> element.</p>
</section3>
<examplecaption='Publish a new sticker pack'><![CDATA[
<iqfrom='romeo@montague.lit/pda'
id='pub1'
to='romeo@montague.lit'
type='set'>
<pubsubxmlns='http://jabber.org/protocol/pubsub'>
<publishnode='urn:xmpp:stickers:0'>
<itemid='EpRv28DHHzFrE4zd+xaNpVb4'>
<packxmlns='urn:xmpp:stickers:0'>
<name>Marsey the Cat</name>
<summary>Be cute or be cynical, this little kitten works both ways.</summary>
<p>The sending entity uses &xep0447; to send the image file from the sticker pack. The <tt><item/></tt>'s <tt><file/></tt> and <tt><sources/></tt> elements from the sticker pack are used as a template. The sending entity MAY add additional <tt><hash/></tt> elements or sources.</p>
<p>Additionally, the sending entity adds an element <tt><sticker/></tt> to the message. This element carries an attribute <tt>pack</tt> referring to the id of the pubsub item carrying the sticker pack. If the sticker pack resides on a pubsub item other than the senders personal eventing (PEP) node named "urn:xmpp:stickers:0", the sending entity must add additional attributes <tt>jid</tt> and <tt>node</tt>, referring to the jid of the pubsub node and the name of the node, respectively.</p>
<p>The sending entity SHOULD use the <tt><file/></tt>'s <tt><desc/></tt> content as the message body, except if the sticker was selected based on a suggestion, in which case the content of the corresponding <tt><suggest/></tt> SHOULD be used.</p>
<section2topic='Receiving a sticker'anchor='receive'>
<p>When receiving a message with a <tt><sticker/></tt> element, the receiving entity SHOULD consider the message and the <tt><file-sharing/></tt> element as a sticker.</p>
<p>When receiving a sticker, the receiving entity may display the stickers image file inline or display the textual representation in the <tt><desc/></tt> element. The receiving entity SHOULD NOT display the received sticker only as a downloadable file.</p>
</section2>
<section2topic='Importing a sticker pack'anchor='import'>
<p>When receiving a sticker or any other reference to a sticker pack, the receiving entity may allow the user to import such sticker pack. The receiving entity SHOULD NOT offer to import a sticker pack that has a <tt><restricted/></tt> element.</p>
<p>When importing a sticker pack, the entity SHOULD make all files that are part of the sticker pack locally available. The entity SHOULD duplicate the pubsub item from its original source to the users personal eventing (PEP) node named "urn:xmpp:stickers:0", preserving the pack id. The entity MAY remove any of the sources provided, and MAY make an effort to make the files available at additional sources, e.g. by using &xep0363;.</p>
</section2>
<section2topic='Sharing a sticker pack'anchor='share'>
<p>After creating or importing a sticker pack, it can be shared using an <tt>xmpp:</tt>-uri as described in &xep0060;.</p>
<p>When handling this URI, the entity SHOULD display a preview of the sticker pack and allow importing it as described above.</p>
<p>Flickering, flashing or blinking stickers can induce seizures or other incapacitating physical reactions. It is RECOMMENDED that clients that support stickers have an option to disable animations and/or stickers entirely.</p>