libQuotient icon indicating copy to clipboard operation
libQuotient copied to clipboard

Event class cannot depend on room version

Open KitsuneRal opened this issue 5 years ago • 0 comments

Mass redactions MSC introduces a different data structure used for a redaction event in a newer room version. While this data structure is back-compatible with the current one so it's possible to make an all-consuming RedactionEvent with no regard to room versions, it's not possible to use EventFactory to create events of the type depending on the room version in order to implement the MSC in a strict way. Such implementation would only create single-id redaction events (say, RedactionEventV1) for older room versions, while newer room versions would get events with the data structure introduced by the MSC (say, RedactionEventV2).

The biggest problem here is that the current library architecture does not expect event classes to depend on room versions: basically, all event parsing is triggered from SyncJob and Room only incorporates those events into the state or into the timeline - which is not quite correct from the Matrix design standpoint, as different room versions may apply different game rules to events and their format in particular. The right way would probably be if SyncJob delivers a JSON list of unparsed room data; and Room::updateData triggers actual creation of event objects, parameterising EventFactory with the room version. Removing the no more needed SyncRoomData middle-man would slightly optimise sync parsing times (already pretty small compared to the time spent in Room::updateData though).

It's a move away from a dream where SyncJob is auto-generated from CS API YAML; but that's not so much of an issue. Slightly more serious is a Catch-22 due to the room version itself being supplied in a room event; so as the first step of the very first sync parsing for a given room, Room (or even Connection::createRoom? It might be desirable to create different room classes depending on the room version) should dive down into the received JSON, find a piece that corresponds to the m.room.create state event and get the room version out of it.

KitsuneRal avatar Nov 22 '19 07:11 KitsuneRal