2929    MissingClientTokenError ,
3030)
3131from  synapse .appservice  import  ApplicationService 
32- from  synapse .events  import  EventBase 
3332from  synapse .http  import  get_request_user_agent 
3433from  synapse .http .site  import  SynapseRequest 
3534from  synapse .logging .opentracing  import  active_span , force_tracing , start_active_span 
3635from  synapse .storage .databases .main .registration  import  TokenLookupResult 
37- from  synapse .types  import  Requester , StateMap ,  UserID , create_requester 
36+ from  synapse .types  import  Requester , UserID , create_requester 
3837from  synapse .util .caches .lrucache  import  LruCache 
3938from  synapse .util .macaroons  import  get_value_from_macaroon , satisfy_expiry 
4039
@@ -61,8 +60,8 @@ def __init__(self, hs: "HomeServer"):
6160        self .hs  =  hs 
6261        self .clock  =  hs .get_clock ()
6362        self .store  =  hs .get_datastores ().main 
64-         self .state  =  hs .get_state_handler ()
6563        self ._account_validity_handler  =  hs .get_account_validity_handler ()
64+         self ._storage_controllers  =  hs .get_storage_controllers ()
6665
6766        self .token_cache : LruCache [str , Tuple [str , bool ]] =  LruCache (
6867            10000 , "token_cache" 
@@ -79,9 +78,8 @@ async def check_user_in_room(
7978        self ,
8079        room_id : str ,
8180        user_id : str ,
82-         current_state : Optional [StateMap [EventBase ]] =  None ,
8381        allow_departed_users : bool  =  False ,
84-     ) ->  EventBase :
82+     ) ->  Tuple [ str ,  Optional [ str ]] :
8583        """Check if the user is in the room, or was at some point. 
8684        Args: 
8785            room_id: The room to check. 
@@ -99,29 +97,28 @@ async def check_user_in_room(
9997        Raises: 
10098            AuthError if the user is/was not in the room. 
10199        Returns: 
102-             Membership event for the user if the user was in the 
103-             room. This will be the join event if they are currently joined to 
104-             the room. This will be the leave event if they have left the room. 
100+             The current membership of the user in the room and the 
101+             membership event ID of the user. 
105102        """ 
106-         if  current_state :
107-             member  =  current_state .get ((EventTypes .Member , user_id ), None )
108-         else :
109-             member  =  await  self .state .get_current_state (
110-                 room_id = room_id , event_type = EventTypes .Member , state_key = user_id 
111-             )
112103
113-         if  member :
114-             membership  =  member .membership 
104+         (
105+             membership ,
106+             member_event_id ,
107+         ) =  await  self .store .get_local_current_membership_for_user_in_room (
108+             user_id = user_id ,
109+             room_id = room_id ,
110+         )
115111
112+         if  membership :
116113            if  membership  ==  Membership .JOIN :
117-                 return  member 
114+                 return  membership ,  member_event_id 
118115
119116            # XXX this looks totally bogus. Why do we not allow users who have been banned, 
120117            # or those who were members previously and have been re-invited? 
121118            if  allow_departed_users  and  membership  ==  Membership .LEAVE :
122119                forgot  =  await  self .store .did_forget (user_id , room_id )
123120                if  not  forgot :
124-                     return  member 
121+                     return  membership ,  member_event_id 
125122
126123        raise  AuthError (403 , "User %s not in room %s"  %  (user_id , room_id ))
127124
@@ -602,8 +599,11 @@ async def check_can_change_room_list(self, room_id: str, user: UserID) -> bool:
602599        # We currently require the user is a "moderator" in the room. We do this 
603600        # by checking if they would (theoretically) be able to change the 
604601        # m.room.canonical_alias events 
605-         power_level_event  =  await  self .state .get_current_state (
606-             room_id , EventTypes .PowerLevels , "" 
602+ 
603+         power_level_event  =  (
604+             await  self ._storage_controllers .state .get_current_state_event (
605+                 room_id , EventTypes .PowerLevels , "" 
606+             )
607607        )
608608
609609        auth_events  =  {}
@@ -693,12 +693,11 @@ async def check_user_in_room_or_world_readable(
693693            #  * The user is a non-guest user, and was ever in the room 
694694            #  * The user is a guest user, and has joined the room 
695695            # else it will throw. 
696-             member_event   =  await  self .check_user_in_room (
696+             return  await  self .check_user_in_room (
697697                room_id , user_id , allow_departed_users = allow_departed_users 
698698            )
699-             return  member_event .membership , member_event .event_id 
700699        except  AuthError :
701-             visibility  =  await  self .state .get_current_state (
700+             visibility  =  await  self ._storage_controllers . state .get_current_state_event (
702701                room_id , EventTypes .RoomHistoryVisibility , "" 
703702            )
704703            if  (
0 commit comments