From 9d1971a5c440fe2bb92ea092d17ac00d37e36466 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Mon, 29 Nov 2021 10:43:20 -0500 Subject: [PATCH] Return the stable `event` field from `/send_join` per MSC3083. (#11413) This does not remove the unstable field and still parses both. Handling of the unstable field will need to be removed in the future. --- .github/workflows/tests.yml | 2 +- changelog.d/11413.bugfix | 1 + scripts-dev/complement.sh | 2 +- synapse/federation/federation_server.py | 5 ++++- synapse/federation/transport/client.py | 13 ++++++++++++- 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 changelog.d/11413.bugfix diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8d7e8cafd..3bee4ee9f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -374,7 +374,7 @@ jobs: working-directory: complement/dockerfiles # Run Complement - - run: go test -v -tags synapse_blacklist,msc2403,msc2946,msc3083 ./tests/... + - run: go test -v -tags synapse_blacklist,msc2403,msc2946 ./tests/... env: COMPLEMENT_BASE_IMAGE: complement-synapse:latest working-directory: complement diff --git a/changelog.d/11413.bugfix b/changelog.d/11413.bugfix new file mode 100644 index 000000000..44111d815 --- /dev/null +++ b/changelog.d/11413.bugfix @@ -0,0 +1 @@ +The `/send_join` response now includes the stable `event` field instead of the unstable field from [MSC3083](https://github.com/matrix-org/matrix-doc/pull/3083). diff --git a/scripts-dev/complement.sh b/scripts-dev/complement.sh index 29568eded..972244f4c 100755 --- a/scripts-dev/complement.sh +++ b/scripts-dev/complement.sh @@ -65,4 +65,4 @@ if [[ -n "$1" ]]; then fi # Run the tests! -go test -v -tags synapse_blacklist,msc2946,msc3083,msc2403 -count=1 $EXTRA_COMPLEMENT_ARGS ./tests/... +go test -v -tags synapse_blacklist,msc2946,msc2403 -count=1 $EXTRA_COMPLEMENT_ARGS ./tests/... diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 9a8758e9a..8fbc75aa6 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -613,8 +613,11 @@ class FederationServer(FederationBase): state = await self.store.get_events(state_ids) time_now = self._clock.time_msec() + event_json = event.get_pdu_json() return { - "org.matrix.msc3083.v2.event": event.get_pdu_json(), + # TODO Remove the unstable prefix when servers have updated. + "org.matrix.msc3083.v2.event": event_json, + "event": event_json, "state": [p.get_pdu_json(time_now) for p in state.values()], "auth_chain": [p.get_pdu_json(time_now) for p in auth_chain], } diff --git a/synapse/federation/transport/client.py b/synapse/federation/transport/client.py index 10b5aa5af..0fea22116 100644 --- a/synapse/federation/transport/client.py +++ b/synapse/federation/transport/client.py @@ -1317,15 +1317,26 @@ class SendJoinParser(ByteParser[SendJoinResponse]): prefix + "auth_chain.item", use_float=True, ) - self._coro_event = ijson.kvitems_coro( + # TODO Remove the unstable prefix when servers have updated. + # + # By re-using the same event dictionary this will cause the parsing of + # org.matrix.msc3083.v2.event and event to stomp over each other. + # Generally this should be fine. + self._coro_unstable_event = ijson.kvitems_coro( _event_parser(self._response.event_dict), prefix + "org.matrix.msc3083.v2.event", use_float=True, ) + self._coro_event = ijson.kvitems_coro( + _event_parser(self._response.event_dict), + prefix + "event", + use_float=True, + ) def write(self, data: bytes) -> int: self._coro_state.send(data) self._coro_auth.send(data) + self._coro_unstable_event.send(data) self._coro_event.send(data) return len(data)