13
13
# limitations under the License.
14
14
15
15
import logging
16
- from typing import TYPE_CHECKING , Any , Dict , List , Optional
16
+ from typing import TYPE_CHECKING , Any , Dict , List , Optional , Set , Tuple
17
17
18
18
import synapse .metrics
19
19
from synapse .api .constants import EventTypes , HistoryVisibility , JoinRules , Membership
@@ -379,7 +379,7 @@ async def _upsert_directory_entry_for_remote_user(
379
379
user_id , event .content .get ("displayname" ), event .content .get ("avatar_url" )
380
380
)
381
381
382
- async def _track_user_joined_room (self , room_id : str , user_id : str ) -> None :
382
+ async def _track_user_joined_room (self , room_id : str , joining_user_id : str ) -> None :
383
383
"""Someone's just joined a room. Update `users_in_public_rooms` or
384
384
`users_who_share_private_rooms` as appropriate.
385
385
@@ -390,32 +390,44 @@ async def _track_user_joined_room(self, room_id: str, user_id: str) -> None:
390
390
room_id
391
391
)
392
392
if is_public :
393
- await self .store .add_users_in_public_rooms (room_id , (user_id ,))
393
+ await self .store .add_users_in_public_rooms (room_id , (joining_user_id ,))
394
394
else :
395
395
users_in_room = await self .store .get_users_in_room (room_id )
396
396
other_users_in_room = [
397
397
other
398
398
for other in users_in_room
399
- if other != user_id
399
+ if other != joining_user_id
400
400
and (
401
+ # We can't apply any special rules to remote users so
402
+ # they're always included
401
403
not self .is_mine_id (other )
404
+ # Check the special rules whether the local user should be
405
+ # included in the user directory
402
406
or await self .store .should_include_local_user_in_dir (other )
403
407
)
404
408
]
405
- to_insert = set ()
409
+ updates_to_users_who_share_rooms : Set [ Tuple [ str , str ]] = set ()
406
410
407
- # First, if they're our user then we need to update for every user
408
- if self .is_mine_id (user_id ):
411
+ # First, if the joining user is our local user then we need an
412
+ # update for every other user in the room.
413
+ if self .is_mine_id (joining_user_id ):
409
414
for other_user_id in other_users_in_room :
410
- to_insert .add ((user_id , other_user_id ))
415
+ updates_to_users_who_share_rooms .add (
416
+ (joining_user_id , other_user_id )
417
+ )
411
418
412
- # Next we need to update for every local user in the room
419
+ # Next, we need an update for every local user in the room that they
420
+ # now share a room with the joining user
413
421
for other_user_id in other_users_in_room :
414
422
if self .is_mine_id (other_user_id ):
415
- to_insert .add ((other_user_id , user_id ))
423
+ updates_to_users_who_share_rooms .add (
424
+ (other_user_id , joining_user_id )
425
+ )
416
426
417
- if to_insert :
418
- await self .store .add_users_who_share_private_room (room_id , to_insert )
427
+ if updates_to_users_who_share_rooms :
428
+ await self .store .add_users_who_share_private_room (
429
+ room_id , updates_to_users_who_share_rooms
430
+ )
419
431
420
432
async def _handle_remove_user (self , room_id : str , user_id : str ) -> None :
421
433
"""Called when when someone leaves a room. The user may be local or remote.
0 commit comments