Skip to content
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

Spec /relations and aggregations #1062

Merged
merged 31 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1d70a8d
Commit to show changes to rich replies section
turt2live May 5, 2022
03c4638
Move rich replies to a module
turt2live May 5, 2022
01cd76e
Add remainder of MSC2674
turt2live May 14, 2022
ff03381
Pivot away from MSC3440: Threads
turt2live May 14, 2022
b319d2f
Add changelog entries so far
turt2live May 14, 2022
9e7929c
Make a note for why we have aggregations/relations if nothing uses it
turt2live May 14, 2022
29c9465
Outright remove threads references
turt2live May 17, 2022
1435d06
Define MSC2675
turt2live May 18, 2022
7a92cf5
Define MSC3666
turt2live May 18, 2022
76e3611
Add note for rich replies?
turt2live May 18, 2022
2063d11
Update content/client-server-api/_index.md
turt2live May 27, 2022
109bfb2
Clarify how ignoring works for aggregations.
turt2live May 27, 2022
0d35037
Try to clarify redactions a bit
turt2live May 27, 2022
532b06b
Clarify using parent/child language
turt2live May 27, 2022
9fa50a7
Add missing bits of MSC2675
turt2live May 27, 2022
753fd81
Add changelog for aggregations
turt2live May 27, 2022
d9004d7
Appease the linters
turt2live May 27, 2022
42e5c4d
Update data/api/client-server/relations.yaml
turt2live May 27, 2022
f8d667a
Apply suggestions from code review
turt2live Jun 2, 2022
315b327
Apply suggestions from code review
turt2live Jun 2, 2022
2cc631e
Try to clarify the return of /relations
turt2live Jun 2, 2022
b5b6fd9
Fix required attribute
turt2live Jun 2, 2022
09422a3
Fix wording round 1
turt2live Jun 7, 2022
0f65b2f
Try to fix pagination
turt2live Jun 7, 2022
340f9e5
Copy/paste the endpoint to make Open API happy
turt2live Jun 7, 2022
c02e1f1
Fix code block examples for rich replies
turt2live Jun 7, 2022
b509444
Apply suggestions from code review
turt2live Jun 8, 2022
5bb8b3e
Apply suggestions on all 3 endpoints
turt2live Jun 8, 2022
13a43c0
Fix description of relationships API
turt2live Jun 8, 2022
a00e70e
Fix warning about server-side aggregation/bundling
turt2live Jun 8, 2022
50b4811
Merge remote-tracking branch 'origin/travis/spec/aggregations' into t…
turt2live Jun 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1062.feature.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Relax the restrictions on Rich Replies, as per [MSC3676](https://github.com/matrix-org/matrix-spec-proposals/pull/3676).
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1062.feature.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Describe a structured system for event relationships, as per [MSC2674](https://github.com/matrix-org/matrix-spec-proposals/pull/2674).
1 change: 1 addition & 0 deletions changelogs/client_server/newsfragments/1062.feature.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Describe how relationships between events can be "aggregated", as per [MSC2675](https://github.com/matrix-org/matrix-spec-proposals/pull/2675) and [MSC3666](https://github.com/matrix-org/matrix-spec-proposals/pull/3666).
225 changes: 225 additions & 0 deletions content/client-server-api/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,16 @@ There are several APIs provided to `GET` events for a room:

### Sending events to a room

{{% boxes/note %}}
{{% added-in v="1.3" %}}

Servers might need to post-process some events if they
[relate to](#forming-relationships-between-events) another event. The event's
relationship type (`rel_type`) determines any restrictions which might apply,
such as the user only being able to send one event of a given type in relation
to another.
{{% /boxes/note %}}

{{% http-api spec="client-server" api="room_state" %}}

**Examples**
Expand Down Expand Up @@ -1831,6 +1841,219 @@ the topic to be removed from the room.

{{% http-api spec="client-server" api="redaction" %}}

### Forming relationships between events

{{% changed-in v="1.3" %}}
richvdh marked this conversation as resolved.
Show resolved Hide resolved

In some cases it is desirable to logically associate one event's contents with
another event's contents — for example, when replying to a message, editing an
event, or simply looking to add context for an event's purpose.

Events are related to each other in a parent/child structure, where any event can
become a parent by simply having a child event point at it. Parent events do not
define their children, instead relying on the children to describe their parent.
richvdh marked this conversation as resolved.
Show resolved Hide resolved

The relationship between a child and its parent event is described in the child
event's `content` as `m.relates_to` (defined below). A child event can point at
any other event, including another child event, to build the relationship so long
as both events are in the same room, however additional restrictions might be imposed
by the type of the relationship (the `rel_type`).

{{% boxes/note %}}
Child events can point at other child events, forming a chain of events. These chains
can naturally take the shape of a tree if two independent children point at a single
parent event, for example.
{{% /boxes/note %}}

To allow the server to aggregate and find child events for a parent, the `m.relates_to`
key of an event MUST be included in the plaintext copy of the event. It cannot be
exclusively recorded in the encrypted payload as the server cannot decrypt the event
for processing.

{{% boxes/warning %}}
If an encrypted event contains an `m.relates_to` in its payload, it should be
ignored and instead favour the plaintext `m.relates_to` copy (including when there
is no plaintext copy). This is to ensure the client's behaviour matches the server's
capability to handle relationships.
{{% /boxes/warning %}}

Relationships which don't match the schema, or which break the rules of a relationship,
are simply ignored. Such an example might be the parent and child being in different
turt2live marked this conversation as resolved.
Show resolved Hide resolved
rooms or the relationship missing properties required by the schema below. The events
turt2live marked this conversation as resolved.
Show resolved Hide resolved
would appear independent of each other or optionally with an error message (if
rendered/handled by the client exclusively).
turt2live marked this conversation as resolved.
Show resolved Hide resolved

{{% boxes/note %}}
While this specification describes an `m.relates_to` object containing a `rel_type`, there
is not currently any relationship type which uses this structure. Replies, described below,
form their relationship outside of the `rel_type` as a legacy type of relationship. Future
versions of the specification might change replies to better match the relationship structures.

Custom `rel_type`s can, and should, still use the schema described above for relevant
behaviour.
{{% /boxes/note %}}

`m.relates_to` is defined as follows:

{{% definition path="api/client-server/definitions/m.relates_to" %}}

#### Relationship types

This specification describes the following relationship types:

* [Rich replies](#rich-replies) (**Note**: does not use `rel_type`).

#### Aggregations

{{% added-in v="1.3" %}}
richvdh marked this conversation as resolved.
Show resolved Hide resolved

Some child events can be "aggregated" by the server, depending on their
`rel_type`. This can allow a set of child events to be summarised to the client without
the client needing the child events themselves.

An example of this might be that a `rel_type` requires an extra `key` field which, when
appropriately specified, would mean that the client receives a total count for the number
of times that `key` was used by child events.

The actual aggregation format depends on the `rel_type`.

{{% boxes/note %}}
This specification does not currently describe any `rel_type` which require
turt2live marked this conversation as resolved.
Show resolved Hide resolved
aggregation. This functionality forms a framework for future extensions.
{{% /boxes/note %}}

Aggregations are sometimes automatically included by a server alongside the parent
event. This This is known as a "bundled aggregation" or "bundle" for simplicity. The
turt2live marked this conversation as resolved.
Show resolved Hide resolved
act of doing this is "bundling".

When an event is served to the client through the APIs listed below, a `m.relations` property
is included under `unsigned` if the event has child events which can be aggregated and point
at it. The `m.relations` property is an object keyed by `rel_type` and value being the type-specific
aggregated format for that `rel_type`, also known as the bundle.

For example (unimportant fields not included):

```json
{
"event_id": "$my_event",
"unsigned": {
"m.relations": {
"org.example.possible_annotations": [
{
"key": "👍",
"origin_server_ts": 1562763768320,
"count": 3
},
{
"key": "👎",
"origin_server_ts": 1562763768320,
"count": 1
}
],
"org.example.possible_thread": {
"current_server_participated": true,
"count": 7,
"latest_event": {
"event_id": "$another_event",
"content": {
"body": "Hello world"
}
}
}
}
}
}
```

Note how the `org.example.possible_annotations` bundle is an array compared to the
`org.example.possible_thread` bundle where the server is summarising the state of
the relationship in a single object. Both are valid ways to aggregate, and their
exact types depend on the `rel_type`.

{{% boxes/warning %}}
State events do not currently receive bundled aggregations. This is not
necessarily a deliberate design decision, and MSCs which aim to fix this are welcome.
{{% /boxes/warning %}}

The endpoints where the server *should* include bundled aggregations are:

* [`GET /rooms/{roomId}/messages`](#get_matrixclientv3roomsroomidmessages)
* [`GET /rooms/{roomId}/context/{eventId}`](#get_matrixclientv3roomsroomidcontexteventid)
* [`GET /rooms/{roomId}/event/{eventId}`](#get_matrixclientv3roomsroomideventeventid)
* [`GET /rooms/{roomId}/relations/{eventId}`](#get_matrixclientv1roomsroomidrelationseventid)
* [`GET /rooms/{roomId}/relations/{eventId}/{relType}`](#get_matrixclientv1roomsroomidrelationseventidreltype)
* [`GET /rooms/{roomId}/relations/{eventId}/{relType}/{eventType}`](#get_matrixclientv1roomsroomidrelationseventidreltypeeventtype)
* [`GET /sync`](#get_matrixclientv3sync) when the relevant section has a `limited` value
of `true`.
* [`POST /search`](#post_matrixclientv3search) for any matching events under `room_events`.

{{% boxes/note %}}
The server is **not** required to return bundled aggregations on deprecated endpoints
such as `/initialSync`.
{{% /boxes/note %}}

While this functionality allows the client to see what was known to the server at the
time of handling, the client should continue to aggregate locally if it is aware of
the relationship type's behaviour. For example, a client might increment a `count`
on a parent event's bundle if it saw a new child event which referenced that parent.

The bundle provided by the server only includes child events which were known at the
time the client would receive the bundle. For example, in a single `/sync` response
with the parent and multiple child events the child events would have already been
included on the parent's `m.relations` field. Events received in future syncs would
need to be aggregated manually by the client.

{{% boxes/note %}}
Events from [ignored users](#ignoring-users) do not appear in the aggregation
from the server, however clients might still have events from ignored users cached. Like
with normal events, clients will need to de-aggregate child events sent by ignored users to
avoid them being considered in counts. Servers must additionally ensure they do not
consider child events from ignored users when preparing a bundle for the client.
{{% /boxes/note %}}

When a parent event is redacted, the child events which pointed to that parent remain, however
when a child event is redacted then the relationship is broken. Therefore, the server needs
to de-aggregate or disassociate the event once the relationship is lost. Clients with local
aggregation or which handle redactions locally should do the same.

It is suggested that clients perform local echo on aggregations — for instance, aggregating
a new child event into a bundle optimistically until the server returns a failure or the client
richvdh marked this conversation as resolved.
Show resolved Hide resolved
gives up on sending the event, at which point the event should be de-aggregated and an
error or similar shown. The client should be cautious to not aggregate an event twice if
it has already optimistically aggregated the event. Clients are encouraged to take this
a step further to additionally track child events which target unsent/pending events,
likely using the transaction ID as a temporary event ID until a proper event ID is known.

{{% boxes/warning %}}
Due to history visibility restrictions, child events might not be visible to the user
if they are in a section of history the user cannot see. This can mean inaccurate aggregations
for events that are "out of range".
turt2live marked this conversation as resolved.
Show resolved Hide resolved

Additionally, if the server is missing portions of the room history then it may not be
able to accurately aggregate the events.
{{% /boxes/warning %}}

#### Relationships API
turt2live marked this conversation as resolved.
Show resolved Hide resolved

To retrieve the child events for a parent from the server, the client can call the
following endpoint. The events returned might require local aggregation by the client,
however if those same events have bundles of their own then they should be present. A
turt2live marked this conversation as resolved.
Show resolved Hide resolved
hypothetical example would be retrieving all responses to a thread, and those responses
might have emoji reactions made against them: the client will need to construct the
thread itself, but the events in the thread should have a reactions bundle on them.

The lack of aggregation behaviour allows clients to retrieve child events which don't
require aggregation, but do make use of a `rel_type`.
turt2live marked this conversation as resolved.
Show resolved Hide resolved

This endpoint is particularly useful if the client has lost context on the aggregation for
a parent event and needs to rebuild/verify it.

{{% boxes/note %}}
Because replies do not use `rel_type`, they will not be accessible via this API.
{{% /boxes/note %}}

{{% http-api spec="client-server" api="relations" %}}

## Rooms

### Types
Expand Down Expand Up @@ -2212,6 +2435,7 @@ that profile.
| Module / Profile | Web | Mobile | Desktop | CLI | Embedded |
|------------------------------------------------------------|-----------|----------|----------|----------|----------|
| [Instant Messaging](#instant-messaging) | Required | Required | Required | Required | Optional |
| [Rich replies](#rich-replies) | Optional | Optional | Optional | Optional | Optional |
| [Direct Messaging](#direct-messaging) | Required | Required | Required | Required | Optional |
| [Mentions](#user-room-and-group-mentions) | Required | Required | Required | Optional | Optional |
| [Presence](#presence) | Required | Required | Required | Required | Optional |
Expand Down Expand Up @@ -2291,6 +2515,7 @@ applications, they are not intended to be fully-fledged communication
systems.

{{% cs-module name="instant_messaging" %}}
{{% cs-module name="rich_replies" %}}
{{% cs-module name="voip_events" %}}
{{% cs-module name="typing_notifications" %}}
{{% cs-module name="receipts" %}}
Expand Down
Loading