|
| 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. |
0 commit comments