summary refs log tree commit diff
path: root/synapse/handlers/sliding_sync/room_lists.py
diff options
context:
space:
mode:
authorEric Eastwood <eric.eastwood@beta.gouv.fr>2024-09-18 18:09:23 -0500
committerGitHub <noreply@github.com>2024-09-18 18:09:23 -0500
commitaf998e6c660986da8385d26d724c70b5d0f77c67 (patch)
treebc2b7a1bddc3878fec26621854fe6379afa44d19 /synapse/handlers/sliding_sync/room_lists.py
parentSliding Sync: Shortcut for checking if certain background updates have comple... (diff)
downloadsynapse-af998e6c660986da8385d26d724c70b5d0f77c67.tar.xz
Sliding sync: Ignore invites from ignored users (#17729)
`m.ignored_user_list` in account data
Diffstat (limited to 'synapse/handlers/sliding_sync/room_lists.py')
-rw-r--r--synapse/handlers/sliding_sync/room_lists.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/synapse/handlers/sliding_sync/room_lists.py b/synapse/handlers/sliding_sync/room_lists.py

index 475bfbbbcb..8457526a45 100644 --- a/synapse/handlers/sliding_sync/room_lists.py +++ b/synapse/handlers/sliding_sync/room_lists.py
@@ -224,15 +224,31 @@ class SlidingSyncRoomLists: user_id ) + # Remove invites from ignored users + ignored_users = await self.store.ignored_users(user_id) + if ignored_users: + # TODO: It would be nice to avoid these copies + room_membership_for_user_map = dict(room_membership_for_user_map) + # Make a copy so we don't run into an error: `dictionary changed size during + # iteration`, when we remove items + for room_id in list(room_membership_for_user_map.keys()): + room_for_user_sliding_sync = room_membership_for_user_map[room_id] + if ( + room_for_user_sliding_sync.membership == Membership.INVITE + and room_for_user_sliding_sync.sender in ignored_users + ): + room_membership_for_user_map.pop(room_id, None) + changes = await self._get_rewind_changes_to_current_membership_to_token( sync_config.user, room_membership_for_user_map, to_token=to_token ) if changes: + # TODO: It would be nice to avoid these copies room_membership_for_user_map = dict(room_membership_for_user_map) for room_id, change in changes.items(): if change is None: # Remove rooms that the user joined after the `to_token` - room_membership_for_user_map.pop(room_id) + room_membership_for_user_map.pop(room_id, None) continue existing_room = room_membership_for_user_map.get(room_id) @@ -926,6 +942,18 @@ class SlidingSyncRoomLists: excluded_rooms=self.rooms_to_exclude_globally, ) + # Remove invites from ignored users + ignored_users = await self.store.ignored_users(user_id) + if ignored_users: + room_for_user_list = [ + room_for_user + for room_for_user in room_for_user_list + if not ( + room_for_user.membership == Membership.INVITE + and room_for_user.sender in ignored_users + ) + ] + # If the user has never joined any rooms before, we can just return an empty list if not room_for_user_list: return {}, set(), set()