Skip to content

Commit 8aaff85

Browse files
Fix newly_left rooms not appearing if we returned early (Sliding Sync) (#17301)
Fix `newly_left` rooms not appearing if we returned early when `membership_snapshot_token.is_before_or_eq(to_token.room_key)`. Introduced in #17187 (part of Sliding Sync) The tests didn't catch it because they had a small typo in it `room_id1` vs `room_id2`. Found while working on #17293
1 parent 8c58eb7 commit 8aaff85

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

changelog.d/17301.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add initial implementation of an experimental [MSC3575](https://github.com/matrix-org/matrix-spec-proposals/pull/3575) Sliding Sync `/sync` endpoint.

synapse/handlers/sliding_sync.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,6 @@ async def get_sync_room_ids_for_user(
275275
instance_map=immutabledict(instance_to_max_stream_ordering_map),
276276
)
277277

278-
# If our `to_token` is already the same or ahead of the latest room membership
279-
# for the user, we can just straight-up return the room list (nothing has
280-
# changed)
281-
if membership_snapshot_token.is_before_or_eq(to_token.room_key):
282-
return sync_room_id_set
283-
284278
# Since we fetched the users room list at some point in time after the from/to
285279
# tokens, we need to revert/rewind some membership changes to match the point in
286280
# time of the `to_token`. In particular, we need to make these fixups:
@@ -300,14 +294,20 @@ async def get_sync_room_ids_for_user(
300294

301295
# 1) Fetch membership changes that fall in the range from `to_token` up to
302296
# `membership_snapshot_token`
303-
membership_change_events_after_to_token = (
304-
await self.store.get_membership_changes_for_user(
305-
user_id,
306-
from_key=to_token.room_key,
307-
to_key=membership_snapshot_token,
308-
excluded_rooms=self.rooms_to_exclude_globally,
297+
#
298+
# If our `to_token` is already the same or ahead of the latest room membership
299+
# for the user, we don't need to do any "2)" fix-ups and can just straight-up
300+
# use the room list from the snapshot as a base (nothing has changed)
301+
membership_change_events_after_to_token = []
302+
if not membership_snapshot_token.is_before_or_eq(to_token.room_key):
303+
membership_change_events_after_to_token = (
304+
await self.store.get_membership_changes_for_user(
305+
user_id,
306+
from_key=to_token.room_key,
307+
to_key=membership_snapshot_token,
308+
excluded_rooms=self.rooms_to_exclude_globally,
309+
)
309310
)
310-
)
311311

312312
# 1) Assemble a list of the last membership events in some given ranges. Someone
313313
# could have left and joined multiple times during the given range but we only

tests/handlers/test_sliding_sync.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def test_only_newly_left_rooms_show_up(self) -> None:
326326

327327
# Leave during the from_token/to_token range (newly_left)
328328
room_id2 = self.helper.create_room_as(user1_id, tok=user1_tok)
329-
self.helper.leave(room_id1, user1_id, tok=user1_tok)
329+
self.helper.leave(room_id2, user1_id, tok=user1_tok)
330330

331331
after_room2_token = self.event_sources.get_current_token()
332332

0 commit comments

Comments
 (0)