|
| 1 | +# MSC4274: Inline media galleries via msgtypes |
| 2 | + |
| 3 | +Matrix allows sharing individual media files such as images or videos via |
| 4 | +dedicated [`m.room.message` msgtypes]. This is, however, not practical for |
| 5 | +sharing larger collections of files. For one thing, there is no mechanism to set |
| 6 | +a joint caption for several media files. For another, there is no way to inform |
| 7 | +other clients that a set of pictures belongs together and should be grouped |
| 8 | +accordingly in the timeline. These shortcomings call for a built-in media |
| 9 | +gallery feature as it is widely known from other messaging apps. |
| 10 | + |
| 11 | +This proposal defines a compact and pragmatic variant of sharing media galleries |
| 12 | +in a single event. |
| 13 | + |
| 14 | +## Proposal |
| 15 | + |
| 16 | +A new `msgtype` of `m.gallery` is introduced with the following properties in |
| 17 | +`content`: |
| 18 | + |
| 19 | +- `body` (string): The caption of the gallery. |
| 20 | +- `format` (string): The format used in `formatted_body`. Currently only |
| 21 | + `org.matrix.custom.html` is supported. |
| 22 | +- `formatted_body` (string): The formatted version of the body. Required if |
| 23 | + `format` is specified. |
| 24 | +- `itemtypes` (array): Ordered array of metadata for each item in the gallery. |
| 25 | + |
| 26 | +The objects in the `itemtypes` array have the same schema as the `content` of |
| 27 | +the msgtypes `m.image`, `m.video`, `m.audio` and `m.file`. Rather than |
| 28 | +`msgtype`, they use `itemtype` though. |
| 29 | + |
| 30 | +``` json5 |
| 31 | +{ |
| 32 | + "type": "m.room.message", |
| 33 | + "content": { |
| 34 | + "msgtype": "m.gallery", |
| 35 | + "body": "Checkout my photos from [FOSDEM 2025](https://fosdem.org/2025/)", |
| 36 | + "format": "org.matrix.custom.html", |
| 37 | + "formatted_body": "Checkout my photos from <a href=\"https://fosdem.org/2025/\">FOSDEM 2025</a>", |
| 38 | + "itemtypes": [{ |
| 39 | + "itemtype": "m.image", |
| 40 | + "body": "filename.jpg", |
| 41 | + "info": { |
| 42 | + "h": 398, |
| 43 | + "mimetype": "image/jpeg", |
| 44 | + "size": 31037, |
| 45 | + "w": 394 |
| 46 | + }, |
| 47 | + "url": "mxc://example.org/JWEIFJgwEIhweiWJE", |
| 48 | + ... |
| 49 | + }, ...] |
| 50 | + }, |
| 51 | + ... |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +## Potential issues |
| 56 | + |
| 57 | +The size of galleries under this proposal is limitted by the event size limit |
| 58 | +(65,536 bytes). An encrypted gallery event with a single image, including |
| 59 | +thumbnail, and no caption measures about 2,000 bytes. Each additional image adds |
| 60 | +roughly another 1,000 bytes. Therefore galleries would be capped to about 60 |
| 61 | +images. While this is a limitation, the amount seems practical for most use |
| 62 | +cases. |
| 63 | + |
| 64 | +Additionally, this proposal doesn't prescribe a fallback mechanism for clients |
| 65 | +that don't support `m.gallery` msgtypes. Clients that care about backwards |
| 66 | +compatibility could encode media links or a generic fallback text into `body` or |
| 67 | +`formatted_body`, respectively. It is unclear, however, if a fallback is |
| 68 | +actually desirable or not because unwrapping 60 images into somebody else's |
| 69 | +timeline might be considered inappropriate if not spammy. |
| 70 | + |
| 71 | +## Alternatives |
| 72 | + |
| 73 | +This proposal is similar to the seemingly abandoned [MSC3382]. The latter |
| 74 | +conflates galleries into `m.text` (or even arbitrary) msgtypes and reuses |
| 75 | +`msgtype` inside the items which creates a circular dependency. These issues are |
| 76 | +solved in the present proposal. |
| 77 | + |
| 78 | +Rather than adding a new `msgtype`, galleries could be expressed via extensible |
| 79 | +events by reusing parts of [MSC1767] and related proposals. This would only take |
| 80 | +effect in a future room version, however, and can be covered in a separate MSC. |
| 81 | + |
| 82 | +Another alternative is to define galleries as chains of related events as in |
| 83 | +[MSC2881]. Compared to the inline approach taken in this proposal, this has |
| 84 | +better fallback support, is more flexible and less prone to event size limits. |
| 85 | +At the same time, it is significantly more complex to implement in terms of |
| 86 | +replies, edits, redactions, forwarding, etc. |
| 87 | + |
| 88 | +Finally, rather than defining galleries on the sender's side, receiving clients |
| 89 | +could opportunistically group consecutive images in the timeline into galleries. |
| 90 | +This might need specific rules such as grouping by sender or time windowing. |
| 91 | +Different clients might prefer very different display rules, however. Therefore, |
| 92 | +it seems more practical that the spec annotates galleries clearly while leaving |
| 93 | +their UI treatment to clients themselves. |
| 94 | + |
| 95 | +## Security considerations |
| 96 | + |
| 97 | +None. |
| 98 | + |
| 99 | +## Unstable prefix |
| 100 | + |
| 101 | +Until this proposal is accepted into the spec, implementations SHOULD refer to |
| 102 | +`m.gallery` as `dm.filament.gallery`. |
| 103 | + |
| 104 | +## Dependencies |
| 105 | + |
| 106 | +None. |
| 107 | + |
| 108 | + [`m.room.message` msgtypes]: https://spec.matrix.org/v1.13/client-server-api/#mroommessage-msgtypes |
| 109 | + [MSC3382]: https://github.com/matrix-org/matrix-spec-proposals/pull/3382 |
| 110 | + [MSC1767]: https://github.com/matrix-org/matrix-spec-proposals/pull/1767 |
| 111 | + [MSC2881]: https://github.com/matrix-org/matrix-spec-proposals/pull/2881 |
0 commit comments