-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Include event_id when /state/:type[/:key]?format=event #15454
Description
Problem
Currently when you GET /_matrix/client/v3/rooms/{room_id}/state/m.room.create?format=event (notice the event format), it doesn't include event_id which is kinda annoying to work with and reference.
Example:
{
"content": {
"creator": "@foo:bar",
"room_version": "6"
},
"origin_server_ts": 1606978812896,
"room_id": "!abc",
"sender": "@foo:bar",
"state_key": "",
"type": "m.room.create",
"unsigned": {
"age_ts": 1606978812896
}
}Proposal
Add event_id to the output. There is no spec to go off of but seems like a non-breaking change we can do.
Spawning from a need in matrix-org/matrix-viewer#167 to get the event_id of the m.room.create event in the room.
Is there a better way to do this? Perhaps /_matrix/client/v3/rooms/{room_id}/messages?dir=f&limit=1
Dev notes
- Relevant spec issue for the
?formatquery parameter: Spec?format=event|contentonGET /state/:type[/:key]matrix-spec#1047 ?formatintroduced to Synapse in Allow clients to ask for the whole of a single state event #1094
Relevant code:
synapse/synapse/rest/client/room.py
Lines 258 to 262 in d935b80
| if format == "event": | |
| event = format_event_for_client_v2(data.get_dict()) | |
| return 200, event | |
| elif format == "content": | |
| return 200, data.get_dict()["content"] |
Currently, we use format_event_for_client_v2(data.get_dict()) against the EventBase PDU JSON dictionary which doesn't include event_id. We could instead use serialize_event(data, self.clock.time_msec()) which would get us something more workable.
We could also alternatively, add event_id to the dictionary returned by EventBase.get_dict() but that probably has too many downstream side-effects like messing with the PDU JSON serialization stuff.
synapse/synapse/events/__init__.py
Lines 362 to 366 in d935b80
| def get_dict(self) -> JsonDict: | |
| d = dict(self._dict) | |
| d.update({"signatures": self.signatures, "unsigned": dict(self.unsigned)}) | |
| return d |
Separately, it would be good to standardize with the ?event_format=client|federation parameter used with other endpoints