Skip to content

Commit c31a073

Browse files
committed
Spec annotations
1 parent a21b23d commit c31a073

File tree

6 files changed

+170
-0
lines changed

6 files changed

+170
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `m.annotation` relations (reactions), as per [MSC2677](https://github.com/matrix-org/matrix-spec-proposals/pull/2677).

content/client-server-api/_index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,7 @@ This specification describes the following relationship types:
19961996

19971997
* [Rich replies](#rich-replies) (**Note**: does not use `rel_type`).
19981998
* [Event replacements](#event-replacements).
1999+
* [Event annotations](#event-annotations-and-reactions).
19992000
* [Threads](#threading).
20002001
* [References](#reference-relations)
20012002

@@ -2579,6 +2580,7 @@ that profile.
25792580
| [Moderation policies](#moderation-policy-lists) | Optional | Optional | Optional | Optional | Optional |
25802581
| [Spaces](#spaces) | Optional | Optional | Optional | Optional | Optional |
25812582
| [Event Replacements](#event-replacements) | Optional | Optional | Optional | Optional | Optional |
2583+
| [Event Annotations and reactions](#event-annotations-and-reactions) | Optional | Optional | Optional | Optional | Optional |
25822584
| [Threading](#threading) | Optional | Optional | Optional | Optional | Optional |
25832585
| [Reference Relations](#reference-relations) | Optional | Optional | Optional | Optional | Optional |
25842586

@@ -2665,5 +2667,7 @@ systems.
26652667
{{< cs-module name="moderation_policies" >}}
26662668
{{< cs-module name="spaces" >}}
26672669
{{< cs-module name="event_replacements" >}}
2670+
{{< cs-module name="event_annotations" >}}
26682671
{{< cs-module name="threading" >}}
26692672
{{< cs-module name="reference_relations" >}}
2673+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
### Event annotations and reactions
2+
3+
{{% added-in v="1.7" %}}
4+
5+
#### `m.annotation` relationship type
6+
7+
Annotations are events that use an [event
8+
relationship](#forming-relationships-between-events) with a `rel_type` of
9+
`m.annotation`.
10+
11+
Annotations are normally used for "reactions": for example, if the user wants
12+
to react to an event with a thumbs-up, then the client sends an annotation
13+
event with the corresponding emoji (👍). Another potential usage is to allow
14+
bots to send an event indicating the success or failure of a command.
15+
16+
Along with the normal properties `event_id` and `rel_type`, an `m.relates_to`
17+
property with `rel_type: m.annotion` should contain a `key` that indicates the
18+
annotation being applied. For example, when reacting with emojis, the key
19+
contains the emoji being used.
20+
21+
An example `m.annotation` relationship is shown below:
22+
23+
```json
24+
"m.relates_to": {
25+
"rel_type": "m.annotation",
26+
"event_id": "$some_event_id",
27+
"key": "👍"
28+
}
29+
```
30+
31+
{{% boxes/note %}}
32+
Any `type` of event is eligible for an annotation, including state events.
33+
{{% /boxes/note %}}
34+
35+
#### Events
36+
37+
{{% event event="m.reaction" %}}
38+
39+
#### Client behaviour {id="annotations-client-behaviour"}
40+
41+
The intention of annotations is that they are counted up, rather than being
42+
displayed individually. Clients must keep count of the number of annotations
43+
with a given event `type` and annotation `key` they observe for each event;
44+
these counts are typically presented alongside the event in the timeline.
45+
46+
When performing this count:
47+
48+
* Each event `type` and annotation `key` should normally be counted
49+
separately, though whether to actually do so is an implementation decision.
50+
51+
* Annotation events sent by [ignored users](#ignoring-users) should be
52+
excluded from the count.
53+
54+
* Multiple identical annotations (i.e., with the same event `type` and
55+
annotation `key`) from the same user (i.e., events with the same `sender`)
56+
should be treated as a single annotation.
57+
58+
* Implementations should ignore any annotation event which refers to an event
59+
which itself has an `m.relates_to` with `rel_type: m.annotation` or
60+
`rel_type: m.replace`. In other words, it is not possible to annotate a
61+
[replacement event](#event-replacements) or an annotation.
62+
63+
* When an annotation is redacted, it is removed from the count.
64+
65+
{{% boxes/note %}}
66+
It is not possible to edit a reaction, since replacement events do not change
67+
`m.relates_to` (see [Applying `m.new_content`](#applying-mnew_content)), and
68+
there is no other meaningful content within `m.reaction`. If a user wishes to
69+
change their reaction, the original reaction should be redacted and a new one
70+
sent in its place.
71+
{{% /boxes/note %}}
72+
73+
#### Server behaviour
74+
75+
##### Avoiding duplicate annotations
76+
77+
Homeservers should prevent users from sending a second annotation for a given
78+
event with identical event `type` and annotation `key` (unless the first event
79+
has been redacted).
80+
81+
Attempts to send such an annotation should be rejected with a 400 error and an
82+
error code of `M_DUPLICATE_ANNOTATION`.
83+
84+
Note that this does not guarantee that duplicate annotations will not arrive
85+
over federation. Clients are responsible for deduplicating received
86+
annotations when [counting annotations](#annotations-client-behaviour).
87+
88+
##### Server-side aggregation of `m.annotation` relationships
89+
90+
`m.annotation` relationships are *not* [aggregated](#aggregations) by the
91+
server. In other words, `m.annotation` is not included in the `m.relations`
92+
property.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,31 @@ Definition:
539539
}
540540
```
541541

542+
**<a name="mrulereaction"></a>`.m.rule.reaction`**
543+
544+
{{% added-in v="1.7" %}}
545+
546+
Matches any event whose type is `m.room.reaction`. This suppresses notifications for [`m.reaction`](#mreaction) events.
547+
548+
Definition:
549+
550+
```json
551+
{
552+
"rule_id": ".m.rule.reaction",
553+
"default": true,
554+
"enabled": true,
555+
"conditions": [
556+
{
557+
"kind": "event_match",
558+
"key": "type",
559+
"pattern": "m.reaction"
560+
}
561+
],
562+
"actions": []
563+
}
564+
```
565+
566+
542567
**`.m.rule.room.server_acl`**
543568

544569
{{% added-in v="1.4" %}}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$ref": "core/room_event.json",
3+
"type": "m.reaction",
4+
"content": {
5+
"m.relates_to": {
6+
"rel_type": "m.annotation",
7+
"event_id": "$some_event_id",
8+
"key": "👍"
9+
}
10+
}
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
allOf:
2+
- $ref: core-event-schema/room_event.yaml
3+
description: |-
4+
Indicates a reaction to a previous event.
5+
6+
Has no defined `content` properties of its own. Its only purpose is to hold an
7+
[`m.relates_to`](/client-server-api/#definition-mrelates_to) property.
8+
9+
Since they contain no content other than `m.relates_to`, `m.reaction` events
10+
are normally not encrypted, as there would be no benefit in doing so.
11+
type: object
12+
properties:
13+
content:
14+
type: object
15+
properties:
16+
m.relates_to:
17+
description: |-
18+
Indicates the event being reacted to, and the type of reaction.
19+
type: object
20+
title: ReactionRelatesTo
21+
properties:
22+
rel_type:
23+
type: string
24+
enum: ["m.annotation"]
25+
event_id:
26+
type: string
27+
description: |-
28+
The event ID of the event that this is a reaction to.
29+
example: "$some_event_id"
30+
key:
31+
type: string
32+
description: |-
33+
An emoji representing the reaction being made. Should include the
34+
unicode emoji presentation selector (`\uFE0F`) for codepoints
35+
which allow it (see the [emoji variation sequences
36+
list](https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-variation-sequences.txt)).
37+
example: "👍"

0 commit comments

Comments
 (0)