Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Refactor state module to support multiple room versions #3673

Merged
merged 9 commits into from
Aug 22, 2018
1 change: 1 addition & 0 deletions changelog.d/3673.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor state module to support multiple room versions
9 changes: 7 additions & 2 deletions synapse/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ class ThirdPartyEntityKind(object):
LOCATION = "location"


class RoomVersions(object):
V1 = "1"
VDH_TEST = "vdh-test-version"


# the version we will give rooms which are created on this server
DEFAULT_ROOM_VERSION = "1"
DEFAULT_ROOM_VERSION = RoomVersions.V1

# vdh-test-version is a placeholder to get room versioning support working and tested
# until we have a working v2.
KNOWN_ROOM_VERSIONS = {"1", "vdh-test-version"}
KNOWN_ROOM_VERSIONS = {RoomVersions.V1, RoomVersions.VDH_TEST}
8 changes: 6 additions & 2 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ def fetch(ev_ids):
ev_ids, get_prev_content=False, check_redacted=False
)

room_version = yield self.store.get_room_version(pdu.room_id)
state_map = yield resolve_events_with_factory(
state_groups, {pdu.event_id: pdu}, fetch
room_version, state_groups, {pdu.event_id: pdu}, fetch
)

state = (yield self.store.get_events(state_map.values())).values()
Expand Down Expand Up @@ -1811,7 +1812,10 @@ def do_auth(self, origin, event, context, auth_events):
(d.type, d.state_key): d for d in different_events if d
})

new_state = self.state_handler.resolve_events(
room_version = yield self.store.get_room_version(event.room_id)

new_state = yield self.state_handler.resolve_events(
room_version,
[list(local_view.values()), list(remote_view.values())],
event
)
Expand Down
5 changes: 3 additions & 2 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ def _update_membership(
prev_events_and_hashes = yield self.store.get_prev_events_for_room(
room_id,
)
latest_event_ids = (
latest_event_ids = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this changing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this used to be a required change but no longer. Will change it back for simplicity of PR

event_id for (event_id, _, _) in prev_events_and_hashes
)
]

current_state_ids = yield self.state_handler.get_current_state_ids(
room_id, latest_event_ids=latest_event_ids,
)
Expand Down
Loading