@@ -1536,15 +1536,13 @@ async def _generate_sync_entry_for_rooms(
15361536 ignored_users = await self .store .ignored_users (user_id )
15371537 if since_token :
15381538 room_changes = await self ._get_rooms_changed (
1539- sync_result_builder , ignored_users , self . rooms_to_exclude
1539+ sync_result_builder , ignored_users
15401540 )
15411541 tags_by_room = await self .store .get_updated_tags (
15421542 user_id , since_token .account_data_key
15431543 )
15441544 else :
1545- room_changes = await self ._get_all_rooms (
1546- sync_result_builder , ignored_users , self .rooms_to_exclude
1547- )
1545+ room_changes = await self ._get_all_rooms (sync_result_builder , ignored_users )
15481546 tags_by_room = await self .store .get_tags_for_user (user_id )
15491547
15501548 log_kv ({"rooms_changed" : len (room_changes .room_entries )})
@@ -1623,13 +1621,14 @@ async def _get_rooms_changed(
16231621 self ,
16241622 sync_result_builder : "SyncResultBuilder" ,
16251623 ignored_users : FrozenSet [str ],
1626- excluded_rooms : List [str ],
16271624 ) -> _RoomChanges :
16281625 """Determine the changes in rooms to report to the user.
16291626
16301627 This function is a first pass at generating the rooms part of the sync response.
16311628 It determines which rooms have changed during the sync period, and categorises
1632- them into four buckets: "knock", "invite", "join" and "leave".
1629+ them into four buckets: "knock", "invite", "join" and "leave". It also excludes
1630+ from that list any room that appears in the list of rooms to exclude from sync
1631+ results in the server configuration.
16331632
16341633 1. Finds all membership changes for the user in the sync period (from
16351634 `since_token` up to `now_token`).
@@ -1655,7 +1654,7 @@ async def _get_rooms_changed(
16551654 # _have_rooms_changed. We could keep the results in memory to avoid a
16561655 # second query, at the cost of more complicated source code.
16571656 membership_change_events = await self .store .get_membership_changes_for_user (
1658- user_id , since_token .room_key , now_token .room_key , excluded_rooms
1657+ user_id , since_token .room_key , now_token .room_key , self . rooms_to_exclude
16591658 )
16601659
16611660 mem_change_events_by_room_id : Dict [str , List [EventBase ]] = {}
@@ -1862,7 +1861,6 @@ async def _get_all_rooms(
18621861 self ,
18631862 sync_result_builder : "SyncResultBuilder" ,
18641863 ignored_users : FrozenSet [str ],
1865- ignored_rooms : List [str ],
18661864 ) -> _RoomChanges :
18671865 """Returns entries for all rooms for the user.
18681866
@@ -1884,7 +1882,7 @@ async def _get_all_rooms(
18841882 room_list = await self .store .get_rooms_for_local_user_where_membership_is (
18851883 user_id = user_id ,
18861884 membership_list = Membership .LIST ,
1887- excluded_rooms = ignored_rooms ,
1885+ excluded_rooms = self . rooms_to_exclude ,
18881886 )
18891887
18901888 room_entries = []
@@ -2150,7 +2148,9 @@ async def _generate_room_entry(
21502148 raise Exception ("Unrecognized rtype: %r" , room_builder .rtype )
21512149
21522150 async def get_rooms_for_user_at (
2153- self , user_id : str , room_key : RoomStreamToken
2151+ self ,
2152+ user_id : str ,
2153+ room_key : RoomStreamToken ,
21542154 ) -> FrozenSet [str ]:
21552155 """Get set of joined rooms for a user at the given stream ordering.
21562156
@@ -2176,7 +2176,12 @@ async def get_rooms_for_user_at(
21762176 # If the membership's stream ordering is after the given stream
21772177 # ordering, we need to go and work out if the user was in the room
21782178 # before.
2179+ # We also need to check whether the room should be excluded from sync
2180+ # responses as per the homeserver config.
21792181 for joined_room in joined_rooms :
2182+ if joined_room .room_id in self .rooms_to_exclude :
2183+ continue
2184+
21802185 if not joined_room .event_pos .persisted_after (room_key ):
21812186 joined_room_ids .add (joined_room .room_id )
21822187 continue
0 commit comments