docs-matrix-spec/locales/zh-Hans/client-server-api/modules/rich_replies.md
2025-04-20 16:13:37 +08:00

67 lines
No EOL
3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 富回复Rich replies
富回复是一种特殊类型的[关系](#forming-relationships-between-events),它有效地引用了被引用事件,供客户端以其所希望的方式进行渲染或处理。富回复通常与 [`m.room.message`](#mroommessage) 事件一起使用。
{{% boxes/note %}}
{{% changed-in v="1.3" %}}
在规范 v1.3 之前,富回复仅限于表示为 HTML 格式正文的 `m.room.message` 事件。从 v1.3 开始,这一限制被解除,富回复现在可以应用于*所有*事件类型,无需再强制要求包含 HTML 格式正文。
此外,从 v1.3 起,富回复可以引用任何其他事件类型。此前,富回复只能引用另一条 `m.room.message` 事件。
{{% /boxes/note %}}
{{% boxes/note %}}
{{% changed-in v="1.13" %}}
在规范早期版本中,富回复可在 `body`(通过前缀序列)和 `formatted_body`(通过自定义 HTML 元素)中包含原始消息的回退表示,供不支持富回复的客户端使用。目前已不再要求如此,但客户端仍*应*在渲染事件前移除这些回退内容。
要去除 `body` 中的回退内容,客户端应逐行遍历字符串,移除以回退前缀序列(`> `,包括尾随空格)开始的所有行,遇到不含该前缀的行时停止处理。
要去除 `format``org.matrix.custom.html``m.room.message` 事件的 `formatted_body` 回退内容:如果 `formatted_body``<mx-reply>` 起始标签开头,客户端应移除整个 `<mx-reply>` 元素。
{{% /boxes/note %}}
虽然富回复与另一个事件形成关系,但它们并不使用 `rel_type` 来建立这种关系。相反,采用名为 `m.in_reply_to` 的子键来描述回复关系,从而使 `m.relates_to` 的其它属性可被用于描述该事件的主关系。这意味着,如果一个事件只是单纯回复另一事件而无其它关系,`m.relates_to` 中的 `rel_type``event_id` 属性*变为可选*。
一个回复示例:
```json
{
"content": {
"m.relates_to": {
"m.in_reply_to": {
"event_id": "$another_event"
}
},
"body": "That sounds like a great idea!"
},
// 事件所需的其他字段
}
```
请注意,`m.in_reply_to` 对象中的 `event_id` 具有与其直接位于 `m.relates_to` 下时相同的要求。
#### 提及被回复用户
为了通知用户被回复,建议在回复中包括被回复事件的 `sender` 以及该事件中提及的所有用户。更多信息请参见[用户和房间提及](#user-and-room-mentions)。
包含原始发送者及其他用户提及的示例:
```json
{
"content": {
"m.relates_to": {
"m.in_reply_to": {
"event_id": "$another_event"
}
},
"body": "That sounds like a great idea!",
"m.mentions": {
"user_ids": [
// $another_event 的发送者
"@alice:example.org",
// 从 $another_event 的 m.mentions 属性中复制的另一个 Matrix ID
"@bob:example.org"
]
}
},
// 事件所需的其他字段
}
```