|
Download content/client-server-api/modules/image_packs.md from abr00kx/taper: direct link, hf CLI and curl.
- Browser
- Download file 8.44 kB
-
https://huggingface.co/abr00kx/taper/resolve/main/content/client-server-api/modules/image_packs.md
- Command line
-
hf download hf://abr00kx/taper/content/client-server-api/modules/image_packs.md
-
curl -L -o image_packs.md https://huggingface.co/abr00kx/taper/resolve/main/content/client-server-api/modules/image_packs.md
8.44 kB
| ### Image packs | |
| {{% added-in v="1.19" %}} | |
| Image packs allow users to organise custom emoticons and stickers into named | |
| collections and share them with others. | |
| An **emoticon** (also called an emote) is a custom image sent inline within a | |
| message, analogous to emoji but defined outside the Unicode standard. A | |
| **sticker** is a standalone image sent as an [`t.sticker`](#tsticker) event. | |
| Image packs provide a distribution and discovery mechanism for both. | |
| {{% boxes/note %}} | |
| Emoticons are distinct from the [`t.emote`](#troommessage-msgtypes) message | |
| type. `t.emote` is used to describe an action (for example, "/me waves | |
| hello"), whereas emoticons are images expressing emotions or other concepts. | |
| This spec prefers the term "emoticon" in the following to avoid confusion. | |
| {{% /boxes/note %}} | |
| #### Shortcode grammar | |
| Each image in a pack is identified by a **shortcode**: a short, human-readable | |
| string used to search for and reference images. Shortcodes are not intended to | |
| serve as accessible descriptions of an image; that purpose is served by the | |
| `body` property of the image object. | |
| A shortcode MUST match the following grammar: | |
| ``` | |
| shortcode = 1*100shortcode_char | |
| shortcode_char = ALPHA / DIGIT / "-" / "_" | |
| ``` | |
| Where `ALPHA` and `DIGIT` are as defined in | |
| [RFC 5234](https://datatracker.ietf.org/doc/html/rfc5234). Shortcodes are | |
| case-sensitive. The length of a shortcode MUST NOT exceed 100 bytes. | |
| {{% boxes/note %}} | |
| The `:` character is specifically excluded because it is widely used across messaging | |
| platforms as a delimiter for triggering emoticon search (for example, typing | |
| `:cat` to search for an emoticon named `cat`). The `/` character is excluded | |
| because clients MAY use it to separate a shortcode from a pack name in | |
| completion UI (for example, `:cat/my_pack:`). Spaces are excluded to avoid | |
| ambiguity and common usability issues. This character set matches that used | |
| by Discord and Slack, simplifying bridging. | |
| {{% /boxes/note %}} | |
| Homeservers MAY enforce this grammar when `t.room.image_pack` events are | |
| submitted by clients via | |
| [`PUT /_taper/client/v3/rooms/{roomId}/state/{eventType}/{stateKey}`](/client-server-api/#put_taperclientv3roomsroomidstateeventtypestatekey). | |
| However, homeservers MUST NOT reject or drop `t.room.image_pack` events | |
| received over federation for failing this grammar. Homeservers MAY locally | |
| soft-fail such events. | |
| Clients SHOULD render emoticons and stickers that have malformed shortcodes, so | |
| that users can identify and correct them. Clients SHOULD enforce this grammar | |
| when creating or editing image packs. | |
| #### Image properties | |
| Emoticons SHOULD be at least 128×128 pixels. Stickers SHOULD be at least | |
| 512×512 pixels. These minimums ensure that images look sharp on high-DPI | |
| displays. | |
| Accepted image formats are the same as those permitted for | |
| [`t.image`](#timage) events. Images MAY be animated; clients MAY pause | |
| animations based on user preferences. | |
| #### Room image packs | |
| A room MAY contain any number of image packs, each defined by an | |
| [`t.room.image_pack`](#troomimage_pack) state event with a distinct `state_key`. An image pack with an empty `state_key` has no special meaning, it is simply another unique identifier. Clients SHOULD | |
| present the images in a room's packs only when the user is interacting in | |
| that room, unless that image pack is enabled globally. | |
| {{% event event="t.room.image_pack" %}} | |
| #### User image packs | |
| To make a room's image pack available globally across all rooms, a user adds | |
| a reference to the pack in their `t.image_pack.rooms` account data event. The | |
| reference consists of the room ID and the `state_key` of the pack. | |
| {{% event event="t.image_pack.rooms" %}} | |
| #### Space image packs | |
| Clients SHOULD surface image packs defined in the canonical space of the | |
| current room, if the user is also a member of that space. This applies | |
| recursively: if the canonical space itself has a canonical space, the packs | |
| of that space SHOULD also be surfaced. Care SHOULD be taken to avoid cycles | |
| when traversing the space hierarchy, and implementations SHOULD impose a | |
| reasonable limit on the traversal depth. | |
| #### Image pack source priority | |
| When presenting image suggestions to the user, clients SHOULD display image | |
| packs in the following order: | |
| 1. Packs referenced in the user's `t.image_pack.rooms` account data. | |
| 2. Packs defined in the current room's state. | |
| 3. Packs from the canonical space hierarchy of the current room. | |
| The ordering of images *within* a pack is currently up to implementations. | |
| #### Client behaviour | |
| ##### Sending custom emoticons | |
| Custom emoticons are sent as `<img>` elements within the `formatted_body` of an | |
| [`t.room.message`](#troommessage) event (with `format` set to | |
| `org.matrix.custom.html`). The `data-mx-emoticon` attribute identifies the | |
| element as a custom emoticon: | |
| ```html | |
| <img data-mx-emoticon | |
| src="runit://example.org/abc123" | |
| alt="a waving cat" | |
| title="cat_wave" | |
| height="32" /> | |
| ``` | |
| A client MUST treat an `<img>` element as a custom emoticon if and only if the | |
| `data-mx-emoticon` attribute is present. If the attribute has a value, that | |
| value MUST be ignored (some HTML serialisers MAY produce | |
| `data-mx-emoticon=""`). | |
| The attributes of the `<img>` element are defined as follows. | |
| The `src` attribute MUST be a valid | |
| [`runit://` URI](/client-server-api/#taper-content-runit-uris). Clients MUST | |
| NOT attempt to render images from other URI schemes, as this could result in | |
| unintended network requests. | |
| The `alt` attribute SHOULD be present and set to the `body` of the image | |
| object, or if absent, the image's shortcode. This attribute provides an | |
| accessible text description of the emoticon as defined by the | |
| [HTML specification](https://html.spec.whatwg.org/multipage/images.html#alt). | |
| The `title` attribute SHOULD be present and set to the shortcode of the | |
| emoticon. Clients MAY display this as a tooltip. | |
| The `height` attribute MUST be present for backwards compatibility with | |
| clients that do not support custom emoticons. Clients SHOULD set this to "32". | |
| Clients implementing image pack support SHOULD override this value when | |
| rendering based on the user's font size or other environmental factors. The | |
| `width` attribute SHOULD be omitted to preserve the image's aspect ratio. | |
| Clients MAY render messages that consist entirely of custom emoticons and/or normal emoji | |
| at a larger size. | |
| ##### Sending stickers | |
| When sending an image from a pack as a sticker, the `body` property of the | |
| [`t.sticker`](#tsticker) event SHOULD be set to the image object's `body` | |
| property, or if absent, the image's shortcode. The `info` property of the | |
| `t.sticker` event SHOULD be set to the image object's `info` property, or if | |
| absent, an empty object. | |
| ##### Emoticon picker suggestions | |
| Clients MAY use the `:` character as a trigger to initiate emoticon search in the message composer. When | |
| multiple packs contain images with the same shortcode, clients SHOULD provide | |
| disambiguation UI rather than silently resolving to one image. Clients MAY | |
| disambiguate by appending a slugified pack display name separated by `/` | |
| (for example, `:cat_wave/my_pack:`). | |
| Because pack names are not globally | |
| unique, clients SHOULD NOT attempt to automatically resolve a shortcode to a | |
| specific image. Clients SHOULD instead present a search modal or similar UI | |
| to allow the user to select the intended image. | |
| #### Security considerations | |
| ##### Encrypted image packs | |
| Image packs and the images they contain are not encrypted. Media referenced | |
| from image packs is therefore visible to homeservers. Encryption of image | |
| packs depends on encrypted state events, which are not currently defined by | |
| the Taper specification. | |
| In addition, a homeserver could correlate the timing of encrypted message | |
| events with media access requests to infer which emoticon was used in an | |
| encrypted event. This attack is analogous to URL preview correlation and is | |
| not unique to image packs. Client-side caching of media can reduce the | |
| frequency of such requests. | |
| Clients SHOULD warn users that media referenced from image packs in | |
| end-to-end encrypted rooms is not encrypted and is therefore visible to the | |
| homeserver. | |
| ##### Abusive content | |
| A user who enables a room image pack globally via `t.image_pack.rooms` | |
| implicitly trusts the pack's administrator not to introduce abusive imagery. | |
| If abusive content is added to a pack, the affected user SHOULD remove the | |
| reference from their `t.image_pack.rooms` account data. | |