From 18c11968937c8313e363d2dc1cae38435af137a6 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 4 Jun 2024 09:46:09 +0100 Subject: [PATCH 1/4] 1.109.0rc1 --- CHANGES.md | 54 +++++++++++++++++++++++++++++++++++++++ changelog.d/17083.misc | 1 - changelog.d/17147.feature | 1 - changelog.d/17164.bugfix | 1 - changelog.d/17167.feature | 1 - changelog.d/17176.misc | 1 - changelog.d/17204.doc | 1 - changelog.d/17211.misc | 1 - changelog.d/17213.feature | 1 - changelog.d/17215.bugfix | 1 - changelog.d/17216.misc | 1 - changelog.d/17219.feature | 1 - changelog.d/17226.misc | 1 - changelog.d/17229.misc | 1 - changelog.d/17238.misc | 1 - changelog.d/17239.misc | 1 - changelog.d/17240.bugfix | 1 - changelog.d/17241.bugfix | 1 - changelog.d/17242.misc | 1 - changelog.d/17246.misc | 1 - changelog.d/17250.misc | 1 - changelog.d/17251.bugfix | 1 - changelog.d/17252.bugfix | 1 - debian/changelog | 6 +++++ pyproject.toml | 2 +- 25 files changed, 61 insertions(+), 23 deletions(-) delete mode 100644 changelog.d/17083.misc delete mode 100644 changelog.d/17147.feature delete mode 100644 changelog.d/17164.bugfix delete mode 100644 changelog.d/17167.feature delete mode 100644 changelog.d/17176.misc delete mode 100644 changelog.d/17204.doc delete mode 100644 changelog.d/17211.misc delete mode 100644 changelog.d/17213.feature delete mode 100644 changelog.d/17215.bugfix delete mode 100644 changelog.d/17216.misc delete mode 100644 changelog.d/17219.feature delete mode 100644 changelog.d/17226.misc delete mode 100644 changelog.d/17229.misc delete mode 100644 changelog.d/17238.misc delete mode 100644 changelog.d/17239.misc delete mode 100644 changelog.d/17240.bugfix delete mode 100644 changelog.d/17241.bugfix delete mode 100644 changelog.d/17242.misc delete mode 100644 changelog.d/17246.misc delete mode 100644 changelog.d/17250.misc delete mode 100644 changelog.d/17251.bugfix delete mode 100644 changelog.d/17252.bugfix diff --git a/CHANGES.md b/CHANGES.md index d517fc4eff..0c61183d6b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,57 @@ +# Synapse 1.109.0rc1 (2024-06-04) + +### Features + +- Add the ability to auto-accept invites on the behalf of users. See the [`auto_accept_invites`](https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html#auto-accept-invites) config option for details. ([\#17147](https://github.com/element-hq/synapse/issues/17147)) +- Add experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync/e2ee` endpoint for to-device messages and device encryption info. ([\#17167](https://github.com/element-hq/synapse/issues/17167)) +- Support [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/issues/3916) by adding unstable media endpoints to `/_matrix/client` (#17213). ([\#17213](https://github.com/element-hq/synapse/issues/17213)) +- Add logging to tasks managed by the task scheduler, showing CPU and database usage. ([\#17219](https://github.com/element-hq/synapse/issues/17219)) + +### Bugfixes + +- Fix deduplicating of membership events to not create unused state groups. ([\#17164](https://github.com/element-hq/synapse/issues/17164)) +- Fix bug where duplicate events could be sent down sync when using workers that are overloaded. ([\#17215](https://github.com/element-hq/synapse/issues/17215)) +- Ignore attempts to send to-device messages to bad users, to avoid log spam when we try to connect to the bad server. ([\#17240](https://github.com/element-hq/synapse/issues/17240)) +- Fix handling of duplicate concurrent uploading of device one-time-keys. ([\#17241](https://github.com/element-hq/synapse/issues/17241)) +- Fix reporting of default tags to Sentry, such as worker name. Broke in v1.108.0. ([\#17251](https://github.com/element-hq/synapse/issues/17251)) +- Fix bug where typing updates would not be sent when using workers after a restart. ([\#17252](https://github.com/element-hq/synapse/issues/17252)) + +### Improved Documentation + +- Update the LemonLDAP documentation to say that claims should be explicitly included in the returned `id_token`, as Synapse won't request them. ([\#17204](https://github.com/element-hq/synapse/issues/17204)) + +### Internal Changes + +- Improve DB usage when fetching related events. ([\#17083](https://github.com/element-hq/synapse/issues/17083)) +- Log exceptions when failing to auto-join new user according to the `auto_join_rooms` option. ([\#17176](https://github.com/element-hq/synapse/issues/17176)) +- Reduce work of calculating outbound device lists updates. ([\#17211](https://github.com/element-hq/synapse/issues/17211)) +- Improve performance of calculating device lists changes in `/sync`. ([\#17216](https://github.com/element-hq/synapse/issues/17216)) +- Move towards using `MultiWriterIdGenerator` everywhere. ([\#17226](https://github.com/element-hq/synapse/issues/17226)) +- Replaces all usages of `StreamIdGenerator` with `MultiWriterIdGenerator`. ([\#17229](https://github.com/element-hq/synapse/issues/17229)) +- Change the `allow_unsafe_locale` config option to also apply when setting up new databases. ([\#17238](https://github.com/element-hq/synapse/issues/17238)) +- Fix errors in logs about closing incorrect logging contexts when media gets rejected by a module. ([\#17239](https://github.com/element-hq/synapse/issues/17239), [\#17246](https://github.com/element-hq/synapse/issues/17246)) +- Clean out invalid destinations from `device_federation_outbox` table. ([\#17242](https://github.com/element-hq/synapse/issues/17242)) +- Stop logging errors when receiving invalid User IDs in key querys requests. ([\#17250](https://github.com/element-hq/synapse/issues/17250)) + + + +### Updates to locked dependencies + +* Bump anyhow from 1.0.83 to 1.0.86. ([\#17220](https://github.com/element-hq/synapse/issues/17220)) +* Bump bcrypt from 4.1.2 to 4.1.3. ([\#17224](https://github.com/element-hq/synapse/issues/17224)) +* Bump lxml from 5.2.1 to 5.2.2. ([\#17261](https://github.com/element-hq/synapse/issues/17261)) +* Bump mypy-zope from 1.0.3 to 1.0.4. ([\#17262](https://github.com/element-hq/synapse/issues/17262)) +* Bump phonenumbers from 8.13.35 to 8.13.37. ([\#17235](https://github.com/element-hq/synapse/issues/17235)) +* Bump prometheus-client from 0.19.0 to 0.20.0. ([\#17233](https://github.com/element-hq/synapse/issues/17233)) +* Bump pyasn1 from 0.5.1 to 0.6.0. ([\#17223](https://github.com/element-hq/synapse/issues/17223)) +* Bump pyicu from 2.13 to 2.13.1. ([\#17236](https://github.com/element-hq/synapse/issues/17236)) +* Bump pyopenssl from 24.0.0 to 24.1.0. ([\#17234](https://github.com/element-hq/synapse/issues/17234)) +* Bump serde from 1.0.201 to 1.0.202. ([\#17221](https://github.com/element-hq/synapse/issues/17221)) +* Bump serde from 1.0.202 to 1.0.203. ([\#17232](https://github.com/element-hq/synapse/issues/17232)) +* Bump twine from 5.0.0 to 5.1.0. ([\#17225](https://github.com/element-hq/synapse/issues/17225)) +* Bump types-psycopg2 from 2.9.21.20240311 to 2.9.21.20240417. ([\#17222](https://github.com/element-hq/synapse/issues/17222)) +* Bump types-pyopenssl from 24.0.0.20240311 to 24.1.0.20240425. ([\#17260](https://github.com/element-hq/synapse/issues/17260)) + # Synapse 1.108.0 (2024-05-28) No significant changes since 1.108.0rc1. diff --git a/changelog.d/17083.misc b/changelog.d/17083.misc deleted file mode 100644 index 7c7cebea4e..0000000000 --- a/changelog.d/17083.misc +++ /dev/null @@ -1 +0,0 @@ -Improve DB usage when fetching related events. diff --git a/changelog.d/17147.feature b/changelog.d/17147.feature deleted file mode 100644 index 7c2cdb6bdf..0000000000 --- a/changelog.d/17147.feature +++ /dev/null @@ -1 +0,0 @@ -Add the ability to auto-accept invites on the behalf of users. See the [`auto_accept_invites`](https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html#auto-accept-invites) config option for details. diff --git a/changelog.d/17164.bugfix b/changelog.d/17164.bugfix deleted file mode 100644 index 597e2f14b0..0000000000 --- a/changelog.d/17164.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix deduplicating of membership events to not create unused state groups. diff --git a/changelog.d/17167.feature b/changelog.d/17167.feature deleted file mode 100644 index 5ad31db974..0000000000 --- a/changelog.d/17167.feature +++ /dev/null @@ -1 +0,0 @@ -Add experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync/e2ee` endpoint for To-Device messages and device encryption info. diff --git a/changelog.d/17176.misc b/changelog.d/17176.misc deleted file mode 100644 index cc9f2a5202..0000000000 --- a/changelog.d/17176.misc +++ /dev/null @@ -1 +0,0 @@ -Log exceptions when failing to auto-join new user according to the `auto_join_rooms` option. \ No newline at end of file diff --git a/changelog.d/17204.doc b/changelog.d/17204.doc deleted file mode 100644 index 5a5a8f5107..0000000000 --- a/changelog.d/17204.doc +++ /dev/null @@ -1 +0,0 @@ -Update OIDC documentation: by default Matrix doesn't query userinfo endpoint, then claims should be put on id_token. diff --git a/changelog.d/17211.misc b/changelog.d/17211.misc deleted file mode 100644 index 144db03a40..0000000000 --- a/changelog.d/17211.misc +++ /dev/null @@ -1 +0,0 @@ -Reduce work of calculating outbound device lists updates. diff --git a/changelog.d/17213.feature b/changelog.d/17213.feature deleted file mode 100644 index ca60afa8f3..0000000000 --- a/changelog.d/17213.feature +++ /dev/null @@ -1 +0,0 @@ -Support MSC3916 by adding unstable media endpoints to `_matrix/client` (#17213). \ No newline at end of file diff --git a/changelog.d/17215.bugfix b/changelog.d/17215.bugfix deleted file mode 100644 index 10981b798e..0000000000 --- a/changelog.d/17215.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix bug where duplicate events could be sent down sync when using workers that are overloaded. diff --git a/changelog.d/17216.misc b/changelog.d/17216.misc deleted file mode 100644 index bd55eeaa33..0000000000 --- a/changelog.d/17216.misc +++ /dev/null @@ -1 +0,0 @@ -Improve performance of calculating device lists changes in `/sync`. diff --git a/changelog.d/17219.feature b/changelog.d/17219.feature deleted file mode 100644 index f8277a89d8..0000000000 --- a/changelog.d/17219.feature +++ /dev/null @@ -1 +0,0 @@ -Add logging to tasks managed by the task scheduler, showing CPU and database usage. \ No newline at end of file diff --git a/changelog.d/17226.misc b/changelog.d/17226.misc deleted file mode 100644 index 7c023a5759..0000000000 --- a/changelog.d/17226.misc +++ /dev/null @@ -1 +0,0 @@ -Move towards using `MultiWriterIdGenerator` everywhere. diff --git a/changelog.d/17229.misc b/changelog.d/17229.misc deleted file mode 100644 index d411550786..0000000000 --- a/changelog.d/17229.misc +++ /dev/null @@ -1 +0,0 @@ -Replaces all usages of `StreamIdGenerator` with `MultiWriterIdGenerator`. diff --git a/changelog.d/17238.misc b/changelog.d/17238.misc deleted file mode 100644 index 261467e55c..0000000000 --- a/changelog.d/17238.misc +++ /dev/null @@ -1 +0,0 @@ -Change the `allow_unsafe_locale` config option to also apply when setting up new databases. diff --git a/changelog.d/17239.misc b/changelog.d/17239.misc deleted file mode 100644 index 9fca36bb29..0000000000 --- a/changelog.d/17239.misc +++ /dev/null @@ -1 +0,0 @@ -Fix errors in logs about closing incorrect logging contexts when media gets rejected by a module. diff --git a/changelog.d/17240.bugfix b/changelog.d/17240.bugfix deleted file mode 100644 index c596d270ce..0000000000 --- a/changelog.d/17240.bugfix +++ /dev/null @@ -1 +0,0 @@ -Ignore attempts to send to-device messages to bad users, to avoid log spam when we try to connect to the bad server. diff --git a/changelog.d/17241.bugfix b/changelog.d/17241.bugfix deleted file mode 100644 index 1b7f0bca94..0000000000 --- a/changelog.d/17241.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix handling of duplicate concurrent uploading of device one-time-keys. diff --git a/changelog.d/17242.misc b/changelog.d/17242.misc deleted file mode 100644 index 5bd627da57..0000000000 --- a/changelog.d/17242.misc +++ /dev/null @@ -1 +0,0 @@ -Clean out invalid destinations from `device_federation_outbox` table. diff --git a/changelog.d/17246.misc b/changelog.d/17246.misc deleted file mode 100644 index 9fca36bb29..0000000000 --- a/changelog.d/17246.misc +++ /dev/null @@ -1 +0,0 @@ -Fix errors in logs about closing incorrect logging contexts when media gets rejected by a module. diff --git a/changelog.d/17250.misc b/changelog.d/17250.misc deleted file mode 100644 index 49834e83ba..0000000000 --- a/changelog.d/17250.misc +++ /dev/null @@ -1 +0,0 @@ -Stop logging errors when receiving invalid User IDs in key querys requests. diff --git a/changelog.d/17251.bugfix b/changelog.d/17251.bugfix deleted file mode 100644 index f573e01e87..0000000000 --- a/changelog.d/17251.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix reporting of default tags to Sentry, such as worker name. Broke in v1.108.0. diff --git a/changelog.d/17252.bugfix b/changelog.d/17252.bugfix deleted file mode 100644 index f3289d1568..0000000000 --- a/changelog.d/17252.bugfix +++ /dev/null @@ -1 +0,0 @@ -Fix bug where typing updates would not be sent when using workers after a restart. diff --git a/debian/changelog b/debian/changelog index 8491b587e8..927248bdab 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +matrix-synapse-py3 (1.109.0~rc1) stable; urgency=medium + + * New Synapse release 1.109.0rc1. + + -- Synapse Packaging team Tue, 04 Jun 2024 09:42:46 +0100 + matrix-synapse-py3 (1.108.0) stable; urgency=medium * New Synapse release 1.108.0. diff --git a/pyproject.toml b/pyproject.toml index 9a3348be49..8cc99b8cba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,7 +96,7 @@ module-name = "synapse.synapse_rust" [tool.poetry] name = "matrix-synapse" -version = "1.108.0" +version = "1.109.0rc1" description = "Homeserver for the Matrix decentralised comms protocol" authors = ["Matrix.org Team and Contributors "] license = "AGPL-3.0-or-later" From e2f8476044ef1e694e8e25c2ccb60711e65d518a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 4 Jun 2024 09:47:28 +0100 Subject: [PATCH 2/4] Fix typo in CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 0c61183d6b..092dbdbf2d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,7 +4,7 @@ - Add the ability to auto-accept invites on the behalf of users. See the [`auto_accept_invites`](https://element-hq.github.io/synapse/latest/usage/configuration/config_documentation.html#auto-accept-invites) config option for details. ([\#17147](https://github.com/element-hq/synapse/issues/17147)) - Add experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync/e2ee` endpoint for to-device messages and device encryption info. ([\#17167](https://github.com/element-hq/synapse/issues/17167)) -- Support [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/issues/3916) by adding unstable media endpoints to `/_matrix/client` (#17213). ([\#17213](https://github.com/element-hq/synapse/issues/17213)) +- Support [MSC3916](https://github.com/matrix-org/matrix-spec-proposals/issues/3916) by adding unstable media endpoints to `/_matrix/client`. ([\#17213](https://github.com/element-hq/synapse/issues/17213)) - Add logging to tasks managed by the task scheduler, showing CPU and database usage. ([\#17219](https://github.com/element-hq/synapse/issues/17219)) ### Bugfixes From 81cef38d4b47776d776577560421795afce85ca1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 4 Jun 2024 11:58:27 +0100 Subject: [PATCH 3/4] Bump sentry-sdk from 2.1.1 to 2.3.1 (#17263) --- poetry.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index 80924ccbb1..942e26701d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2387,13 +2387,13 @@ doc = ["Sphinx", "sphinx-rtd-theme"] [[package]] name = "sentry-sdk" -version = "2.1.1" +version = "2.3.1" description = "Python client for Sentry (https://sentry.io)" optional = true python-versions = ">=3.6" files = [ - {file = "sentry_sdk-2.1.1-py2.py3-none-any.whl", hash = "sha256:99aeb78fb76771513bd3b2829d12613130152620768d00cd3e45ac00cb17950f"}, - {file = "sentry_sdk-2.1.1.tar.gz", hash = "sha256:95d8c0bb41c8b0bc37ab202c2c4a295bb84398ee05f4cdce55051cd75b926ec1"}, + {file = "sentry_sdk-2.3.1-py2.py3-none-any.whl", hash = "sha256:c5aeb095ba226391d337dd42a6f9470d86c9fc236ecc71cfc7cd1942b45010c6"}, + {file = "sentry_sdk-2.3.1.tar.gz", hash = "sha256:139a71a19f5e9eb5d3623942491ce03cf8ebc14ea2e39ba3e6fe79560d8a5b1f"}, ] [package.dependencies] @@ -2415,7 +2415,7 @@ django = ["django (>=1.8)"] falcon = ["falcon (>=1.4)"] fastapi = ["fastapi (>=0.79.0)"] flask = ["blinker (>=1.1)", "flask (>=0.11)", "markupsafe"] -grpcio = ["grpcio (>=1.21.1)"] +grpcio = ["grpcio (>=1.21.1)", "protobuf (>=3.8.0)"] httpx = ["httpx (>=0.16.0)"] huey = ["huey (>=2)"] huggingface-hub = ["huggingface-hub (>=0.22)"] From 7d8f0ef351e99adf602b3acb67b2516a02ff6918 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 4 Jun 2024 12:58:03 -0500 Subject: [PATCH 4/4] Use fully-qualified `PersistedEventPosition` when returning `RoomsForUser` (#17265) Use fully-qualified `PersistedEventPosition` (`instance_name` and `stream_ordering`) when returning `RoomsForUser` to facilitate proper comparisons and `RoomStreamToken` generation. Spawning from https://github.com/element-hq/synapse/pull/17187 where we want to utilize this change --- changelog.d/17265.misc | 1 + synapse/federation/federation_server.py | 4 +- synapse/handlers/admin.py | 10 +--- synapse/handlers/initial_sync.py | 2 +- synapse/handlers/pagination.py | 3 +- synapse/handlers/room.py | 60 +------------------- synapse/handlers/sync.py | 2 +- synapse/storage/databases/main/roommember.py | 14 ++++- synapse/storage/roommember.py | 2 +- synapse/types/__init__.py | 57 +++++++++++++++++++ tests/replication/storage/test_events.py | 5 +- 11 files changed, 85 insertions(+), 75 deletions(-) create mode 100644 changelog.d/17265.misc diff --git a/changelog.d/17265.misc b/changelog.d/17265.misc new file mode 100644 index 0000000000..e6d4d8b4ee --- /dev/null +++ b/changelog.d/17265.misc @@ -0,0 +1 @@ +Use fully-qualified `PersistedEventPosition` when returning `RoomsForUser` to facilitate proper comparisons and `RoomStreamToken` generation. diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index 7ffc650aa1..1932fa82a4 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -674,7 +674,7 @@ class FederationServer(FederationBase): # This is in addition to the HS-level rate limiting applied by # BaseFederationServlet. # type-ignore: mypy doesn't seem able to deduce the type of the limiter(!?) - await self._room_member_handler._join_rate_per_room_limiter.ratelimit( # type: ignore[has-type] + await self._room_member_handler._join_rate_per_room_limiter.ratelimit( requester=None, key=room_id, update=False, @@ -717,7 +717,7 @@ class FederationServer(FederationBase): SynapseTags.SEND_JOIN_RESPONSE_IS_PARTIAL_STATE, caller_supports_partial_state, ) - await self._room_member_handler._join_rate_per_room_limiter.ratelimit( # type: ignore[has-type] + await self._room_member_handler._join_rate_per_room_limiter.ratelimit( requester=None, key=room_id, update=False, diff --git a/synapse/handlers/admin.py b/synapse/handlers/admin.py index 702d40332c..21d3bb37f3 100644 --- a/synapse/handlers/admin.py +++ b/synapse/handlers/admin.py @@ -126,13 +126,7 @@ class AdminHandler: # Get all rooms the user is in or has been in rooms = await self._store.get_rooms_for_local_user_where_membership_is( user_id, - membership_list=( - Membership.JOIN, - Membership.LEAVE, - Membership.BAN, - Membership.INVITE, - Membership.KNOCK, - ), + membership_list=Membership.LIST, ) # We only try and fetch events for rooms the user has been in. If @@ -179,7 +173,7 @@ class AdminHandler: if room.membership == Membership.JOIN: stream_ordering = self._store.get_room_max_stream_ordering() else: - stream_ordering = room.stream_ordering + stream_ordering = room.event_pos.stream from_key = RoomStreamToken(topological=0, stream=0) to_key = RoomStreamToken(stream=stream_ordering) diff --git a/synapse/handlers/initial_sync.py b/synapse/handlers/initial_sync.py index d99fc4bec0..84d6fecf31 100644 --- a/synapse/handlers/initial_sync.py +++ b/synapse/handlers/initial_sync.py @@ -199,7 +199,7 @@ class InitialSyncHandler: ) elif event.membership == Membership.LEAVE: room_end_token = RoomStreamToken( - stream=event.stream_ordering, + stream=event.event_pos.stream, ) deferred_room_state = run_in_background( self._state_storage_controller.get_state_for_events, diff --git a/synapse/handlers/pagination.py b/synapse/handlers/pagination.py index 6617105cdb..f7447b8ba5 100644 --- a/synapse/handlers/pagination.py +++ b/synapse/handlers/pagination.py @@ -27,7 +27,6 @@ from synapse.api.constants import Direction, EventTypes, Membership from synapse.api.errors import SynapseError from synapse.api.filtering import Filter from synapse.events.utils import SerializeEventConfig -from synapse.handlers.room import ShutdownRoomParams, ShutdownRoomResponse from synapse.handlers.worker_lock import NEW_EVENT_DURING_PURGE_LOCK_NAME from synapse.logging.opentracing import trace from synapse.metrics.background_process_metrics import run_as_background_process @@ -38,6 +37,8 @@ from synapse.types import ( JsonMapping, Requester, ScheduledTask, + ShutdownRoomParams, + ShutdownRoomResponse, StreamKeyType, TaskStatus, ) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 51739a2653..7f1b674d10 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -40,7 +40,6 @@ from typing import ( ) import attr -from typing_extensions import TypedDict import synapse.events.snapshot from synapse.api.constants import ( @@ -81,6 +80,8 @@ from synapse.types import ( RoomAlias, RoomID, RoomStreamToken, + ShutdownRoomParams, + ShutdownRoomResponse, StateMap, StrCollection, StreamKeyType, @@ -1780,63 +1781,6 @@ class RoomEventSource(EventSource[RoomStreamToken, EventBase]): return self.store.get_current_room_stream_token_for_room_id(room_id) -class ShutdownRoomParams(TypedDict): - """ - Attributes: - requester_user_id: - User who requested the action. Will be recorded as putting the room on the - blocking list. - new_room_user_id: - If set, a new room will be created with this user ID - as the creator and admin, and all users in the old room will be - moved into that room. If not set, no new room will be created - and the users will just be removed from the old room. - new_room_name: - A string representing the name of the room that new users will - be invited to. Defaults to `Content Violation Notification` - message: - A string containing the first message that will be sent as - `new_room_user_id` in the new room. Ideally this will clearly - convey why the original room was shut down. - Defaults to `Sharing illegal content on this server is not - permitted and rooms in violation will be blocked.` - block: - If set to `true`, this room will be added to a blocking list, - preventing future attempts to join the room. Defaults to `false`. - purge: - If set to `true`, purge the given room from the database. - force_purge: - If set to `true`, the room will be purged from database - even if there are still users joined to the room. - """ - - requester_user_id: Optional[str] - new_room_user_id: Optional[str] - new_room_name: Optional[str] - message: Optional[str] - block: bool - purge: bool - force_purge: bool - - -class ShutdownRoomResponse(TypedDict): - """ - Attributes: - kicked_users: An array of users (`user_id`) that were kicked. - failed_to_kick_users: - An array of users (`user_id`) that that were not kicked. - local_aliases: - An array of strings representing the local aliases that were - migrated from the old room to the new. - new_room_id: A string representing the room ID of the new room. - """ - - kicked_users: List[str] - failed_to_kick_users: List[str] - local_aliases: List[str] - new_room_id: Optional[str] - - class RoomShutdownHandler: DEFAULT_MESSAGE = ( "Sharing illegal content on this server is not permitted and rooms in" diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 1d7d9dfdd0..e815e0ea7f 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -2805,7 +2805,7 @@ class SyncHandler: continue leave_token = now_token.copy_and_replace( - StreamKeyType.ROOM, RoomStreamToken(stream=event.stream_ordering) + StreamKeyType.ROOM, RoomStreamToken(stream=event.event_pos.stream) ) room_entries.append( RoomSyncResultBuilder( diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 9fddbb2caf..d8b54dc4e3 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -476,7 +476,7 @@ class RoomMemberWorkerStore(EventsWorkerStore, CacheInvalidationWorkerStore): ) sql = """ - SELECT room_id, e.sender, c.membership, event_id, e.stream_ordering, r.room_version + SELECT room_id, e.sender, c.membership, event_id, e.instance_name, e.stream_ordering, r.room_version FROM local_current_membership AS c INNER JOIN events AS e USING (room_id, event_id) INNER JOIN rooms AS r USING (room_id) @@ -488,7 +488,17 @@ class RoomMemberWorkerStore(EventsWorkerStore, CacheInvalidationWorkerStore): ) txn.execute(sql, (user_id, *args)) - results = [RoomsForUser(*r) for r in txn] + results = [ + RoomsForUser( + room_id=room_id, + sender=sender, + membership=membership, + event_id=event_id, + event_pos=PersistedEventPosition(instance_name, stream_ordering), + room_version_id=room_version, + ) + for room_id, sender, membership, event_id, instance_name, stream_ordering, room_version in txn + ] return results diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index 7471f81a19..80c9630867 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -35,7 +35,7 @@ class RoomsForUser: sender: str membership: str event_id: str - stream_ordering: int + event_pos: PersistedEventPosition room_version_id: str diff --git a/synapse/types/__init__.py b/synapse/types/__init__.py index 151658df53..3a89787cab 100644 --- a/synapse/types/__init__.py +++ b/synapse/types/__init__.py @@ -1279,3 +1279,60 @@ class ScheduledTask: result: Optional[JsonMapping] # Optional error that should be assigned a value when the status is FAILED error: Optional[str] + + +class ShutdownRoomParams(TypedDict): + """ + Attributes: + requester_user_id: + User who requested the action. Will be recorded as putting the room on the + blocking list. + new_room_user_id: + If set, a new room will be created with this user ID + as the creator and admin, and all users in the old room will be + moved into that room. If not set, no new room will be created + and the users will just be removed from the old room. + new_room_name: + A string representing the name of the room that new users will + be invited to. Defaults to `Content Violation Notification` + message: + A string containing the first message that will be sent as + `new_room_user_id` in the new room. Ideally this will clearly + convey why the original room was shut down. + Defaults to `Sharing illegal content on this server is not + permitted and rooms in violation will be blocked.` + block: + If set to `true`, this room will be added to a blocking list, + preventing future attempts to join the room. Defaults to `false`. + purge: + If set to `true`, purge the given room from the database. + force_purge: + If set to `true`, the room will be purged from database + even if there are still users joined to the room. + """ + + requester_user_id: Optional[str] + new_room_user_id: Optional[str] + new_room_name: Optional[str] + message: Optional[str] + block: bool + purge: bool + force_purge: bool + + +class ShutdownRoomResponse(TypedDict): + """ + Attributes: + kicked_users: An array of users (`user_id`) that were kicked. + failed_to_kick_users: + An array of users (`user_id`) that that were not kicked. + local_aliases: + An array of strings representing the local aliases that were + migrated from the old room to the new. + new_room_id: A string representing the room ID of the new room. + """ + + kicked_users: List[str] + failed_to_kick_users: List[str] + local_aliases: List[str] + new_room_id: Optional[str] diff --git a/tests/replication/storage/test_events.py b/tests/replication/storage/test_events.py index 86c8f14d1b..4e41a1c912 100644 --- a/tests/replication/storage/test_events.py +++ b/tests/replication/storage/test_events.py @@ -154,7 +154,10 @@ class EventsWorkerStoreTestCase(BaseWorkerStoreTestCase): USER_ID, "invite", event.event_id, - event.internal_metadata.stream_ordering, + PersistedEventPosition( + self.hs.get_instance_name(), + event.internal_metadata.stream_ordering, + ), RoomVersions.V1.identifier, ) ],