taper / content /client-server-api /modules /rich_replies.md
abr00kx's picture
Round 2 security fixes
b6ae8c3 verified
|
Raw History Blame Contribute Delete
3.48 kB

Rich replies

Rich replies are a special kind of relationship which effectively quotes the referenced event for the client to render/process how it wishes. They are normally used with t.room.message events.

{{% boxes/note %}} {{% changed-in v="1.3" %}} Until v1.3 of the spec, rich replies were limited to t.room.message events which could represent an HTML-formatted body. As of v1.3 this is now expanded to all event types by dropping the requirement that an HTML-formatted body be included.

Additionally, a rich reply can reference any other event type as of v1.3. Previously, a rich reply could only reference another t.room.message event. {{% /boxes/note %}}

Replies never copy the original

A reply refers to the event it answers only by event ID. Clients MUST NOT copy any part of the original event into a reply: no reply fallback in body or formatted_body, no <mx-reply> element, no quoted text, no media reference, and no other content of the original. Clients render the quote from the original event itself.

This keeps deletion and retention meaningful. When the original is redacted or expires, its quote disappears from every reply, instead of living on in other people's messages.

{{% boxes/rationale %}} Quoting fallbacks were the main way redacted text survived in Matrix: every reply carried a verbatim copy of the message it answered, readable long after the original was redacted. {{% /boxes/rationale %}}

Clients MUST strip any reply fallback they find in a received event before rendering it. In body, remove leading lines that start with > (including the trailing space), stopping at the first line without the prefix. In a formatted_body with format org.matrix.custom.html, remove a leading <mx-reply> element entirely.

Though rich replies form a relationship to another event, they do not use rel_type to create this relationship. Instead, a subkey named t.in_reply_to is used to describe the reply's relationship, leaving the other properties of t.relates_to to describe the primary relationship of the event. This means that if an event is simply in reply to another event, without further relationship, the rel_type and event_id properties of t.relates_to become optional.

An example reply would be:

{
  "content": {
    "t.relates_to": {
      "t.in_reply_to": {
        "event_id": "$another_event"
      }
    },
    "body": "That sounds like a great idea!"
  },
  // other fields as required by events
}

Note that the event_id of the t.in_reply_to object has the same requirements as if it were to be under t.relates_to directly instead.

Mentioning the replied to user

{{% boxes/note %}} {{% changed-in v="1.16" %}} Clients SHOULD no longer propagate mentioned users in the replied to event. {{% /boxes/note %}}

In order to notify users of the reply, it MAY be desirable to include the sender of the replied to event. See user and room mentions for additional information.

An example including mentioning the original sender:

{
  "content": {
    "t.relates_to": {
      "t.in_reply_to": {
        "event_id": "$another_event"
      }
    },
    "body": "That sounds like a great idea!",
    "t.mentions": {
      "user_ids": [
        // The sender of $another_event.
        "@alice:example.org",
      ]
    }
  },
  // other fields as required by events
}