Skip to content

Commit 8ab2988

Browse files
authored
Remove reply fallbacks (#1994)
As per MSC2781.
1 parent 7ec9b7f commit 8ab2988

File tree

5 files changed

+40
-168
lines changed

5 files changed

+40
-168
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove reply fallbacks, as per [MSC2781](https://github.com/matrix-org/matrix-spec-proposals/issues/2781).

content/client-server-api/modules/event_replacements.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -362,21 +362,19 @@ property under `m.new_content`.
362362

363363
#### Edits of replies
364364

365-
Some particular constraints apply to events which replace a
366-
[reply](#rich-replies). In particular:
367-
368-
* In contrast to the original reply, there should be no `m.in_reply_to`
369-
property in the the `m.relates_to` object, since it would be redundant (see
370-
[Applying `m.new_content`](#applying-mnew_content) above, which notes that
371-
the original event's `m.relates_to` is preserved), as well as being contrary
372-
to the spirit of the event relationships mechanism which expects only one
373-
"parent" per event.
374-
375-
* `m.new_content` should **not** contain any [reply
376-
fallback](#fallbacks-for-rich-replies),
377-
since it is assumed that any client which can handle edits can also display
378-
replies natively. However, the `content` of the replacement event should provide
379-
fallback content for clients which support neither rich replies nor edits.
365+
A particular constraint applies to events which replace a [reply](#rich-replies):
366+
in contrast to the original reply, there should be no `m.in_reply_to` property
367+
in the the `m.relates_to` object, since it would be redundant (see
368+
[Applying `m.new_content`](#applying-mnew_content) above, which notes that the
369+
original event's `m.relates_to` is preserved), as well as being contrary to the
370+
spirit of the event relationships mechanism which expects only one "parent" per
371+
event.
372+
373+
{{% boxes/note %}}
374+
{{% changed-in v="1.13" %}}
375+
In previous versions of the specification, events which replace a [reply](#rich-replies)
376+
could include a fallback in the `content`. This is no longer the case.
377+
{{% /boxes/note %}}
380378

381379
An example of an edit to a reply is as follows:
382380

@@ -385,15 +383,11 @@ An example of an edit to a reply is as follows:
385383
"type": "m.room.message",
386384
// irrelevant fields not shown
387385
"content": {
388-
"body": "> <@alice:example.org> question\n\n* reply",
386+
"body": "* reply",
389387
"msgtype": "m.text",
390-
"format": "org.matrix.custom.html",
391-
"formatted_body": "<mx-reply><blockquote><a href=\"https://matrix.to/#/!somewhere:example.org/$event:example.org\">In reply to</a> <a href=\"https://matrix.to/#/@alice:example.org\">@alice:example.org</a><br />question</blockquote></mx-reply>* reply",
392388
"m.new_content": {
393389
"body": "reply",
394390
"msgtype": "m.text",
395-
"format": "org.matrix.custom.html",
396-
"formatted_body": "reply"
397391
},
398392
"m.relates_to": {
399393
"rel_type": "m.replace",

content/client-server-api/modules/instant_messaging.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ having appropriate closing tags, appropriate attributes (considering the
9898
custom ones defined in this specification), and generally valid
9999
structure.
100100

101-
A special tag, `mx-reply`, may appear on rich replies (described below)
102-
and should be allowed if, and only if, the tag appears as the very first
103-
tag in the `formatted_body`. The tag cannot be nested and cannot be
104-
located after another tag in the tree. Because the tag contains HTML, an
105-
`mx-reply` is expected to have a partner closing tag and should be
106-
treated similar to a `div`. Clients that support rich replies will end
107-
up stripping the tag and its contents and therefore may wish to exclude
108-
the tag entirely.
101+
{{% boxes/note %}}
102+
{{% changed-in v="1.13" %}}
103+
In previous versions of the specification, [rich replies](#rich-replies) could
104+
use a special tag, `mx-reply`. This is no longer the case. Clients SHOULD strip
105+
this tag and its content. See the "Rich replies" section for more information.
106+
{{% /boxes/note %}}
109107

110108
{{% boxes/note %}}
111109
A future iteration of the specification will support more powerful and

content/client-server-api/modules/rich_replies.md

Lines changed: 19 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11

22
### Rich replies
33

4-
{{% changed-in v="1.3" %}}
5-
64
Rich replies are a
75
special kind of [relationship](#forming-relationships-between-events) which
86
effectively quotes the referenced event for the client to render/process how
97
it wishes. They are normally used with [`m.room.message`](#mroommessage) events.
108

119
{{% boxes/note %}}
10+
{{% changed-in v="1.3" %}}
1211
Until v1.3 of the spec, rich replies were limited to `m.room.message` events
1312
which could represent an HTML-formatted body. As of v1.3 this is now expanded
1413
to *all* event types by dropping the requirement that an HTML-formatted body
@@ -18,9 +17,24 @@ Additionally, a rich reply can reference any other event type as of v1.3.
1817
Previously, a rich reply could only reference another `m.room.message` event.
1918
{{% /boxes/note %}}
2019

21-
When possible, events SHOULD include a [fallback representation](#fallbacks-for-rich-replies)
22-
to allow clients which do not render rich replies to still see something which
23-
appears to be a quoted reply.
20+
{{% boxes/note %}}
21+
{{% changed-in v="1.13" %}}
22+
In previous versions of the specification, rich replies could include a fallback
23+
representation of the original message message in the `body` (using a prefix
24+
sequence) and `formatted_body` (using a custom HTML element) for clients that do
25+
not support rich replies. This is no longer the case, but clients SHOULD still
26+
remove this fallback before rendering the event.
27+
28+
To strip the fallback on the `body`, the client should iterate over each
29+
line of the string, removing any lines that start with the fallback
30+
prefix sequence (`> `, including the trailing space) and stopping when
31+
a line is encountered without the prefix.
32+
33+
To strip the fallback on the `formatted_body` of an `m.room.message` event with
34+
a `format` of `org.matrix.custom.html`: if the`formatted_body` begins with an
35+
`<mx-reply>` start tag, the client should remove the entirety of the
36+
`<mx-reply>` element.
37+
{{% /boxes/note %}}
2438

2539
Though rich replies form a relationship to another event, they do not
2640
use `rel_type` to create this relationship. Instead, a subkey named `m.in_reply_to`
@@ -48,137 +62,6 @@ An example reply would be:
4862
Note that the `event_id` of the `m.in_reply_to` object has the same requirements
4963
as if it were to be under `m.relates_to` directly instead.
5064

51-
#### Fallbacks for rich replies
52-
53-
Some clients may not have support for rich replies and therefore need a
54-
fallback to use instead. Clients that do not support rich replies should
55-
render the event as if rich replies were not special.
56-
57-
Clients that do support rich replies SHOULD provide the fallback format on
58-
replies, and MUST strip the fallback before rendering the reply. The
59-
specific fallback text is different for each `msgtype`, however the
60-
general format for the `body` is:
61-
62-
```text
63-
> <@alice:example.org> This is the first line of the original body
64-
> This is the second line
65-
66-
This is where the reply goes
67-
```
68-
69-
The `formatted_body`, if present and using an associated `format` of
70-
`org.matrix.custom.html`, should use the following template:
71-
72-
```html
73-
<mx-reply>
74-
<blockquote>
75-
<a href="https://matrix.to/#/!somewhere:example.org/$event:example.org">In reply to</a>
76-
<a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a>
77-
<br />
78-
<!-- This is where the related event's HTML would be. -->
79-
</blockquote>
80-
</mx-reply>
81-
This is where the reply goes.
82-
```
83-
84-
If the related event does not have a `formatted_body`, the event's
85-
`body` should be considered after encoding any HTML special characters.
86-
Note that the `href` in both of the anchors use a [matrix.to
87-
URI](/appendices#matrixto-navigation).
88-
89-
##### Stripping the fallback
90-
91-
Clients which support rich replies MUST strip the fallback from the
92-
event before rendering the event. This is because the text provided in
93-
the fallback cannot be trusted to be an accurate representation of the
94-
event. After removing the fallback, clients are recommended to represent
95-
the event referenced by `m.in_reply_to` similar to the fallback's
96-
representation, although clients do have creative freedom for their user
97-
interface. Clients should prefer the `formatted_body` over the `body`,
98-
just like with other `m.room.message` events.
99-
100-
To strip the fallback on the `body`, the client should iterate over each
101-
line of the string, removing any lines that start with the fallback
102-
prefix ("&gt; ", including the space, without quotes) and stopping when
103-
a line is encountered without the prefix. This prefix is known as the
104-
"fallback prefix sequence".
105-
106-
To strip the fallback on the `formatted_body`, the client should remove
107-
the entirety of the `mx-reply` tag.
108-
109-
##### Fallback for `m.text`, `m.notice`, and unrecognised message types
110-
111-
Using the prefix sequence, the first line of the related event's `body`
112-
should be prefixed with the user's ID, followed by each line being
113-
prefixed with the fallback prefix sequence. For example:
114-
115-
```text
116-
> <@alice:example.org> This is the first line
117-
> This is the second line
118-
119-
This is the reply
120-
```
121-
122-
The `formatted_body` uses the template defined earlier in this section.
123-
124-
##### Fallback for `m.emote`
125-
126-
Similar to the fallback for `m.text`, each line gets prefixed with the
127-
fallback prefix sequence. However an asterisk should be inserted before
128-
the user's ID, like so:
129-
130-
```text
131-
> * <@alice:example.org> feels like today is going to be a great day
132-
133-
This is the reply
134-
```
135-
136-
The `formatted_body` has a subtle difference for the template where the
137-
asterisk is also inserted ahead of the user's ID:
138-
139-
```html
140-
<mx-reply>
141-
<blockquote>
142-
<a href="https://matrix.to/#/!somewhere:example.org/$event:example.org">In reply to</a>
143-
* <a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a>
144-
<br />
145-
<!-- This is where the related event's HTML would be. -->
146-
</blockquote>
147-
</mx-reply>
148-
This is where the reply goes.
149-
```
150-
151-
##### Fallback for `m.image`, `m.video`, `m.audio`, and `m.file`
152-
153-
The related event's `body` would be a file name, which may not be very
154-
descriptive. The related event should additionally not have a `format`
155-
or `formatted_body` in the `content` - if the event does have a `format`
156-
and/or `formatted_body`, those fields should be ignored. Because the
157-
filename alone may not be descriptive, the related event's `body` should
158-
be considered to be `"sent a file."` such that the output looks similar
159-
to the following:
160-
161-
```text
162-
> <@alice:example.org> sent a file.
163-
164-
This is the reply
165-
```
166-
```html
167-
<mx-reply>
168-
<blockquote>
169-
<a href="https://matrix.to/#/!somewhere:example.org/$event:example.org">In reply to</a>
170-
<a href="https://matrix.to/#/@alice:example.org">@alice:example.org</a>
171-
<br />
172-
sent a file.
173-
</blockquote>
174-
</mx-reply>
175-
This is where the reply goes.
176-
```
177-
178-
For `m.image`, the text should be `"sent an image."`. For `m.video`, the
179-
text should be `"sent a video."`. For `m.audio`, the text should be
180-
`"sent an audio file"`.
181-
18265
#### Mentioning the replied to user
18366

18467
In order to notify users of the reply, it may be desirable to include the `sender`

content/client-server-api/modules/threading.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ flag to `true`.
106106
}
107107
```
108108

109-
For `m.room.message` events represented this way, no [reply fallback](#fallbacks-for-rich-replies)
110-
is specified. This allows thread-aware clients to discard the `m.in_reply_to` object entirely
111-
when `is_falling_back` is `true`.
112-
113109
{{% boxes/note %}}
114110
Clients which are acutely aware of threads (they do not render threads, but are otherwise
115111
aware of the feature existing in the spec) can treat rich replies to an event with a `rel_type`

0 commit comments

Comments
 (0)