-
Notifications
You must be signed in to change notification settings - Fork 400
MSC2881: Message Attachments #2881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MurzNN
wants to merge
40
commits into
matrix-org:main
Choose a base branch
from
MurzNN:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
e0e7133
Added proposial "Message Attachments"
MurzNN 96fef8b
Assign 2881 number to MSC and some typos
MurzNN 8065221
Added mentions of similar MSC
MurzNN 0de8e47
Direct mxc links and improved alternative
MurzNN 45c91fd
Improved description of 1'st alternative
MurzNN a226142
Added second implementation
MurzNN 616dcba
Added unstable prefixes, fixed typo
MurzNN 6b5ccbe
Added unstable to class to
MurzNN e343893
Moved fallback dispay to implementation 1
MurzNN d448559
Added example of media event to implentation 2
MurzNN c33ef1a
Move second implementation to main place
MurzNN ad7f2fa
Paraphrasing
MurzNN dd423aa
Described edits and improved description
MurzNN 76e0522
Added fallback description
MurzNN 9a7f694
Added edits composer description
MurzNN 910be82
Added link to extensible events suggestion
MurzNN abc7edf
Added alternative with attachments after message
MurzNN 108ffa7
Added redact action on remove media
MurzNN 2be176c
Fixed typo
MurzNN eea1ba0
Fix typo again
MurzNN 87bfff2
Added delete (redact action)
MurzNN ba19693
Added potential issue and hiding recommendation
MurzNN 6147bd6
Added link to MSC2278
MurzNN 6da8d3a
Fix typos and added link to MSC2675
MurzNN fa6f59b
Fix typo
MurzNN 2e8536e
Added proposal for replacement to #2530 / #2529
MurzNN 0eb7773
Added links to implementation examples
MurzNN 00ade35
Improved description
MurzNN 5df15b6
Description for implementation together with #2530
MurzNN a470fba
improve grammar
MurzNN 39c08c4
Move back first alternative as option two
MurzNN 12c0a3f
Fix typo
MurzNN 21f14c2
Described replacing fallback to rich representation
MurzNN cfb8f55
Name options as primary-secondary
MurzNN 55db2fe
Named options
MurzNN 9ebce4a
Grammar fixes
MurzNN 633160a
Grammar fixes
MurzNN d77ba1e
Grammar fixes
MurzNN ae52584
Merge branch 'matrix-org:main' into master
MurzNN 7d4542f
Link to MSC3051 and separate alternative version to 3382
MurzNN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# MSC2881: Message Attachments | ||
|
||
*This MSC is especially for media image attachments to message, but I try to make it extendable for multiple attachment types (files, videos, external URLs, links to other Matrix events, etc). So, in most of examples, I am using "image", but it means, that, instead of image, there may be another attachment type.* | ||
|
||
In the current implementation each media (file, image, video) can be sent only via a separate event to the room. But in most cases media is not sent alone, it must be commented via some text by the sender. So the user often wants to attach some images (one or several) directly to his text message when he is composing it. | ||
|
||
And now the user can send images only before the message (or after it) as a separate message, but he can't attach images during the composing process to send them when the text is finished, together with the text message in one event. | ||
|
||
On the display side, when the user sends multiple images, the problem is that each image is displayed alone, as separate event with full width in timeline, not linked to the message, and not grouped to the gallery. | ||
|
||
## Proposal | ||
MurzNN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To solve the described problem, I propose to extend `m.room.message` event with `m.attachments` field, that contains the array of message attachments. This can be done together with [MSC1767: Extensible events in Matrix](https://github.com/matrix-org/matrix-doc/pull/1767) with adding new type `m.attachments`, which will contain the group of attached elements. | ||
|
||
Each element of `m.attachments` array has a structure like a message with media item (`m.image`, `m.video`, etc), here is example of the message with this field: | ||
|
||
```json | ||
{ | ||
"type": "m.room.message", | ||
"content": { | ||
"msgtype": "m.text", | ||
"body": "Here is my photos and videos from yesterday event", | ||
"m.attachments": [ | ||
{ | ||
"msgtype": "m.image", | ||
"url": "mxc://example.com/KUAQOesGECkQTgdtedkftISg", | ||
"body": "Image 1.jpg", | ||
"info": { | ||
"mimetype": "image/jpg", | ||
"size": 1153501, | ||
"w": 963, | ||
"h": 734, | ||
"thumbnail_url": "mxc://example.com/0f4f88220b7c9a83d122ca8f9f11faacfc93cd18", | ||
"thumbnail_info": { | ||
"mimetype": "image/jpg", | ||
"size": 575468, | ||
"w": 787, | ||
"h": 600 | ||
} | ||
} | ||
}, | ||
{ | ||
"msgtype": "m.video", | ||
"url": "mxc://example.com/KUAQOe1GECk2TgdtedkftISg", | ||
"body": "Video 2.mp4", | ||
"info": { | ||
"mimetype": "video/mp4", | ||
"size": 6615304, | ||
"w": 1280, | ||
"h": 720, | ||
"thumbnail_url": "mxc://example.com/0f4f88120bfc9183d122ca8f9f11faacfc93cd18", | ||
"thumbnail_info": { | ||
"mimetype": "image/jpeg", | ||
"size": 2459, | ||
"w": 800, | ||
"h": 450 | ||
}, | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Client support | ||
|
||
### Compose recommendations: | ||
|
||
In the message composer, on "paste file" event, the Matrix client must not instantly upload the file to the server, but the client must show its thumbnail in the special area, with the ability to remove it and to add more files. *Alternatively, it can start uploading instantly to improve the speed of the following message sending process, but there is no way to delete media in Matrix API, so server will store each file, even if it is not attached to the message.* | ||
|
||
On "message send" action, Matrix client must upload each attached file to server, get `mxc` of it, and attach `mxc` to message contents. | ||
|
||
If the user uploads only one media and leaves the message text empty, media can be sent as regular `m.image` or similar message. | ||
|
||
### Display recommendations: | ||
|
||
On the client site, attachments must be displayed as grid of clickable thumbnails, like the current `m.image` events, but with a smaller size, having fixed height, like a regular image gallery. On click, Matrix client must display media in full size, and, if possible, as a gallery with "next-previous" buttons. | ||
|
||
If the message contains only one attachment, it can be displayed as full-width thumbnail, like current `m.image` and `m.video` messages. | ||
|
||
### Fallback display | ||
|
||
For fallback display of attachments in old Matrix clients, we can attach them directly to `formatted_body` of message, here is HTML representation: | ||
|
||
```html | ||
<p>Here is my photos and videos from yesterday event</p> | ||
<div class="mx-attachments"> | ||
<p>Attachments:</p> | ||
<ul> | ||
<li><a href="https://example.com/_matrix/media/r0/download/example.com/KUAQOesGECkQTgdtedkftISg">Image 1.jpg</a></li> | ||
MurzNN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<li><a href="https://example.com/_matrix/media/r0/download/example.com/0f4f88120bfc9183d122ca8f9f11faacfc93cd18">Video 2.mp4</a></li> | ||
</ul> | ||
</div> | ||
``` | ||
|
||
and JSON of `content` field: | ||
|
||
```json | ||
"content": { | ||
"msgtype": "m.text", | ||
"body": "Here is my photos and videos from yesterday event\nAttachments:\nhttps://example.com/_matrix/media/r0/download/example.com//KUAQOesGECkQTgdtedkftISg\nhttps://example.com/_matrix/media/r0/download/example.com/0f4f88120bfc9183d122ca8f9f11faacfc93cd18", | ||
"format": "org.matrix.custom.html", | ||
"formatted_body": "<p>Here is my photos and videos from yesterday event</p>\n<div class=\"mx-attachments\"><p>Attachments:</p>\n<ul>\n<li><a href="https://example.com/_matrix/media/r0/download/example.com//KUAQOesGECkQTgdtedkftISg">Image 1.jpg</a></li>\n<li><a href="https://example.com/_matrix/media/r0/download/example.com/0f4f88120bfc9183d122ca8f9f11faacfc93cd18">Video 2.mp4</a></li>\n</ul></div>" | ||
} | ||
``` | ||
|
||
## Server support | ||
|
||
This MSC does not need any changes on server side. | ||
|
||
## Potential issues | ||
|
||
The main issue is fallback display for old clients. Providing the list of links to each attachment into the formatted body is suitable workaround, and clients, which render attachments on their own, can easily remove this block via cutting `<div class="mx-attachments">` tag. | ||
|
||
## Alternatives | ||
|
||
1. An alternative can be posting media messages as separate events, as it was done earlier, and aggregating them into event via `m.relates_to` field, but clients must do a hide of those events, when aggregating event will be added to the room (like editions), but this will be harder to implement. | ||
MurzNN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
2. Other alternative is embedding images (and other media types) into message body via html tags, but this will make extracting and stylizing of the attachments harder. | ||
3. Next alternative is reuse [MSC1767: Extensible events in Matrix](https://github.com/matrix-org/matrix-doc/pull/1767) for attaching and grouping media attachments, but in current state it requires only one unique type of content per message, so we can't attach, for example, two `m.image` items into one message. Maybe, instead of separate current issue, we can extend [MSC1767](https://github.com/matrix-org/matrix-doc/pull/1767) via converting `content` to array, to allow adding several items of same type to one message. | ||
|
||
MurzNN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
## Future considerations | ||
|
||
In future, we may extend the `m.attachments` field with new types to allow attaching external URL as cards with URL preview, oEmbed entities, and other events (for example, to forward the list of several events to other room with the user comment). |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.