43 lines
No EOL
1.3 KiB
Markdown
43 lines
No EOL
1.3 KiB
Markdown
### 引用关系
|
|
|
|
{{% added-in v="1.5" %}}
|
|
|
|
以通用方式引用其他事件时,可以使用 `rel_type` 为 `m.reference` 作为一种[关系类型](#forming-relationships-between-events)。引用本身没有特定含义,通常依赖于具体的应用场景。例如,[密钥验证框架](#key-verification-framework)便使用引用关系,将不同的事件与某次特定的验证尝试关联起来。
|
|
|
|
{{% boxes/note %}}
|
|
希望支持话题或回复功能的客户端应使用除引用以外的其他关系类型。引用通常用于关联数据而非消息。
|
|
{{% /boxes/note %}}
|
|
|
|
#### 服务器行为
|
|
|
|
##### `m.reference` 的服务端聚合
|
|
|
|
`m.reference` 关系的[聚合格式](#aggregations-of-child-events)包含一个名为 `chunk` 的属性,该属性列出了所有对该事件(父事件)进行 `m.reference` 的事件。目前,`chunk` 中的事件只包含单一的 `event_id` 字段。
|
|
|
|
例如,给定一个带有如下 `m.reference` 关系的事件:
|
|
|
|
```json
|
|
{
|
|
"content": {
|
|
"m.relates_to": {
|
|
"rel_type": "m.reference",
|
|
"event_id": "$another_event"
|
|
}
|
|
// 其他需要的内容字段
|
|
}
|
|
// 事件所需的其他字段
|
|
}
|
|
```
|
|
|
|
其聚合结果如下所示:
|
|
|
|
```json
|
|
{
|
|
"m.reference": {
|
|
"chunk": [
|
|
{ "event_id": "$one" },
|
|
{ "event_id": "$two" }
|
|
]
|
|
}
|
|
}
|
|
``` |