This room version is the first ever version for rooms, and contains the building blocks for other room versions.
Table of Contents
Clients may need to consider some algorithms performed by the server for their own implementation.
Upon receipt of a redaction event, the server must strip off any keys not in the following list:
The content object must also be stripped of all keys, unless it is one of one of the following event types:
Warning
The information contained in this section is strictly for server implementors. Applications which use the Client-Server API are generally unaffected by the intricacies contained here. The section above regarding client considerations is the resource that Client-Server API use cases should reference.
The algorithms defined here should only apply to version 1 rooms. Other algorithms may be used by other room versions, and as such servers should be aware of which version room they are dealing with prior to executing a given algorithm.
Warning
Although room version 1 is the most popular room version, it is known to have undesirable effects. Servers implementing support for room version 1 should be aware that restrictions should be generally relaxed and that inconsistencies may occur until room version 2 (or later) is ready and adopted.
Warning
This section documents the state resolution algorithm as implemented by Synapse as of December 2017 (and therefore the de-facto Matrix protocol). However, this algorithm is known to have some problems.
The room state S’(E) after an event E is defined in terms of the room state S(E) before E, and depends on whether E is a state event or a message event:
The room state S(E) before E is the resolution of the set of states {S’(E’), S’(E’’), …} consisting of the states after each of E's prev_events {E’, E’’, …}.
The resolution of a set of states is defined as follows. The resolved state is built up in a number of passes; here we use R to refer to the results of the resolution so far.
A conflict occurs between states where those states have different event_ids for the same (event_type, state_key). The events thus affected are said to be conflicting events.
The types of state events that affect authorization are:
Note
Power levels are inferred from defaults when not explicitly supplied. For example, mentions of the sender's power level can also refer to the default power level for users in the room.
The rules are as follows:
Note
Some consequences of these rules:
Events in version 1 rooms have the following structure:
A persistent data unit (event) for room versions 1 and 2.
Persistent Data Unit
Parameter | Type | Description |
---|---|---|
room_id | string | Required. Room identifier. |
sender | string | Required. The ID of the user sending the event. |
origin | string | Required. The server_name of the homeserver that created this event. |
origin_server_ts | integer | Required. Timestamp in milliseconds on origin homeserver when this event was created. |
type | string | Required. Event type |
state_key | string | If this key is present, the event is a state event, and it will replace previous events with the same type and state_key in the room state. |
content | object | Required. The content of the event. |
prev_events | [[string, Event Hash]] | Required. Event IDs and reference hashes for the most recent events in the room that the homeserver was aware of when it made this event. Must contain less than or equal to 20 events. |
depth | integer | Required. The maximum depth of the prev_events, plus one. Must be less than the maximum value for an integer (2^63 - 1). If the room's depth is already at the limit, the depth must be set to the limit. |
auth_events | [[string, Event Hash]] | Required. Event IDs and reference hashes for the authorization events that would allow this event to be in the room. Must contain less than or equal to 10 events. Note that if the relevant auth event selection rules are used, this restriction should never be encountered. |
redacts | string | For redaction events, the ID of the event being redacted. |
unsigned | UnsignedData | Additional data added by the origin server but not covered by the signatures. More keys than those defined here may be used. |
event_id | string | Required. The event ID for the PDU. |
hashes | Event Hash | Required. Content hashes of the PDU, following the algorithm specified in Signing Events. |
signatures | {string: Server Signatures} | Required. Signatures for the PDU, following the algorithm specified in Signing Events. |
UnsignedData
Parameter | Type | Description |
---|---|---|
age | integer | The number of milliseconds that have passed since this message was sent. |
replaces_state | string | The event ID of the state event this event replaces. |
prev_sender | string | The sender of the replaced state event. |
prev_content | object | The content of the replaced state event. |
redacted_because | string | A reason for why the event was redacted. |
Event Hash
Parameter | Type | Description |
---|---|---|
sha256 | string | Required. The hash. |
Example:
{ "auth_events": [ [ "$abc123:matrix.org", { "sha256": "Base64EncodedSha256HashesShouldBe43BytesLong" } ] ], "content": { "key": "value" }, "depth": 12, "event_id": "$a4ecee13e2accdadf56c1025:example.com", "hashes": { "sha256": "ThisHashCoversAllFieldsInCaseThisIsRedacted" }, "origin": "matrix.org", "origin_server_ts": 1234567890, "prev_events": [ [ "$abc123:matrix.org", { "sha256": "Base64EncodedSha256HashesShouldBe43BytesLong" } ] ], "redacts": "$def456:matrix.org", "room_id": "!abc123:matrix.org", "sender": "@someone:matrix.org", "signatures": { "example.com": { "ed25519:key_version:": "86BytesOfSignatureOfTheRedactedEvent" } }, "state_key": "my_key", "type": "m.room.message", "unsigned": { "key": "value" } }
Servers MUST NOT strictly enforce the JSON format specified in the appendices for the reasons described there.