Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return some room data in Sliding Sync /sync #17320

Merged
merged 75 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
079194c
Return some room timeline data in Sliding Sync
MadLittleMods Jun 17, 2024
3e0f759
Strip invite/knock event itself and avoid mutating event `unsigned`
MadLittleMods Jun 17, 2024
5e2fd4e
Add changelog
MadLittleMods Jun 17, 2024
8ce06f1
Fix sort being lost
MadLittleMods Jun 17, 2024
aa5f54a
Start on required_state
MadLittleMods Jun 18, 2024
5c175d5
Add some notes from pairing
MadLittleMods Jun 18, 2024
9089bfe
Remove required_state for now
MadLittleMods Jun 18, 2024
9427991
Clean up knock_state comments
MadLittleMods Jun 18, 2024
19b2297
Calculate `num_live`
MadLittleMods Jun 18, 2024
81d36f3
Add tests for `limited`
MadLittleMods Jun 18, 2024
9791209
Add more tests
MadLittleMods Jun 18, 2024
70ecd4d
Fix lint
MadLittleMods Jun 19, 2024
71eabe5
Make room name optional
MadLittleMods Jun 19, 2024
39b4f10
Update comments
MadLittleMods Jun 19, 2024
9883b0f
Add bundled aggregations
MadLittleMods Jun 19, 2024
1c06153
Determine limited before filtering
MadLittleMods Jun 19, 2024
57ba033
Merge branch 'develop' into madlittlemods/sliding-sync-room-data
MadLittleMods Jun 19, 2024
c81f300
Add better support for leave/ban
MadLittleMods Jun 19, 2024
d801db0
Fix lints
MadLittleMods Jun 19, 2024
6942b64
Merge branch 'develop' into madlittlemods/sliding-sync-room-data
MadLittleMods Jun 19, 2024
884b448
Update some wording
MadLittleMods Jun 19, 2024
0eb0294
Remove unused `IncludeOldRooms` class
MadLittleMods Jun 20, 2024
b1b4231
Merge branch 'develop' into madlittlemods/sliding-sync-room-data
MadLittleMods Jun 24, 2024
87fac19
Fix lints
MadLittleMods Jun 24, 2024
0e71a2f
Add TODO for filtering call invites in public rooms
MadLittleMods Jun 24, 2024
21ca02c
`newly_joined` vs `limited` already being tracked in a discussion
MadLittleMods Jun 24, 2024
3568311
Fix spelling typo
MadLittleMods Jun 25, 2024
7aea406
Just stripped_state for invite rooms
MadLittleMods Jun 25, 2024
e3e431f
Finish up stripped_state for invite rooms
MadLittleMods Jun 25, 2024
303d834
Add tracking discussion for not optional in the future
MadLittleMods Jun 25, 2024
4c22131
Start testing for the correct room membership (failing)
MadLittleMods Jun 25, 2024
83d6f76
Describe `current_state_delta_stream` better
MadLittleMods Jun 25, 2024
fbd92e1
Add `get_current_state_delta_membership_changes_for_user(...)` (using…
MadLittleMods Jun 26, 2024
6c791a8
WIP: Add back `newly_left`
MadLittleMods Jun 26, 2024
27d74b0
Iterate
MadLittleMods Jun 26, 2024
fb8fbd4
Just fetch full events for `get_current_state_delta_membership_change…
MadLittleMods Jun 26, 2024
d91aa00
Remove extras
MadLittleMods Jun 26, 2024
daa7e36
Add docstring
MadLittleMods Jun 26, 2024
cccbd15
Refactor back to not pulling out full events
MadLittleMods Jun 26, 2024
62c6a4e
Add `newly_joined` support to `get_sync_room_ids_for_user(...)`
MadLittleMods Jun 26, 2024
39259f6
Join both tables with stream_ordering
MadLittleMods Jun 26, 2024
5c21315
Merge branch 'develop' into madlittlemods/sliding-sync-room-data
MadLittleMods Jun 26, 2024
c60aca7
Fix clause change
MadLittleMods Jun 26, 2024
11db1be
Remove debug log
MadLittleMods Jun 26, 2024
7395e10
Fix `builtins.SyntaxError: EOL while scanning string literal (test_sy…
MadLittleMods Jun 26, 2024
2bf3923
Add some tests for `get_current_state_delta_membership_changes_for_us…
MadLittleMods Jun 26, 2024
ec2d8dc
Create events using helper
MadLittleMods Jun 26, 2024
0b9a903
Add test that remotely joins room
MadLittleMods Jun 27, 2024
48d0acf
Actually test `get_current_state_delta_membership_changes_for_user(..…
MadLittleMods Jun 27, 2024
2a944ff
Add state of the db in each situation
MadLittleMods Jun 27, 2024
8df39d1
Remove redundant `instance_name` column
MadLittleMods Jun 27, 2024
b7914e7
Add skipped test for state resets
MadLittleMods Jun 27, 2024
7eb1806
Fix lints
MadLittleMods Jun 27, 2024
935b98c
All `get_current_state_delta_membership_changes_for_user(...)` tests …
MadLittleMods Jun 27, 2024
f163fcf
Remove need for topological_ordering
MadLittleMods Jun 27, 2024
956f20e
(currently failing) Add test to make sure membership changes don't re…
MadLittleMods Jun 27, 2024
830e09d
Grab `prev_membership` to see whether the server left the room (fixes…
MadLittleMods Jun 27, 2024
15fcead
Slight clean-up
MadLittleMods Jun 27, 2024
81c06be
Detect state resets
MadLittleMods Jun 27, 2024
eb159c1
Don't worry about `state_reset` for now
MadLittleMods Jun 27, 2024
ba56350
Passing current tests
MadLittleMods Jun 27, 2024
f774032
Add better comments
MadLittleMods Jun 27, 2024
325856e
Inclusive ranges
MadLittleMods Jun 27, 2024
63c7b50
(doesn't work) Add test for batch persisting multiple member events f…
MadLittleMods Jun 27, 2024
1158058
Opt for tackling more batch scenarios in future PRs
MadLittleMods Jun 27, 2024
32b8b68
Add TODO to handle state resets
MadLittleMods Jun 27, 2024
6045e11
Merge branch 'develop' into madlittlemods/sliding-sync-room-data
MadLittleMods Jul 1, 2024
9e53336
Avoid fetching full events for `prev_event_ids`
MadLittleMods Jul 1, 2024
a4263bf
Update stream tests with prev event info
MadLittleMods Jul 1, 2024
10d78d6
Protect for non-existent prev events
MadLittleMods Jul 2, 2024
0061561
Merge branch 'develop' into madlittlemods/sliding-sync-room-data
MadLittleMods Jul 2, 2024
b8687e7
Select `to_key if to_key else from_key`
MadLittleMods Jul 2, 2024
7c9513c
Add missing test description
MadLittleMods Jul 2, 2024
8b73185
Trigger CI again
MadLittleMods Jul 2, 2024
126ce1e
Merge branch 'develop' into madlittlemods/sliding-sync-room-data
erikjohnston Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/17320.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `rooms` data to experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint.
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
MadLittleMods marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator Author

@MadLittleMods MadLittleMods Jul 2, 2024

Choose a reason for hiding this comment

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

CI keeps failing on building debs. It's unclear what's even going wrong or a change to cause this and I'm unable to merge with the failing status. It was building fine on the develop merge.

https://github.com/element-hq/synapse/actions/runs/9754628604/job/26922590117

...

Building wheels for collected packages: cffi, jaeger-client, markupsafe, opentracing, psycopg2, pyicu, systemd-python, threadloop, thrift, zope-interface
  Building wheel for cffi (pyproject.toml): started
  error: subprocess-exited-with-error
  
  × Building wheel for cffi (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for cffi (pyproject.toml): finished with status 'error'
  ERROR: Failed building wheel for cffi

....

Failed to build cffi
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (cffi)
Traceback (most recent call last):
  File "/usr/bin/dh_virtualenv", line 111, in <module>
    sys.exit(main() or 0)
             ^^^^^^
  File "/usr/bin/dh_virtualenv", line 91, in main
    deploy.install_dependencies()
  File "/usr/lib/python3/dist-packages/dh_virtualenv/deployment.py", line 202, in install_dependencies
    subprocess.check_call(self.pip('-r', requirements_path))
  File "/usr/lib/python3.12/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/bin/python', '/synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/bin/pip', 'install', '--log=/tmp/tmp1je1k3qf', '--no-deps', '--no-cache-dir', '--compile', '-r', './exported_requirements.txt']' returned non-zero exit status 1.
make[1]: Leaving directory '/synapse/build'
make[1]: *** [debian/rules:57: override_dh_virtualenv] Error 1
make: *** [debian/rules:66: binary] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
build of debian:sid failed: Command '['docker', 'run', '--rm', '--name', 'synapse_build_sid', '--volume=/home/runner/work/synapse/synapse/src:/synapse/source:ro', '--volume=/home/runner/work/synapse/synapse/src/../debs:/debs', '-e', 'TARGET_USERID=1001', '-e', 'TARGET_GROUPID=127', '-e', 'DEB_BUILD_OPTIONS=', 'dh-venv-builder:sid']' returned non-zero exit status 2.
Traceback (most recent call last):
  File "/home/runner/work/synapse/synapse/./src/scripts-dev/build_debian_packages.py", line 225, in <module>
    run_builds(
  File "/home/runner/work/synapse/synapse/./src/scripts-dev/build_debian_packages.py", line 182, in run_builds
    for _ in res:
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/synapse/synapse/./src/scripts-dev/build_debian_packages.py", line 179, in <lambda>
    res = e.map(lambda dist: builder.run_build(dist, skip_tests), dists)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/synapse/synapse/./src/scripts-dev/build_debian_packages.py", line 70, in run_build
    self._inner_build(dist, skip_tests)
  File "/home/runner/work/synapse/synapse/./src/scripts-dev/build_debian_packages.py", line 123, in _inner_build
    subprocess.check_call(
  File "/opt/hostedtoolcache/Python/3.12.4/x64/lib/python3.12/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['docker', 'run', '--rm', '--name', 'synapse_build_sid', '--volume=/home/runner/work/synapse/synapse/src:/synapse/source:ro', '--volume=/home/runner/work/synapse/synapse/src/../debs:/debs', '-e', 'TARGET_USERID=1001', '-e', 'TARGET_GROUPID=127', '-e', 'DEB_BUILD_OPTIONS=', 'dh-venv-builder:sid']' returned non-zero exit status 2.

If I run scripts-dev/build_debian_packages.py locally, I see a different error (even on develop) which is a bit confusing because I'd assume it should behaving about the same given it's all running in Docker.

Local build output
...
Successfully installed matrix-synapse-1.110.0rc2
/ /synapse/build
Running 0 tests.
E
===============================================================================
[ERROR]
Traceback (most recent call last):
  File "/synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/trial/runner.py", line 711, in loadByName
    return self.suiteFactory([self.findByName(name, recurse=recurse)])
  File "/synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/trial/runner.py", line 474, in findByName
    obj = reflect.namedModule(searchName)
  File "/synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/lib/python3.9/site-packages/twisted/python/reflect.py", line 156, in namedModule
    topLevel = __import__(name)
  File "/tmp/tmp.DNj5v3i4RS/tests/__init__.py", line 24, in <module>
    from synapse.util.patch_inline_callbacks import do_patch
  File "/synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/__init__.py", line 32, in <module>
    from synapse.util.rust import check_rust_lib_up_to_date
  File "/synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/util/rust.py", line 27, in <module>
    from synapse.synapse_rust import get_rust_file_digest
builtins.ImportError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /synapse/build/debian/matrix-synapse-py3/opt/venvs/matrix-synapse/lib/python3.9/site-packages/synapse/synapse_rust.abi3.so)

tests
-------------------------------------------------------------------------------
Ran 1 tests in 0.000s

FAILED (errors=1)
make[1]: *** [debian/rules:57: override_dh_virtualenv] Error 1
make[1]: Leaving directory '/synapse/build'
make: *** [debian/rules:66: binary] Error 2
dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
build of debian:bullseye failed: Command '['docker', 'run', '--rm', '--name', 'synapse_build_bullseye', '--volume=/home/eric/Documents/github/element/synapse:/synapse/source:ro', '--volume=/home/eric/Documents/github/element/synapse/../debs:/debs', '-e', 'TARGET_USERID=1000', '-e', 'TARGET_GROUPID=1000', '-e', 'DEB_BUILD_OPTIONS=', 'dh-venv-builder:bullseye']' returned non-zero exit status 2.
not building debian:bookworm due to earlier failure
not building debian:sid due to earlier failure
not building ubuntu:focal due to earlier failure
not building ubuntu:jammy due to earlier failure
not building ubuntu:lunar due to earlier failure
not building ubuntu:mantic due to earlier failure
not building debian:trixie due to earlier failure
Traceback (most recent call last):
  File "/home/eric/Documents/github/element/synapse/scripts-dev/build_debian_packages.py", line 225, in <module>
    run_builds(
  File "/home/eric/Documents/github/element/synapse/scripts-dev/build_debian_packages.py", line 182, in run_builds
    for _ in res:
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eric/Documents/github/element/synapse/scripts-dev/build_debian_packages.py", line 179, in <lambda>
    res = e.map(lambda dist: builder.run_build(dist, skip_tests), dists)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eric/Documents/github/element/synapse/scripts-dev/build_debian_packages.py", line 70, in run_build
    self._inner_build(dist, skip_tests)
  File "/home/eric/Documents/github/element/synapse/scripts-dev/build_debian_packages.py", line 123, in _inner_build
    subprocess.check_call(
  File "/usr/lib/python3.12/subprocess.py", line 413, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['docker', 'run', '--rm', '--name', 'synapse_build_bullseye', '--volume=/home/eric/Documents/github/element/synapse:/synapse/source:ro', '--volume=/home/eric/Documents/github/element/synapse/../debs:/debs', '-e', 'TARGET_USERID=1000', '-e', 'TARGET_GROUPID=1000', '-e', 'DEB_BUILD_OPTIONS=', 'dh-venv-builder:bullseye']' returned non-zero exit status 2.

Copy link
Member

Choose a reason for hiding this comment

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

I've just rerun this on develop and it looks like its broken there too

Copy link
Member

Choose a reason for hiding this comment

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

#17389 was the issue in CI

#17390 was the issue running locally

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for fixing up the deb build issues @erikjohnston!

For the first one, the fact that it was building a wheel at all is the hint as it should be downloading one normally.

For the second one, it makes more sense but if we expect a clean checkout for the Docker builds, it would be nice to remove things according to the .gitignore.

18 changes: 18 additions & 0 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,21 @@ def maybe_upsert_event_field(
del container[key]

return upsert_okay


def strip_event(event: EventBase) -> JsonDict:
"""
Used for "stripped state" events which provide a simplified view of the state of a
room intended to help a potential joiner identify the room (relevant when the user
is invited or knocked).

Stripped state events can only have the `sender`, `type`, `state_key` and `content`
properties present.
"""

return {
"type": event.type,
"state_key": event.state_key,
"content": event.content,
"sender": event.sender,
}
642 changes: 490 additions & 152 deletions synapse/handlers/sliding_sync.py

Large diffs are not rendered by default.

112 changes: 99 additions & 13 deletions synapse/rest/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ class SlidingSyncRestServlet(RestServlet):
"lists": {
"foo-list": {
"ranges": [ [0, 99] ],
"sort": [ "by_notification_level", "by_recency", "by_name" ],
"required_state": [
["m.room.join_rules", ""],
["m.room.history_visibility", ""],
Expand All @@ -771,18 +770,13 @@ class SlidingSyncRestServlet(RestServlet):
"filters": {
"is_dm": true
},
"bump_event_types": [ "m.room.message", "m.room.encrypted" ],
}
},
// Room Subscriptions API
"room_subscriptions": {
"!sub1:bar": {
"required_state": [ ["*","*"] ],
"timeline_limit": 10,
"include_old_rooms": {
"timeline_limit": 1,
"required_state": [ ["m.room.tombstone", ""], ["m.room.create", ""] ],
}
}
},
// Extensions API
Expand All @@ -791,7 +785,7 @@ class SlidingSyncRestServlet(RestServlet):

Response JSON::
{
"next_pos": "s58_224_0_13_10_1_1_16_0_1",
"pos": "s58_224_0_13_10_1_1_16_0_1",
"lists": {
"foo-list": {
"count": 1337,
Expand Down Expand Up @@ -830,7 +824,8 @@ class SlidingSyncRestServlet(RestServlet):
"joined_count": 41,
"invited_count": 1,
"notification_count": 1,
"highlight_count": 0
"highlight_count": 0,
"num_live": 2"
},
// rooms from list
"!foo:bar": {
Expand All @@ -855,7 +850,8 @@ class SlidingSyncRestServlet(RestServlet):
"joined_count": 4,
"invited_count": 0,
"notification_count": 54,
"highlight_count": 3
"highlight_count": 3,
"num_live": 1,
},
// ... 99 more items
},
Expand All @@ -871,10 +867,11 @@ def __init__(self, hs: "HomeServer"):
super().__init__()
self.auth = hs.get_auth()
self.store = hs.get_datastores().main
self.clock = hs.get_clock()
self.filtering = hs.get_filtering()
self.sliding_sync_handler = hs.get_sliding_sync_handler()
self.event_serializer = hs.get_event_client_serializer()

# TODO: Update this to `on_GET` once we figure out how we want to handle params
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
requester = await self.auth.get_user_by_req(request, allow_guest=True)
user = requester.user
Expand Down Expand Up @@ -920,22 +917,25 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
logger.info("Client has disconnected; not serializing response.")
return 200, {}

response_content = await self.encode_response(sliding_sync_results)
response_content = await self.encode_response(requester, sliding_sync_results)

return 200, response_content

# TODO: Is there a better way to encode things?
async def encode_response(
self,
requester: Requester,
sliding_sync_result: SlidingSyncResult,
) -> JsonDict:
response: JsonDict = defaultdict(dict)

response["next_pos"] = await sliding_sync_result.next_pos.to_string(self.store)
response["pos"] = await sliding_sync_result.next_pos.to_string(self.store)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just updating this field to match the MSC3575. next_pos sounds better to me but I assume pos was originally chosen to save on bytes and this can throw this in the bikeshed for later.

serialized_lists = self.encode_lists(sliding_sync_result.lists)
if serialized_lists:
response["lists"] = serialized_lists
response["rooms"] = {} # TODO: sliding_sync_result.rooms
response["rooms"] = await self.encode_rooms(
requester, sliding_sync_result.rooms
)
response["extensions"] = {} # TODO: sliding_sync_result.extensions

return response
Expand All @@ -961,6 +961,92 @@ def encode_operation(

return serialized_lists

async def encode_rooms(
self,
requester: Requester,
rooms: Dict[str, SlidingSyncResult.RoomResult],
) -> JsonDict:
time_now = self.clock.time_msec()

serialize_options = SerializeEventConfig(
event_format=format_event_for_client_v2_without_room_id,
requester=requester,
)

serialized_rooms: Dict[str, JsonDict] = {}
for room_id, room_result in rooms.items():
serialized_rooms[room_id] = {
"joined_count": room_result.joined_count,
"invited_count": room_result.invited_count,
"notification_count": room_result.notification_count,
"highlight_count": room_result.highlight_count,
}

if room_result.name:
serialized_rooms[room_id]["name"] = room_result.name

if room_result.avatar:
serialized_rooms[room_id]["avatar"] = room_result.avatar

if room_result.heroes:
serialized_rooms[room_id]["heroes"] = room_result.heroes

# We should only include the `initial` key if it's `True` to save bandwidth.
# The absense of this flag means `False`.
if room_result.initial:
serialized_rooms[room_id]["initial"] = room_result.initial

# This will omitted for invite/knock rooms with `stripped_state`
if room_result.required_state is not None:
serialized_required_state = (
await self.event_serializer.serialize_events(
room_result.required_state,
time_now,
config=serialize_options,
)
)
serialized_rooms[room_id]["required_state"] = serialized_required_state

# This will omitted for invite/knock rooms with `stripped_state`
if room_result.timeline_events is not None:
serialized_timeline = await self.event_serializer.serialize_events(
room_result.timeline_events,
time_now,
config=serialize_options,
bundle_aggregations=room_result.bundled_aggregations,
)
serialized_rooms[room_id]["timeline"] = serialized_timeline

# This will omitted for invite/knock rooms with `stripped_state`
if room_result.limited is not None:
serialized_rooms[room_id]["limited"] = room_result.limited

# This will omitted for invite/knock rooms with `stripped_state`
if room_result.prev_batch is not None:
serialized_rooms[room_id]["prev_batch"] = (
await room_result.prev_batch.to_string(self.store)
)

# This will omitted for invite/knock rooms with `stripped_state`
if room_result.num_live is not None:
serialized_rooms[room_id]["num_live"] = room_result.num_live

# Field should be absent on non-DM rooms
if room_result.is_dm:
serialized_rooms[room_id]["is_dm"] = room_result.is_dm

# Stripped state only applies to invite/knock rooms
if room_result.stripped_state is not None:
# TODO: `knocked_state` but that isn't specced yet.
#
# TODO: Instead of adding `knocked_state`, it would be good to rename
# this to `stripped_state` so it can be shared between invite and knock
# rooms, see
# https://github.com/matrix-org/matrix-spec-proposals/pull/3575#discussion_r1117629919
serialized_rooms[room_id]["invite_state"] = room_result.stripped_state

return serialized_rooms


def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None:
SyncRestServlet(hs).register(http_server)
Expand Down
12 changes: 2 additions & 10 deletions synapse/storage/databases/main/events_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
)
from synapse.events import EventBase, make_event_from_dict
from synapse.events.snapshot import EventContext
from synapse.events.utils import prune_event
from synapse.events.utils import prune_event, strip_event
from synapse.logging.context import (
PreserveLoggingContext,
current_context,
Expand Down Expand Up @@ -1025,15 +1025,7 @@ async def get_stripped_room_state_from_event_context(

state_to_include = await self.get_events(selected_state_ids.values())

return [
{
"type": e.type,
"state_key": e.state_key,
"content": e.content,
"sender": e.sender,
}
for e in state_to_include.values()
]
return [strip_event(e) for e in state_to_include.values()]

def _maybe_start_fetch_thread(self) -> None:
"""Starts an event fetch thread if we are not yet at the maximum number."""
Expand Down
Loading
Loading